forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityCodeGenHelpers.cs
More file actions
86 lines (68 loc) · 3.05 KB
/
Copy pathUnityCodeGenHelpers.cs
File metadata and controls
86 lines (68 loc) · 3.05 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
// 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 System.Linq;
using UnityEditor.Scripting.ScriptCompilation;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Scripting;
namespace UnityEditor.Scripting.ScriptCompilation
{
internal static class UnityCodeGenHelpers
{
const string k_CompilerSuffix = ".Compiler";
const string k_CodeGenSuffix = ".CodeGen";
const string k_CompilerTestsSuffix = ".Compiler.Tests";
const string k_CodeGenTestsSuffix = ".CodeGen.Tests";
const string k_CodeGenPrefix = "Unity.";
const string k_UnityEngineModules = "UnityEngine";
const string k_UnityEngineModulesLower = "unityengine";
const string k_UnityEditorModules = "UnityEditor";
const string k_UnityEditorModulesLower = "unityeditor";
public struct ScriptCodeGenAssemblies
{
public List<ScriptAssembly> ScriptAssemblies;
public List<ScriptAssembly> CodeGenAssemblies;
}
public static bool IsCodeGen(string assemblyName)
{
var name = AssetPath.GetAssemblyNameWithoutExtension(assemblyName);
if (name.StartsWith(k_CodeGenPrefix, StringComparison.OrdinalIgnoreCase) && name.EndsWith(k_CompilerSuffix, StringComparison.OrdinalIgnoreCase))
return true;
if (name.StartsWith(k_CodeGenPrefix, StringComparison.OrdinalIgnoreCase) && name.EndsWith(k_CodeGenSuffix, StringComparison.OrdinalIgnoreCase))
return true;
return false;
}
public static bool IsCodeGenTest(string assemblyName)
{
var name = AssetPath.GetAssemblyNameWithoutExtension(assemblyName);
if (name.StartsWith(k_CodeGenPrefix, StringComparison.OrdinalIgnoreCase) && name.EndsWith(k_CompilerTestsSuffix, StringComparison.OrdinalIgnoreCase))
return true;
if (name.StartsWith(k_CodeGenPrefix, StringComparison.OrdinalIgnoreCase) && name.EndsWith(k_CodeGenTestsSuffix, StringComparison.OrdinalIgnoreCase))
return true;
return false;
}
public static ScriptCodeGenAssemblies ToScriptCodeGenAssemblies(ScriptAssembly[] scriptAssemblies)
{
var result = new ScriptCodeGenAssemblies();
result.ScriptAssemblies = new List<ScriptAssembly>(scriptAssemblies.Length);
result.CodeGenAssemblies = new List<ScriptAssembly>(scriptAssemblies.Length);
foreach (var scriptAssembly in scriptAssemblies)
{
bool isCodeGen = IsCodeGen(scriptAssembly.Filename);
if (isCodeGen)
{
result.CodeGenAssemblies.Add(scriptAssembly);
}
else
{
result.ScriptAssemblies.Add(scriptAssembly);
}
}
return result;
}
}
}