@loucompanion/forge-bridge 0.1.4-dev.e847c8c66ea9 → 0.1.4-dev.ec3460040366
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/bridge.service.d.ts +1 -0
- package/dist/bridge/bridge.service.js +13 -8
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +15 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +58 -25
- package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/host-runtime-lease.d.ts +3 -1
- package/dist/runtime/host-runtime-lease.js +27 -111
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/session/managed-attempt-tools.js +5 -5
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstatSync, readlinkSync, realpathSync } from "node:fs";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
/**
|
|
6
|
+
* Where a supervised ASP.NET runtime builds and runs from, relative to each project in its
|
|
7
|
+
* graph. Agent builds keep the default `bin/<Configuration>/<TargetFramework>/` output, so they
|
|
8
|
+
* never overwrite (or, on Windows, fail on the locks of) the files a running runtime executes.
|
|
9
|
+
*/
|
|
10
|
+
export const supervisedRuntimeOutputRoot = "bin/forge-runtime";
|
|
11
|
+
// More links than this on one path is a loop (Linux gives up at 40 too).
|
|
12
|
+
const maxPathLinks = 40;
|
|
13
|
+
/**
|
|
14
|
+
* Where a path really is, existing or not yet: its deepest existing ancestor resolved through every
|
|
15
|
+
* symlink and junction, with the rest appended. A lexical path alone lets a link alias another directory.
|
|
16
|
+
* A link whose target does not exist yet still leads to that target, so it is followed by its
|
|
17
|
+
* link text, never taken as its own location; a link loop fails with `path_link_unresolvable`.
|
|
18
|
+
*/
|
|
19
|
+
export async function canonicalExistingPath(target) {
|
|
20
|
+
return await canonicalPathThroughLinks(target, 0);
|
|
21
|
+
}
|
|
22
|
+
async function canonicalPathThroughLinks(target, links) {
|
|
23
|
+
const resolved = path.resolve(target);
|
|
24
|
+
const real = await fs.realpath(resolved).catch(() => null);
|
|
25
|
+
if (real !== null)
|
|
26
|
+
return real;
|
|
27
|
+
if ((await fs.lstat(resolved).catch(() => null))?.isSymbolicLink()) {
|
|
28
|
+
const linkTarget = path.resolve(path.dirname(resolved), await fs.readlink(resolved));
|
|
29
|
+
return await canonicalPathThroughLinks(linkTarget, countedLink(resolved, links));
|
|
30
|
+
}
|
|
31
|
+
const parent = path.dirname(resolved);
|
|
32
|
+
return parent === resolved ? resolved : path.join(await canonicalPathThroughLinks(parent, links), path.basename(resolved));
|
|
33
|
+
}
|
|
34
|
+
/** canonicalExistingPath, for synchronous planning. */
|
|
35
|
+
export function canonicalExistingPathSync(target) {
|
|
36
|
+
return canonicalPathThroughLinksSync(target, 0);
|
|
37
|
+
}
|
|
38
|
+
function canonicalPathThroughLinksSync(target, links) {
|
|
39
|
+
const resolved = path.resolve(target);
|
|
40
|
+
const real = attempt(() => realpathSync.native(resolved));
|
|
41
|
+
if (real !== null)
|
|
42
|
+
return real;
|
|
43
|
+
if (attempt(() => lstatSync(resolved))?.isSymbolicLink()) {
|
|
44
|
+
const linkTarget = path.resolve(path.dirname(resolved), readlinkSync(resolved));
|
|
45
|
+
return canonicalPathThroughLinksSync(linkTarget, countedLink(resolved, links));
|
|
46
|
+
}
|
|
47
|
+
const parent = path.dirname(resolved);
|
|
48
|
+
return parent === resolved ? resolved : path.join(canonicalPathThroughLinksSync(parent, links), path.basename(resolved));
|
|
49
|
+
}
|
|
50
|
+
function attempt(read) {
|
|
51
|
+
try {
|
|
52
|
+
return read();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function countedLink(link, links) {
|
|
59
|
+
if (links >= maxPathLinks) {
|
|
60
|
+
throw new Error(`path_link_unresolvable: ${link} leads through more than ${maxPathLinks} links, so Forge cannot tell where it points.`);
|
|
61
|
+
}
|
|
62
|
+
return links + 1;
|
|
63
|
+
}
|
|
64
|
+
export const fileSystemProjectFiles = {
|
|
65
|
+
read: async (file) => await fs.readFile(file, "utf8").catch(() => null),
|
|
66
|
+
list: async (directory) => await fs.readdir(directory).catch(() => null),
|
|
67
|
+
canonical: canonicalExistingPath,
|
|
68
|
+
};
|
|
69
|
+
// Verbs that write (or, for clean, delete) a project's build output.
|
|
70
|
+
const outputWritingVerbs = new Set(["build", "test", "publish", "pack", "run", "msbuild", "clean"]);
|
|
71
|
+
const releaseByDefaultVerbs = new Set(["publish", "pack"]);
|
|
72
|
+
const optionsWithValues = new Set([
|
|
73
|
+
"-c", "--configuration", "-f", "--framework", "-r", "--runtime", "-o", "--output", "-a", "--arch", "--os",
|
|
74
|
+
"-v", "--verbosity", "-s", "--source", "--artifacts-path", "--project", "--solution", "-e", "--environment",
|
|
75
|
+
"-lp", "--launch-profile", "-l", "--logger", "--filter", "--settings", "--results-directory", "--collect",
|
|
76
|
+
"-d", "--diag", "--test-adapter-path", "--version-suffix", "--blame-hang-timeout", "--blame-crash-dump-type",
|
|
77
|
+
"--blame-hang-dump-type", "--max-parallel-test-modules", "--report-trx-filename",
|
|
78
|
+
]);
|
|
79
|
+
const projectFilePattern = /\.(?:cs|fs|vb)proj$/iu;
|
|
80
|
+
const solutionFilePattern = /\.slnx?$/iu;
|
|
81
|
+
function pathApi(platform) {
|
|
82
|
+
return platform === "win32" ? path.win32 : path.posix;
|
|
83
|
+
}
|
|
84
|
+
export function hostPathPlatform() {
|
|
85
|
+
return process.platform === "win32" ? "win32" : "posix";
|
|
86
|
+
}
|
|
87
|
+
export function isDotnetExecutable(command, platform = hostPathPlatform()) {
|
|
88
|
+
const executable = pathApi(platform).basename(command).toLowerCase();
|
|
89
|
+
return executable === "dotnet" || executable === "dotnet.exe";
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reads a dotnet command's build-output intent: its verb, target candidates, and output
|
|
93
|
+
* settings. Returns null when the command writes no build output. With `holder`, the command is
|
|
94
|
+
* a running runtime's `dotnet run`: `--no-build` does not matter, it executes from the output.
|
|
95
|
+
*/
|
|
96
|
+
export function parseDotnetOutputCommand(command, args, cwd, options = {}) {
|
|
97
|
+
const platform = options.platform ?? hostPathPlatform();
|
|
98
|
+
if (!isDotnetExecutable(command, platform))
|
|
99
|
+
return null;
|
|
100
|
+
const separator = args.indexOf("--");
|
|
101
|
+
const commandArgs = separator < 0 ? args : args.slice(0, separator);
|
|
102
|
+
const verbIndex = commandArgs.findIndex(argument => !argument.startsWith("-"));
|
|
103
|
+
const verb = commandArgs[verbIndex]?.toLowerCase() ?? "";
|
|
104
|
+
if (options.holder ? verb !== "run" : !outputWritingVerbs.has(verb))
|
|
105
|
+
return null;
|
|
106
|
+
const parsed = parseArguments(commandArgs.slice(verbIndex + 1));
|
|
107
|
+
if (!options.holder && verb !== "build" && verb !== "msbuild" && verb !== "clean" && parsed.flags.has("--no-build"))
|
|
108
|
+
return null;
|
|
109
|
+
if (verb === "msbuild" && parsed.msbuildTargets.length > 0
|
|
110
|
+
&& parsed.msbuildTargets.every(target => target.toLowerCase() === "restore"))
|
|
111
|
+
return null;
|
|
112
|
+
const p = pathApi(platform);
|
|
113
|
+
const resolvedCwd = p.resolve(cwd);
|
|
114
|
+
const explicitTargets = ["--project", "--solution"].flatMap(name => parsed.values.get(name) ?? []);
|
|
115
|
+
// `dotnet run` hands positional arguments to the application; other verbs take them as targets.
|
|
116
|
+
const candidates = verb === "run" ? explicitTargets : [...explicitTargets, ...parsed.positionals];
|
|
117
|
+
return {
|
|
118
|
+
verb,
|
|
119
|
+
cwd: resolvedCwd,
|
|
120
|
+
targets: candidates.map(candidate => p.resolve(resolvedCwd, normalizeSeparators(candidate, platform))),
|
|
121
|
+
settings: outputSettings(verb, parsed, resolvedCwd, platform),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function parseArguments(args) {
|
|
125
|
+
const parsed = { flags: new Set(), values: new Map(), properties: new Map(), msbuildTargets: [], positionals: [] };
|
|
126
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
127
|
+
const argument = args[index];
|
|
128
|
+
if (readMsbuildSwitch(argument, parsed))
|
|
129
|
+
continue;
|
|
130
|
+
if (!argument.startsWith("-")) {
|
|
131
|
+
parsed.positionals.push(argument);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const inline = /^(--?[A-Za-z][\w-]*)[=:](.*)$/u.exec(argument);
|
|
135
|
+
const name = (inline?.[1] ?? argument).toLowerCase();
|
|
136
|
+
if (inline && optionsWithValues.has(name))
|
|
137
|
+
parsed.values.set(name, inline[2]);
|
|
138
|
+
else if (optionsWithValues.has(name) && index + 1 < args.length)
|
|
139
|
+
parsed.values.set(name, args[++index]);
|
|
140
|
+
else
|
|
141
|
+
parsed.flags.add(name);
|
|
142
|
+
}
|
|
143
|
+
return parsed;
|
|
144
|
+
}
|
|
145
|
+
/** `-p:`/`-property:` assignments and `-t:`/`-target:` lists, in any of MSBuild's prefix spellings. */
|
|
146
|
+
function readMsbuildSwitch(argument, parsed) {
|
|
147
|
+
const property = /^(?:-{1,2}|\/)(?:p|property):(.+)$/iu.exec(argument);
|
|
148
|
+
if (property) {
|
|
149
|
+
for (const assignment of property[1].split(/[;,]/u)) {
|
|
150
|
+
const equals = assignment.indexOf("=");
|
|
151
|
+
if (equals > 0)
|
|
152
|
+
parsed.properties.set(assignment.slice(0, equals).trim().toLowerCase(), assignment.slice(equals + 1).trim());
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
const target = /^(?:-{1,2}|\/)(?:t|target):(.+)$/iu.exec(argument);
|
|
157
|
+
if (target) {
|
|
158
|
+
parsed.msbuildTargets.push(...target[1].split(/[;,]/u).map(value => value.trim()).filter(Boolean));
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
function outputSettings(verb, parsed, cwd, platform) {
|
|
164
|
+
const p = pathApi(platform);
|
|
165
|
+
const property = (name) => parsed.properties.get(name.toLowerCase()) || null;
|
|
166
|
+
const perProject = (value) => value ? { path: normalizeSeparators(value, platform), perProject: true } : null;
|
|
167
|
+
const fromCwd = (value) => value ? { path: p.resolve(cwd, normalizeSeparators(value, platform)), perProject: false } : null;
|
|
168
|
+
const os = parsed.values.get("--os");
|
|
169
|
+
const arch = parsed.values.get("-a") ?? parsed.values.get("--arch");
|
|
170
|
+
return {
|
|
171
|
+
configuration: parsed.values.get("-c") ?? parsed.values.get("--configuration") ?? property("Configuration")
|
|
172
|
+
?? (releaseByDefaultVerbs.has(verb) ? "Release" : "Debug"),
|
|
173
|
+
framework: parsed.values.get("-f") ?? parsed.values.get("--framework") ?? property("TargetFramework"),
|
|
174
|
+
runtime: parsed.values.get("-r") ?? parsed.values.get("--runtime") ?? property("RuntimeIdentifier")
|
|
175
|
+
?? (os || arch ? `${os ?? "*"}-${arch ?? "*"}` : null),
|
|
176
|
+
outDir: perProject(property("OutDir") ?? property("OutputPath")),
|
|
177
|
+
output: fromCwd(parsed.values.get("-o") ?? parsed.values.get("--output")),
|
|
178
|
+
baseOutputPath: perProject(property("BaseOutputPath")),
|
|
179
|
+
artifactsPath: fromCwd(parsed.values.get("--artifacts-path")) ?? perProject(property("ArtifactsPath")),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function normalizeSeparators(value, platform) {
|
|
183
|
+
return platform === "win32" ? value : value.replaceAll("\\", "/");
|
|
184
|
+
}
|
|
185
|
+
/** True when the arguments already choose where the build output goes. */
|
|
186
|
+
export function declaresDotnetOutput(settings) {
|
|
187
|
+
return Boolean(settings.outDir ?? settings.output ?? settings.baseOutputPath ?? settings.artifactsPath);
|
|
188
|
+
}
|
|
189
|
+
/** True when a project file multi-targets (`<TargetFrameworks>`, even with one entry). */
|
|
190
|
+
export function isMultiTargetedProject(projectXml) {
|
|
191
|
+
return /<TargetFrameworks>\s*[^<\s]/u.test(projectXml.replaceAll(/<!--[\s\S]*?-->/gu, ""));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The directory a project's primary output lands in under these settings. An unknown target
|
|
195
|
+
* framework is the wildcard `*`, which matches any framework in sameOutputDirectory.
|
|
196
|
+
*/
|
|
197
|
+
export function projectOutputDirectory(projectFile, settings, platform = hostPathPlatform(), layout = {}) {
|
|
198
|
+
const p = pathApi(platform);
|
|
199
|
+
const projectDirectory = p.dirname(projectFile);
|
|
200
|
+
const at = (location) => location.perProject ? p.resolve(projectDirectory, location.path) : location.path;
|
|
201
|
+
// OutDir wins over the OutputPath that `-o` sets; a global OutputPath is used as given.
|
|
202
|
+
const explicit = settings.outDir ?? settings.output;
|
|
203
|
+
if (explicit)
|
|
204
|
+
return p.resolve(at(explicit));
|
|
205
|
+
if (settings.artifactsPath) {
|
|
206
|
+
// The SDK's ArtifactsPivots: the configuration, the framework only when the project
|
|
207
|
+
// multi-targets, then an explicit RID, lowercased and joined by `_`.
|
|
208
|
+
const pivot = [
|
|
209
|
+
settings.configuration,
|
|
210
|
+
...(layout.multiTargeted ? [settings.framework ?? "*"] : []),
|
|
211
|
+
...(settings.runtime ? [settings.runtime] : []),
|
|
212
|
+
].join("_").toLowerCase();
|
|
213
|
+
return p.join(artifactsProjectRoot(projectFile, at(settings.artifactsPath), platform), pivot);
|
|
214
|
+
}
|
|
215
|
+
const base = settings.baseOutputPath ? at(settings.baseOutputPath) : p.join(projectDirectory, "bin");
|
|
216
|
+
return p.join(base, settings.configuration, settings.framework ?? "*", ...(settings.runtime ? [settings.runtime] : []));
|
|
217
|
+
}
|
|
218
|
+
function artifactsProjectRoot(projectFile, artifactsPath, platform) {
|
|
219
|
+
const p = pathApi(platform);
|
|
220
|
+
return p.join(artifactsPath, "bin", p.basename(projectFile).replace(projectFilePattern, ""));
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The one directory holding every build output of a project under these settings, whatever
|
|
224
|
+
* configuration or framework they leave open: what a runtime's build receipt verifies. Without
|
|
225
|
+
* the project file's name, an artifacts layout's root is its `bin`, above every project's folder.
|
|
226
|
+
*/
|
|
227
|
+
export function projectOutputRoot(projectDirectory, projectFile, settings, platform = hostPathPlatform()) {
|
|
228
|
+
const p = pathApi(platform);
|
|
229
|
+
const at = (location) => p.resolve(location.perProject ? p.resolve(projectDirectory, location.path) : location.path);
|
|
230
|
+
const explicit = settings.outDir ?? settings.output;
|
|
231
|
+
if (explicit)
|
|
232
|
+
return at(explicit);
|
|
233
|
+
if (settings.artifactsPath) {
|
|
234
|
+
const artifactsPath = at(settings.artifactsPath);
|
|
235
|
+
return projectFile ? artifactsProjectRoot(projectFile, artifactsPath, platform) : p.join(artifactsPath, "bin");
|
|
236
|
+
}
|
|
237
|
+
return settings.baseOutputPath ? at(settings.baseOutputPath) : p.join(projectDirectory, "bin");
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Compares two output directories segment by segment. `*` matches any run of characters inside
|
|
241
|
+
* one segment: `*` is any framework folder, and `debug_*` any framework pivot.
|
|
242
|
+
*/
|
|
243
|
+
export function sameOutputDirectory(left, right, platform = hostPathPlatform()) {
|
|
244
|
+
const segments = (value) => {
|
|
245
|
+
const resolved = pathApi(platform).resolve(value);
|
|
246
|
+
return (platform === "win32" ? resolved.toLowerCase() : resolved).split(/[\\/]+/u).filter(Boolean);
|
|
247
|
+
};
|
|
248
|
+
const a = segments(left);
|
|
249
|
+
const b = segments(right);
|
|
250
|
+
return a.length === b.length && a.every((segment, index) => sameSegment(segment, b[index]));
|
|
251
|
+
}
|
|
252
|
+
function sameSegment(left, right) {
|
|
253
|
+
if (left === right)
|
|
254
|
+
return true;
|
|
255
|
+
const leftOpen = left.includes("*");
|
|
256
|
+
const rightOpen = right.includes("*");
|
|
257
|
+
// `*` never crosses `_`, so two open pivots meet only with the same parts, each pair able to name one value.
|
|
258
|
+
if (leftOpen && rightOpen) {
|
|
259
|
+
const leftParts = left.split("_");
|
|
260
|
+
const rightParts = right.split("_");
|
|
261
|
+
return leftParts.length === rightParts.length && leftParts.every((part, index) => samePivotPart(part, rightParts[index]));
|
|
262
|
+
}
|
|
263
|
+
if (leftOpen)
|
|
264
|
+
return matchesWildcard(left, right);
|
|
265
|
+
return rightOpen && matchesWildcard(right, left);
|
|
266
|
+
}
|
|
267
|
+
/** One `_`-free pivot part: both open ones share a value when their literal start and end agree. */
|
|
268
|
+
function samePivotPart(left, right) {
|
|
269
|
+
if (left === right)
|
|
270
|
+
return true;
|
|
271
|
+
if (!left.includes("*"))
|
|
272
|
+
return matchesWildcard(right, left);
|
|
273
|
+
if (!right.includes("*"))
|
|
274
|
+
return matchesWildcard(left, right);
|
|
275
|
+
const [leftStart, rightStart] = [left.slice(0, left.indexOf("*")), right.slice(0, right.indexOf("*"))];
|
|
276
|
+
const [leftEnd, rightEnd] = [left.slice(left.lastIndexOf("*") + 1), right.slice(right.lastIndexOf("*") + 1)];
|
|
277
|
+
return (leftStart.startsWith(rightStart) || rightStart.startsWith(leftStart))
|
|
278
|
+
&& (leftEnd.endsWith(rightEnd) || rightEnd.endsWith(leftEnd));
|
|
279
|
+
}
|
|
280
|
+
/** `*` stands for one framework or RID value, which never contains the pivot separator `_`. */
|
|
281
|
+
function matchesWildcard(pattern, value) {
|
|
282
|
+
const expression = pattern.split("*").map(part => part.replaceAll(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join("[^_]*");
|
|
283
|
+
return new RegExp(`^${expression}$`, "u").test(value);
|
|
284
|
+
}
|
|
285
|
+
/** ProjectReference Include values of a project file, ignoring commented-out references. */
|
|
286
|
+
export function projectReferenceIncludes(projectXml) {
|
|
287
|
+
const withoutComments = projectXml.replaceAll(/<!--[\s\S]*?-->/gu, "");
|
|
288
|
+
const includes = [];
|
|
289
|
+
for (const match of withoutComments.matchAll(/<ProjectReference\b[^>]*?\bInclude\s*=\s*(?:"([^"]*)"|'([^']*)')/giu)) {
|
|
290
|
+
for (const part of (match[1] ?? match[2] ?? "").split(";")) {
|
|
291
|
+
const trimmed = part.trim();
|
|
292
|
+
if (trimmed)
|
|
293
|
+
includes.push(trimmed);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return includes;
|
|
297
|
+
}
|
|
298
|
+
/** Project paths a .sln or .slnx lists. */
|
|
299
|
+
export function solutionProjectPaths(solution, content) {
|
|
300
|
+
const pattern = /\.slnx$/iu.test(solution)
|
|
301
|
+
? /<Project\b[^>]*?\bPath\s*=\s*"([^"]+)"/giu
|
|
302
|
+
: /^Project\("\{[^}]*\}"\)\s*=\s*"[^"]*"\s*,\s*"([^"]+)"/gmu;
|
|
303
|
+
return [...content.matchAll(pattern)].map(match => match[1].trim()).filter(entry => projectFilePattern.test(entry));
|
|
304
|
+
}
|
|
305
|
+
/** Every project file a command builds: its targets, solution members, and their ProjectReference closure. */
|
|
306
|
+
export async function dotnetCommandProjects(command, files = fileSystemProjectFiles, platform = hostPathPlatform()) {
|
|
307
|
+
const p = pathApi(platform);
|
|
308
|
+
const queue = [...await targetProjectFiles(command, files, platform)];
|
|
309
|
+
const visited = new Map();
|
|
310
|
+
while (queue.length > 0) {
|
|
311
|
+
const projectFile = queue.shift();
|
|
312
|
+
const key = platform === "win32" ? projectFile.toLowerCase() : projectFile;
|
|
313
|
+
if (visited.has(key))
|
|
314
|
+
continue;
|
|
315
|
+
const content = await files.read(projectFile);
|
|
316
|
+
if (content === null)
|
|
317
|
+
continue;
|
|
318
|
+
visited.set(key, projectFile);
|
|
319
|
+
for (const include of projectReferenceIncludes(content)) {
|
|
320
|
+
// An MSBuild property cannot be resolved here.
|
|
321
|
+
if (!include.includes("$("))
|
|
322
|
+
queue.push(p.resolve(p.dirname(projectFile), normalizeSeparators(include, platform)));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return [...visited.values()];
|
|
326
|
+
}
|
|
327
|
+
async function targetProjectFiles(command, files, platform) {
|
|
328
|
+
const fromCandidates = async (candidates) => {
|
|
329
|
+
const found = [];
|
|
330
|
+
for (const candidate of candidates) {
|
|
331
|
+
if (projectFilePattern.test(candidate) || solutionFilePattern.test(candidate))
|
|
332
|
+
found.push(candidate);
|
|
333
|
+
else
|
|
334
|
+
found.push(...((await files.list(candidate)) ?? [])
|
|
335
|
+
.filter(entry => projectFilePattern.test(entry) || solutionFilePattern.test(entry))
|
|
336
|
+
.map(entry => pathApi(platform).join(candidate, entry)));
|
|
337
|
+
}
|
|
338
|
+
return found;
|
|
339
|
+
};
|
|
340
|
+
// A positional value that is no target (an unlisted option's value) leaves the working directory as the target.
|
|
341
|
+
const explicit = await fromCandidates(command.targets);
|
|
342
|
+
const targets = explicit.length > 0 ? explicit : await fromCandidates([command.cwd]);
|
|
343
|
+
const projects = [];
|
|
344
|
+
for (const target of targets) {
|
|
345
|
+
if (!solutionFilePattern.test(target)) {
|
|
346
|
+
projects.push(target);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const content = await files.read(target);
|
|
350
|
+
const p = pathApi(platform);
|
|
351
|
+
for (const entry of content ? solutionProjectPaths(target, content) : []) {
|
|
352
|
+
projects.push(p.resolve(p.dirname(target), normalizeSeparators(entry, platform)));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return projects;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* The projects whose output a build (`writer`) would write while a runtime (`holder`) executes
|
|
359
|
+
* from that same output, in the runtime's graph order (its own project first).
|
|
360
|
+
*/
|
|
361
|
+
export async function findDotnetOutputCollisions(writer, holder, files = fileSystemProjectFiles, platform = hostPathPlatform()) {
|
|
362
|
+
const key = (value) => platform === "win32" ? value.toLowerCase() : value;
|
|
363
|
+
// Projects and outputs compare by real location: a link to the worktree or to an output is the same place.
|
|
364
|
+
const real = files.canonical ?? (async (value) => value);
|
|
365
|
+
const written = new Set(await Promise.all((await dotnetCommandProjects(writer, files, platform))
|
|
366
|
+
.map(async (project) => key(await real(project)))));
|
|
367
|
+
const collisions = [];
|
|
368
|
+
for (const project of await dotnetCommandProjects(holder, files, platform)) {
|
|
369
|
+
const realProject = await real(project);
|
|
370
|
+
if (!written.has(key(realProject)))
|
|
371
|
+
continue;
|
|
372
|
+
const layout = { multiTargeted: isMultiTargetedProject((await files.read(project)) ?? "") };
|
|
373
|
+
const held = await real(projectOutputDirectory(project, holder.settings, platform, layout));
|
|
374
|
+
if (sameOutputDirectory(await real(projectOutputDirectory(project, writer.settings, platform, layout)), held, platform)) {
|
|
375
|
+
collisions.push({ project: realProject, outputDirectory: held });
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return collisions;
|
|
379
|
+
}
|
|
380
|
+
/** A runtime role as a directory name: kept when it is already safe, otherwise a stable digest. */
|
|
381
|
+
export function runtimeOutputName(role) {
|
|
382
|
+
return /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/u.test(role)
|
|
383
|
+
? role
|
|
384
|
+
: createHash("sha256").update(role).digest("hex").slice(0, 16);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Gives a supervised `dotnet run` its own build output, `bin/forge-runtime/<role>/` under each
|
|
388
|
+
* project, unless the configured arguments already choose one. The ASP.NET prebuild forwards the
|
|
389
|
+
* same property to its `dotnet build`, so the runtime builds and runs from that directory.
|
|
390
|
+
*/
|
|
391
|
+
export function isolatedRuntimeOutputArguments(command, args, role, platform = hostPathPlatform()) {
|
|
392
|
+
const runtime = parseDotnetOutputCommand(command, args, ".", { platform, holder: true });
|
|
393
|
+
if (!runtime || declaresDotnetOutput(runtime.settings))
|
|
394
|
+
return args;
|
|
395
|
+
const separator = args.indexOf("--");
|
|
396
|
+
const insertionIndex = separator < 0 ? args.length : separator;
|
|
397
|
+
return [
|
|
398
|
+
...args.slice(0, insertionIndex),
|
|
399
|
+
`-p:OutDir=${supervisedRuntimeOutputRoot}/${runtimeOutputName(role)}/`,
|
|
400
|
+
...args.slice(insertionIndex),
|
|
401
|
+
];
|
|
402
|
+
}
|
|
@@ -73,6 +73,8 @@ export interface HostRuntimeReapOptions {
|
|
|
73
73
|
readonly runnerId: string;
|
|
74
74
|
readonly runnerInstanceId: string;
|
|
75
75
|
readonly nowMs?: number;
|
|
76
|
+
/** Where maintenance reports a degraded lease it released or kept; the bridge log by default. */
|
|
77
|
+
readonly log?: (message: string) => void;
|
|
76
78
|
}
|
|
77
79
|
export interface HostRuntimeReapReport {
|
|
78
80
|
readonly examined: number;
|
|
@@ -224,7 +226,7 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
|
|
|
224
226
|
launchNodeRuntime<T>(dispatchAttemptId: string, fencingToken: string, portName: string, command: NodeRuntimeCommand, launcher: NodeRuntimeCommandLauncher<T>, signal?: AbortSignal): Promise<HostNodeRuntimeLaunch<T>>;
|
|
225
227
|
release(dispatchAttemptId: string, fencingToken: string, preservePreparation?: boolean): Promise<RuntimeIsolationLease | null>;
|
|
226
228
|
private readLedgers;
|
|
227
|
-
|
|
229
|
+
/** Degrades and counts a ledger whose runtime may still be live. A retained released ledger owns no slot, so it is neither changed nor counted. */
|
|
228
230
|
private markLedgerDegraded;
|
|
229
231
|
private rememberDegraded;
|
|
230
232
|
private forgetDegraded;
|