forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponseFileProvider.cs
More file actions
97 lines (82 loc) · 2.9 KB
/
Copy pathResponseFileProvider.cs
File metadata and controls
97 lines (82 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor.Scripting.ScriptCompilation;
using UnityEngine;
namespace UnityEditor.Scripting.Compilers
{
internal abstract class ResponseFileProvider
{
private const string k_AssetsFolder = "Assets";
public abstract string ResponseFileName { get; }
public abstract string[] ObsoleteResponseFileNames { get; }
public string ProjectPath
{
get; set;
}
protected ResponseFileProvider()
{
var dataPath = Application.dataPath;
ProjectPath = Path.GetDirectoryName(dataPath);
}
public List<string> Get(string folderToLookForResponseFilesIn)
{
if (!string.IsNullOrEmpty(folderToLookForResponseFilesIn) && !Path.IsPathRooted(folderToLookForResponseFilesIn))
{
folderToLookForResponseFilesIn = AssetPath.Combine(ProjectPath, folderToLookForResponseFilesIn);
}
var result = new List<string>();
var folderResponseFile = GetCompilerSpecific(folderToLookForResponseFilesIn);
if (!string.IsNullOrEmpty(folderResponseFile))
{
AddIfNotNull(result, folderResponseFile);
}
else
{
AddIfNotNull(result, GetDefaultResponseFiles());
}
return result;
}
protected string GetCompilerSpecific(string path)
{
if (string.IsNullOrEmpty(path))
{
return null;
}
//We only look for the specific response file in the folder.
var responseFilePath = AssetPath.Combine(path, ResponseFileName);
if (File.Exists(responseFilePath))
{
return responseFilePath;
}
return null;
}
protected string GetDefaultResponseFiles()
{
var rootResponseFilePath = AssetPath.Combine(ProjectPath, k_AssetsFolder, ResponseFileName);
if (File.Exists(rootResponseFilePath))
{
return rootResponseFilePath;
}
foreach (var obsoleteResponseFileName in ObsoleteResponseFileNames)
{
var obsoleteResponseFilePath = AssetPath.Combine(ProjectPath, k_AssetsFolder, obsoleteResponseFileName);
if (File.Exists(obsoleteResponseFilePath))
{
return obsoleteResponseFilePath;
}
}
return null;
}
private static void AddIfNotNull<T>(List<T> list, T element)
{
if (element != null)
{
list.Add(element);
}
}
}
}