forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptAssembly.cs
More file actions
147 lines (125 loc) · 5.63 KB
/
Copy pathScriptAssembly.cs
File metadata and controls
147 lines (125 loc) · 5.63 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// 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.Diagnostics;
using System.Linq;
using UnityEditor.Scripting.Compilers;
using UnityEditor.Compilation;
using UnityEditor.Modules;
namespace UnityEditor.Scripting.ScriptCompilation
{
// Settings that would be common for a group of ScriptAssembly's created for the same build target.
class ScriptAssemblySettings
{
public BuildTarget BuildTarget { get; set; }
public BuildTargetGroup BuildTargetGroup { get; set; }
public string OutputDirectory { get; set; }
public EditorScriptCompilationOptions CompilationOptions { get; set; }
public ScriptCompilerOptions PredefinedAssembliesCompilerOptions { get; set; }
public string[] ExtraGeneralDefines { get; set; }
public ICompilationExtension CompilationExtension { get; set; }
public string ProjectRootNamespace { get; set; }
public CodeOptimization EditorCodeOptimization { get; set; }
public ScriptAssemblySettings()
{
BuildTarget = BuildTarget.NoTarget;
BuildTargetGroup = BuildTargetGroup.Unknown;
PredefinedAssembliesCompilerOptions = new ScriptCompilerOptions();
ExtraGeneralDefines = new string[0];
}
public bool BuildingForEditor
{
get { return (CompilationOptions & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor; }
}
public bool BuildingDevelopmentBuild
{
get { return (CompilationOptions & EditorScriptCompilationOptions.BuildingDevelopmentBuild) == EditorScriptCompilationOptions.BuildingDevelopmentBuild; }
}
}
[DebuggerDisplay("{Filename}")]
class ScriptAssembly
{
public string OriginPath { get; set; }
public AssemblyFlags Flags { get; set; }
public BuildTarget BuildTarget { get; set; }
public SupportedLanguage Language { get; set; }
public string Filename { get; set; }
public string PdbFilename
{
get
{
return $"{AssetPath.GetAssemblyNameWithoutExtension(Filename)}.pdb";
}
}
public string OutputDirectory { get; set; }
/// <summary>
/// References to dependencies that will be built.
/// </summary>
public ScriptAssembly[] ScriptAssemblyReferences { get; set; }
/// <summary>
///References to dependencies that that will *not* be built.
/// </summary>
public string[] References { get; set; }
public string[] Defines { get; set; }
public string[] Files { get; set; }
public string RootNamespace { get; set; }
public bool CallOnBeforeCompilationStarted { get; set; }
public ScriptCompilerOptions CompilerOptions { get; set; }
public string GeneratedResponseFile { get; set; }
public DirtySource DirtySource { get; set; }
// Indicates whether the assembly had compile errors on last compilation
public bool HasCompileErrors { get; set; }
public ScriptAssembly()
{
DirtySource = DirtySource.None;
}
public string FullPath { get { return AssetPath.Combine(OutputDirectory, Filename); } }
public string PdbFullPath { get { return AssetPath.Combine(OutputDirectory, PdbFilename); } }
public string ReferenceAssemblyFilename
{
get
{
return $"{Filename}.ref";
}
}
public string[] GetAllReferences()
{
return References.Concat(ScriptAssemblyReferences.Select(a => a.FullPath)).ToArray();
}
public MonoIsland ToMonoIsland(EditorScriptCompilationOptions options, string buildOutputDirectory, string projectPath = null)
{
bool buildingForEditor = (options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor;
bool developmentBuild = (options & EditorScriptCompilationOptions.BuildingDevelopmentBuild) == EditorScriptCompilationOptions.BuildingDevelopmentBuild;
var references = ScriptAssemblyReferences.Select(a => AssetPath.Combine(a.OutputDirectory, a.Filename));
var referencesArray = references.Concat(References).ToArray();
var responseFileProvider = Language?.CreateResponseFileProvider();
if (!string.IsNullOrEmpty(projectPath) && responseFileProvider != null)
{
responseFileProvider.ProjectPath = projectPath;
}
List<string> reposeFiles = responseFileProvider?.Get(OriginPath) ?? new List<string>();
var outputPath = AssetPath.Combine(buildOutputDirectory, Filename);
return new MonoIsland(BuildTarget,
buildingForEditor,
developmentBuild,
CompilerOptions.AllowUnsafeCode,
CompilerOptions.ApiCompatibilityLevel,
Files,
referencesArray,
Defines,
outputPath,
reposeFiles.ToArray());
}
public string[] GetResponseFiles()
{
if (Language == null)
{
throw new ArgumentException("Language: not set on ScriptAssembly. Cannot resolve responsefiles");
}
var responseFileProvider = Language.CreateResponseFileProvider();
return responseFileProvider.Get(OriginPath).ToArray();
}
}
}