Repository navigation
Expand file tree
/
Copy pathScriptCompiler.cs
More file actions
205 lines (198 loc) · 8.57 KB
/
Copy pathScriptCompiler.cs
File metadata and controls
205 lines (198 loc) · 8.57 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Inno.Assets;
using Inno.Assets.Pipeline;
using Inno.Plugins.Authoring;
namespace Inno.Scripting.Compiler;
/// <summary>
/// Produces deterministic runtime and editor script artifacts from one authoring snapshot.
/// </summary>
public sealed class ScriptCompiler
{
private readonly AssetPipeline m_assets;
private readonly ScriptArtifactCache m_artifacts;
private readonly ScriptCompilerOptions m_options;
private readonly PluginEnvironment m_plugins;
/// <summary>
/// Creates a compiler over explicit authoring services owned by one host.
/// </summary>
/// <param name="options">
/// The project and derived-cache locations used by compilation.
/// </param>
/// <param name="assets">
/// The authoring asset pipeline supplying committed source artifacts.
/// </param>
/// <param name="plugins">
/// The Plugin environment supplying the candidate Plugin source generation.
/// </param>
/// <exception cref="ArgumentNullException">
/// Thrown when an owner argument is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when the project root is empty.
/// </exception>
public ScriptCompiler(
ScriptCompilerOptions options,
AssetPipeline assets,
PluginEnvironment plugins
) {
ArgumentNullException.ThrowIfNull(options);
ArgumentNullException.ThrowIfNull(assets);
ArgumentNullException.ThrowIfNull(plugins);
ArgumentNullException.ThrowIfNull(options.compilationEnvironment);
ArgumentException.ThrowIfNullOrWhiteSpace(options.projectRootDirectory);
m_options = new ScriptCompilerOptions
{
projectRootDirectory = System.IO.Path.GetFullPath(options.projectRootDirectory),
compilationEnvironment = options.compilationEnvironment
};
m_assets = assets;
m_plugins = plugins;
m_artifacts = new ScriptArtifactCache(m_options.outputDirectory);
}
/// <summary>
/// Regenerates IDE project files from the current source graph and logical API references.
/// </summary>
/// <exception cref="InvalidOperationException">
/// Thrown when the authoring asset pipeline is not initialized.
/// </exception>
public void GenerateProjectFiles()
{
ScriptProjectGenerator.Generate(
m_options,
m_assets,
m_plugins);
}
/// <summary>
/// Compiles a complete runtime and editor candidate generation without activating it.
/// </summary>
/// <remarks>
/// Source discovery captures live inputs on the owner thread. Reference generation, Roslyn and
/// artifact writes run in the background; progress observers must accept callbacks from either thread.
/// Retain the source generation until the returned operation drains, including after cancellation.
/// Complete cache trees use Core IO atomic publication and replacement. A committed cache remains
/// valid if cleanup of its previous tree fails; compilation does not activate either generation.
/// </remarks>
/// <param name="progress">
/// Optional observer for monotonic compiler progress.
/// </param>
/// <param name="cancellationToken">
/// The token that cancels compilation before an artifact generation is committed.
/// </param>
/// <returns>
/// The immutable diagnostics and artifacts produced by the compilation attempt.
/// </returns>
/// <exception cref="OperationCanceledException">
/// Thrown when <paramref name="cancellationToken"/> is canceled.
/// </exception>
/// <exception cref="IOException">
/// Artifact publication fails, or cleanup fails after a complete cache tree commits.
/// </exception>
/// <exception cref="UnauthorizedAccessException">
/// The filesystem continues denying artifact access after the bounded Core IO wait.
/// </exception>
/// <exception cref="AggregateException">
/// Cache replacement and restoration both fail; the exception identifies the preserved previous tree.
/// </exception>
/// <param name="sourceSnapshot">
/// Optional isolated authoring sources. Capture on its owner thread and keep its transaction
/// alive until compilation drains; null selects the current Plugin candidate or active sources.
/// </param>
public ValueTask<ScriptCompilationResult> CompileAuthoringGenerationAsync(
IProgress<ScriptCompilationProgress>? progress = null,
CancellationToken cancellationToken = default,
IAssetSourceSnapshot? sourceSnapshot = null
)
=> ScriptCompilerEngine.CompileAsync(
m_options,
m_assets,
m_plugins,
includeEditor: true,
targetRuntimeDirectory: null,
progress is null
? null
: (
fraction,
stage
) => progress.Report(new ScriptCompilationProgress(fraction, stage)),
cancellationToken,
sourceSnapshot);
/// <summary>
/// Compiles only the runtime assembly closure required by a deployed Player and binds it to that Player runtime.
/// </summary>
/// <remarks>
/// Complete cache trees use Core IO atomic publication and replacement. Cancellation before commit
/// preserves the previous tree; cancellation does not undo a committed cache. Cleanup failure after
/// commit preserves the installed tree and remaining backup without activating a generation.
/// </remarks>
/// <param name="targetRuntimeDirectory">
/// The verified Player Support Pack directory whose runtime assemblies will execute the emitted scripts.
/// </param>
/// <param name="progress">
/// Optional observer for monotonic compiler progress.
/// </param>
/// <param name="cancellationToken">
/// The token that cancels compilation before an artifact generation is committed.
/// </param>
/// <returns>
/// The immutable diagnostics and runtime-only artifacts produced by the compilation attempt.
/// </returns>
/// <exception cref="OperationCanceledException">
/// Thrown when <paramref name="cancellationToken"/> is canceled.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when <paramref name="targetRuntimeDirectory"/> is empty.
/// </exception>
/// <exception cref="DirectoryNotFoundException">
/// Thrown when <paramref name="targetRuntimeDirectory"/> does not exist.
/// </exception>
/// <exception cref="InvalidDataException">
/// Thrown when the target runtime has no valid Inno runtime assembly closure.
/// </exception>
/// <exception cref="IOException">
/// Artifact publication fails, or cleanup fails after a complete cache tree commits.
/// </exception>
/// <exception cref="UnauthorizedAccessException">
/// The filesystem continues denying artifact access after the bounded Core IO wait.
/// </exception>
/// <exception cref="AggregateException">
/// Cache replacement and restoration both fail; the exception identifies the preserved previous tree.
/// </exception>
public ValueTask<ScriptCompilationResult> CompileRuntimeDeploymentAsync(
string targetRuntimeDirectory,
IProgress<ScriptCompilationProgress>? progress = null,
CancellationToken cancellationToken = default
) {
ArgumentException.ThrowIfNullOrWhiteSpace(targetRuntimeDirectory);
return ScriptCompilerEngine.CompileAsync(
m_options,
m_assets,
m_plugins,
includeEditor: false,
targetRuntimeDirectory: targetRuntimeDirectory,
progress is null
? null
: (
fraction,
stage
) => progress.Report(new ScriptCompilationProgress(fraction, stage)),
cancellationToken);
}
/// <summary>
/// Removes unreferenced compiler generations while retaining the supplied active directories.
/// </summary>
/// <param name="retainedDirectories">
/// The generation directories that remain reachable from active runtime sessions.
/// </param>
/// <returns>
/// The number of obsolete generation directories removed from the compiler cache.
/// </returns>
public int CollectArtifacts(IEnumerable<string?> retainedDirectories)
{
ArgumentNullException.ThrowIfNull(retainedDirectories);
return m_artifacts.Collect(retainedDirectories);
}
}