@smoothbricks/nx-plugin 0.4.25 → 0.4.26
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/README.md +144 -41
- package/dist/bin/smoo-nx-exec.js +3 -14
- package/dist/cargo-closure-input.d.ts +13 -15
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -37
- package/dist/cargo-source-hash.d.ts +12 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +416 -32
- package/dist/cargo-workspace.d.ts +7 -7
- package/dist/cargo-workspace.js +8 -8
- package/dist/ensure-built.d.ts +6 -0
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +79 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -96
- package/dist/managed-assets.d.ts +6 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +6 -2
- package/dist/workspace-manifest.d.ts +0 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/envrc +6 -1
- package/managed/raw/tooling/direnv/developer-links.ts +43 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +1 -0
- package/managed/raw/tooling/direnv/inherited-devenv.ts +69 -19
- package/managed/raw/tooling/direnv/setup-environment.ts +79 -2
- package/nextest.toml +3 -37
- package/package.json +2 -2
- package/src/__tests__/counted-cargo-process.ts +286 -0
- package/src/__tests__/counted-cargo.ts +711 -0
- package/src/__tests__/fixture-cargo-home.ts +36 -0
- package/src/__tests__/fixture-nx-env.ts +93 -3
- package/src/bin/smoo-nx-exec.ts +3 -14
- package/src/bounded-test-policy.test.ts +0 -1
- package/src/cargo-closure-input.test.ts +313 -15
- package/src/cargo-closure-input.ts +42 -50
- package/src/cargo-resolve-cache.test.ts +975 -0
- package/src/cargo-source-hash.test.ts +17 -3
- package/src/cargo-source-hash.ts +447 -37
- package/src/cargo-workspace.ts +8 -8
- package/src/ensure-built.test.ts +122 -20
- package/src/ensure-built.ts +82 -5
- package/src/index.test.ts +203 -107
- package/src/index.ts +86 -115
- package/src/managed-assets.ts +12 -0
- package/src/manifest-hash.ts +7 -2
- package/src/nextest-partitions.test.ts +150 -0
- package/src/nx-cache-bound.test.ts +114 -0
- package/src/nx-resident-graph-workers.test.ts +121 -0
- package/src/nx-store-resolution.test.ts +98 -0
- package/src/task-history-namespace.test.ts +183 -0
- package/src/workspace-manifest.ts +0 -1
- package/test-timings.json +30 -28
- package/src/__tests__/in-process-nx-index.ts +0 -9
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { execFileSync, spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { channel } from 'node:diagnostics_channel';
|
|
4
|
+
import { constants, realpathSync, statSync } from 'node:fs';
|
|
5
|
+
import { access, lstat, mkdir, readdir, readFile, readlink, realpath, rename, rm, stat, writeFile, } from 'node:fs/promises';
|
|
6
|
+
import { homedir } from 'node:os';
|
|
7
|
+
import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
8
|
+
import native from 'nx/src/native/index.js';
|
|
9
|
+
import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory.js';
|
|
10
|
+
import { CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
|
|
11
|
+
const { FileLock, IS_WASM, WorkspaceContext } = native;
|
|
12
|
+
const cargoResolveEvents = channel('@smoothbricks/nx-plugin:cargo-resolve');
|
|
6
13
|
/**
|
|
7
14
|
* Narrowed field by field, not by typia: graph inference imports this module,
|
|
8
15
|
* and a workspace that loads the plugin from its sources runs them without
|
|
@@ -30,6 +37,9 @@ function parseCargoMetadata(json) {
|
|
|
30
37
|
targets: list(member(pkg, 'targets'), 'package targets').map((target) => ({
|
|
31
38
|
src_path: text(member(target, 'src_path'), 'target src_path'),
|
|
32
39
|
})),
|
|
40
|
+
...(member(pkg, 'governing_manifest_path') === undefined
|
|
41
|
+
? {}
|
|
42
|
+
: { governing_manifest_path: text(member(pkg, 'governing_manifest_path'), 'governing manifest') }),
|
|
33
43
|
})),
|
|
34
44
|
resolve: resolveGraph === null
|
|
35
45
|
? null
|
|
@@ -45,6 +55,58 @@ function parseCargoMetadata(json) {
|
|
|
45
55
|
workspace_root: text(member(document, 'workspace_root'), 'workspace_root'),
|
|
46
56
|
};
|
|
47
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Nx workers handle termination by exiting, so their exit hook kills owned
|
|
60
|
+
* Cargo groups. Standalone callers need signal forwarding after detaching
|
|
61
|
+
* Cargo from the terminal; handlers are installed only where the caller has
|
|
62
|
+
* not already chosen a signal disposition, and removed after the last child.
|
|
63
|
+
* Uncatchable SIGKILL cannot execute either hook.
|
|
64
|
+
*/
|
|
65
|
+
const cargoChildren = new Set();
|
|
66
|
+
function killCargoChild(child) {
|
|
67
|
+
if (process.platform === 'win32' || child.pid === undefined)
|
|
68
|
+
child.kill('SIGKILL');
|
|
69
|
+
else {
|
|
70
|
+
try {
|
|
71
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'ESRCH'))
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function killCargoChildren() {
|
|
80
|
+
for (const child of cargoChildren)
|
|
81
|
+
killCargoChild(child);
|
|
82
|
+
}
|
|
83
|
+
const forwardedSignals = new Set();
|
|
84
|
+
const cargoSignalHandlers = {
|
|
85
|
+
SIGINT: () => forwardCargoSignal('SIGINT'),
|
|
86
|
+
SIGTERM: () => forwardCargoSignal('SIGTERM'),
|
|
87
|
+
SIGHUP: () => forwardCargoSignal('SIGHUP'),
|
|
88
|
+
};
|
|
89
|
+
function removeCargoSignalHandlers() {
|
|
90
|
+
for (const signal of forwardedSignals)
|
|
91
|
+
process.removeListener(signal, cargoSignalHandlers[signal]);
|
|
92
|
+
forwardedSignals.clear();
|
|
93
|
+
}
|
|
94
|
+
function forwardCargoSignal(signal) {
|
|
95
|
+
killCargoChildren();
|
|
96
|
+
removeCargoSignalHandlers();
|
|
97
|
+
process.kill(process.pid, signal);
|
|
98
|
+
}
|
|
99
|
+
function ownCargoChildren() {
|
|
100
|
+
process.on('exit', killCargoChildren);
|
|
101
|
+
for (const signal of Object.keys(cargoSignalHandlers)) {
|
|
102
|
+
if (signal !== 'SIGINT' && signal !== 'SIGTERM' && signal !== 'SIGHUP')
|
|
103
|
+
continue;
|
|
104
|
+
if (process.listenerCount(signal) !== 0)
|
|
105
|
+
continue;
|
|
106
|
+
process.on(signal, cargoSignalHandlers[signal]);
|
|
107
|
+
forwardedSignals.add(signal);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
48
110
|
/**
|
|
49
111
|
* Cargo's stdout, or its failure with Cargo's stderr in the message. Not
|
|
50
112
|
* `promisify` from `node:util`: importing that module makes Node probe color
|
|
@@ -54,9 +116,67 @@ function parseCargoMetadata(json) {
|
|
|
54
116
|
* every run.
|
|
55
117
|
*/
|
|
56
118
|
function runCargo(args, cwd) {
|
|
57
|
-
//
|
|
119
|
+
// spawn forwards detached groups; execFile does not. The public ES2022
|
|
120
|
+
// library API requires the constructor form, not Promise.withResolvers.
|
|
58
121
|
return new Promise((settle, reject) => {
|
|
59
|
-
|
|
122
|
+
const child = spawn('cargo', args, {
|
|
123
|
+
cwd,
|
|
124
|
+
detached: process.platform !== 'win32',
|
|
125
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
126
|
+
});
|
|
127
|
+
let stdout = '';
|
|
128
|
+
let stderr = '';
|
|
129
|
+
let stdoutBytes = 0;
|
|
130
|
+
let stderrBytes = 0;
|
|
131
|
+
let failure;
|
|
132
|
+
const fail = (error) => {
|
|
133
|
+
failure ??= error;
|
|
134
|
+
killCargoChild(child);
|
|
135
|
+
};
|
|
136
|
+
child.stdout.setEncoding('utf8');
|
|
137
|
+
child.stderr.setEncoding('utf8');
|
|
138
|
+
child.stdout.on('data', (chunk) => {
|
|
139
|
+
if (failure !== undefined)
|
|
140
|
+
return;
|
|
141
|
+
stdoutBytes += Buffer.byteLength(chunk);
|
|
142
|
+
if (stdoutBytes > 64 * 1024 * 1024) {
|
|
143
|
+
fail(new Error('Cargo stdout exceeded 64 MiB'));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
stdout += chunk;
|
|
147
|
+
});
|
|
148
|
+
child.stderr.on('data', (chunk) => {
|
|
149
|
+
if (failure !== undefined)
|
|
150
|
+
return;
|
|
151
|
+
stderrBytes += Buffer.byteLength(chunk);
|
|
152
|
+
if (stderrBytes > 64 * 1024 * 1024) {
|
|
153
|
+
fail(new Error('Cargo stderr exceeded 64 MiB'));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
stderr += chunk;
|
|
157
|
+
});
|
|
158
|
+
child.on('error', (error) => {
|
|
159
|
+
failure ??= error;
|
|
160
|
+
});
|
|
161
|
+
child.stdout.on('error', fail);
|
|
162
|
+
child.stderr.on('error', fail);
|
|
163
|
+
child.on('close', (code, signal) => {
|
|
164
|
+
cargoChildren.delete(child);
|
|
165
|
+
if (cargoChildren.size === 0) {
|
|
166
|
+
process.removeListener('exit', killCargoChildren);
|
|
167
|
+
removeCargoSignalHandlers();
|
|
168
|
+
}
|
|
169
|
+
if (failure !== undefined)
|
|
170
|
+
reject(failure);
|
|
171
|
+
else if (code !== 0) {
|
|
172
|
+
reject(new Error(`cargo ${args.join(' ')} failed (${signal ?? code}): ${stderr.trim()}`));
|
|
173
|
+
}
|
|
174
|
+
else
|
|
175
|
+
settle(stdout);
|
|
176
|
+
});
|
|
177
|
+
if (cargoChildren.size === 0)
|
|
178
|
+
ownCargoChildren();
|
|
179
|
+
cargoChildren.add(child);
|
|
60
180
|
});
|
|
61
181
|
}
|
|
62
182
|
/** Directories the hash never descends into: build output, VCS and volume metadata, installed packages. */
|
|
@@ -97,40 +217,304 @@ export const CARGO_ANCESTOR_INPUTS = ['Cargo.toml', '.cargo/config', '.cargo/con
|
|
|
97
217
|
// on stderr ("Blocking waiting for file lock on package cache") a
|
|
98
218
|
// timing-dependent number of times when Nx hashes many tasks at once, which
|
|
99
219
|
// made one unchanged tree produce four different task hashes per run. Cargo's
|
|
100
|
-
// stderr is kept for the failure path only, where
|
|
220
|
+
// stderr is kept for the failure path only, where runCargo includes it in the
|
|
101
221
|
// rejected error. Git runs under the same rule.
|
|
102
222
|
const CHILD_STDIO = ['ignore', 'pipe', 'pipe'];
|
|
103
|
-
/**
|
|
104
|
-
export
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
223
|
+
/** A Cargo resolution refusal: no stale closure or runtime whole-workspace substitute is safe. */
|
|
224
|
+
export class CargoMetadataError extends Error {
|
|
225
|
+
manifestPath;
|
|
226
|
+
constructor(manifestPath, cause) {
|
|
227
|
+
const detail = cause instanceof Error
|
|
228
|
+
? `${cause.name}: ${cause.message}`
|
|
229
|
+
: typeof cause === 'object' && cause !== null && 'message' in cause
|
|
230
|
+
? String(cause.message)
|
|
231
|
+
: String(cause);
|
|
232
|
+
super(`Locked offline Cargo resolution failed for ${manifestPath}: ${detail}`, { cause });
|
|
233
|
+
this.name = 'CargoMetadataError';
|
|
234
|
+
this.manifestPath = manifestPath;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const resolves = new Map();
|
|
238
|
+
const RESOLVE_CACHE_SCHEMA = 'cargo-resolve-v1';
|
|
239
|
+
/**
|
|
240
|
+
* The full manifest SET, not merely the last closure: adding a glob workspace
|
|
241
|
+
* member must invalidate resolution even when Cargo.lock did not change.
|
|
242
|
+
* Graph callers supply Nx's already-current index; standalone hash callers
|
|
243
|
+
* take a fresh native snapshot. File contents below are read directly so an
|
|
244
|
+
* edit within Nx's mtime granularity cannot reuse a stale resolution.
|
|
245
|
+
*/
|
|
246
|
+
function resolutionFiles(root, manifest, cargo, indexed) {
|
|
247
|
+
const paths = new Set([manifest]);
|
|
248
|
+
for (const file of indexed)
|
|
249
|
+
paths.add(resolve(root, file));
|
|
250
|
+
for (const pkg of cargo?.local ?? []) {
|
|
251
|
+
paths.add(pkg.manifest);
|
|
252
|
+
paths.add(pkg.governingManifest);
|
|
253
|
+
}
|
|
254
|
+
if (cargo !== null)
|
|
255
|
+
paths.add(join(cargo.root, 'Cargo.toml'));
|
|
256
|
+
const directories = new Set([root]);
|
|
257
|
+
for (const file of paths)
|
|
258
|
+
directories.add(dirname(file));
|
|
259
|
+
for (const directory of directories) {
|
|
260
|
+
paths.add(join(directory, 'Cargo.lock'));
|
|
261
|
+
for (let ancestor = directory;; ancestor = dirname(ancestor)) {
|
|
262
|
+
paths.add(join(ancestor, '.cargo/config'));
|
|
263
|
+
paths.add(join(ancestor, '.cargo/config.toml'));
|
|
264
|
+
paths.add(join(ancestor, 'rust-toolchain'));
|
|
265
|
+
paths.add(join(ancestor, 'rust-toolchain.toml'));
|
|
266
|
+
paths.add(join(ancestor, 'Cargo.toml'));
|
|
267
|
+
if (dirname(ancestor) === ancestor)
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
for (const pin of CARGO_TOOLCHAIN_PIN_INPUTS)
|
|
272
|
+
paths.add(pin.replace('{workspaceRoot}', root));
|
|
273
|
+
const cargoHome = resolve(process.env.CARGO_HOME ?? join(homedir(), '.cargo'));
|
|
274
|
+
paths.add(join(cargoHome, 'config'));
|
|
275
|
+
paths.add(join(cargoHome, 'config.toml'));
|
|
276
|
+
return paths;
|
|
277
|
+
}
|
|
278
|
+
/** Toolchain selection can change even while the declared pin's bytes do not. */
|
|
279
|
+
async function cargoExecutable() {
|
|
280
|
+
for (const directory of (process.env.PATH ?? '').split(delimiter)) {
|
|
281
|
+
const executable = resolve(directory, process.platform === 'win32' ? 'cargo.exe' : 'cargo');
|
|
282
|
+
try {
|
|
283
|
+
await access(executable, constants.X_OK);
|
|
284
|
+
return await realpath(executable);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
if (!(error instanceof Error &&
|
|
288
|
+
'code' in error &&
|
|
289
|
+
(error.code === 'ENOENT' || error.code === 'EACCES' || error.code === 'ENOTDIR')))
|
|
290
|
+
throw error;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return '<cargo-not-on-PATH>';
|
|
294
|
+
}
|
|
295
|
+
async function resolutionKey(root, manifest, cargo, indexed) {
|
|
296
|
+
const cargoHome = resolve(process.env.CARGO_HOME ?? join(homedir(), '.cargo'));
|
|
297
|
+
const executable = await cargoExecutable();
|
|
298
|
+
const hash = createHash('sha256').update(`${RESOLVE_CACHE_SCHEMA}\0${root}\0${manifest}\0${cargoHome}\0${executable}\0${process.env.RUSTUP_TOOLCHAIN ?? ''}\0${process.env.RUSTUP_HOME ?? ''}\0`);
|
|
299
|
+
for (const file of [...resolutionFiles(root, manifest, cargo, indexed)].sort()) {
|
|
300
|
+
hash.update(file).update('\0');
|
|
301
|
+
try {
|
|
302
|
+
const [bytes, canonical] = await Promise.all([readFile(file), realpath(file)]);
|
|
303
|
+
hash.update(`${canonical}\0${bytes.length}\0`).update(bytes);
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
|
|
307
|
+
throw error;
|
|
308
|
+
hash.update('missing');
|
|
309
|
+
}
|
|
310
|
+
hash.update('\0');
|
|
311
|
+
}
|
|
312
|
+
return hash.digest('hex');
|
|
313
|
+
}
|
|
314
|
+
function cargoFromMetadata(metadata) {
|
|
114
315
|
return {
|
|
115
|
-
root:
|
|
316
|
+
root: metadata.workspace_root,
|
|
116
317
|
members: new Set(metadata.workspace_members),
|
|
117
|
-
local
|
|
318
|
+
local: metadata.packages
|
|
319
|
+
.filter((pkg) => pkg.source === null)
|
|
320
|
+
.map((pkg) => {
|
|
321
|
+
if (pkg.governing_manifest_path === undefined)
|
|
322
|
+
throw new Error('Cargo cache omitted a governing manifest');
|
|
323
|
+
return {
|
|
324
|
+
id: pkg.id,
|
|
325
|
+
directory: dirname(pkg.manifest_path),
|
|
326
|
+
manifest: pkg.manifest_path,
|
|
327
|
+
sources: pkg.targets.map((target) => target.src_path),
|
|
328
|
+
governingManifest: pkg.governing_manifest_path,
|
|
329
|
+
};
|
|
330
|
+
}),
|
|
118
331
|
edges: metadata.resolve === null
|
|
119
332
|
? null
|
|
120
|
-
: new Map(metadata.resolve.nodes.map((node) => [node.id, node.deps.map((
|
|
333
|
+
: new Map(metadata.resolve.nodes.map((node) => [node.id, node.deps.map((dep) => dep.pkg)])),
|
|
121
334
|
};
|
|
122
335
|
}
|
|
336
|
+
async function loadResolveCache(file) {
|
|
337
|
+
let content;
|
|
338
|
+
try {
|
|
339
|
+
content = await readFile(file, 'utf8');
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
343
|
+
return null;
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
try {
|
|
347
|
+
const newline = content.indexOf('\n');
|
|
348
|
+
const key = content.slice(0, newline);
|
|
349
|
+
if (newline === -1 || !/^[a-f0-9]{64}$/.test(key))
|
|
350
|
+
throw new Error('invalid content-key header');
|
|
351
|
+
const metadata = parseCargoMetadata(content.slice(newline + 1));
|
|
352
|
+
return { key, cargo: cargoFromMetadata(metadata) };
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
process.stderr.write(`@smoothbricks/nx-plugin: discarding corrupt Cargo resolution cache ${file}: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
123
359
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
360
|
+
* One content-keyed resolution per Cargo workspace, across concurrent graph
|
|
361
|
+
* calls and workers. Nx's kernel FileLock releases even if its worker dies;
|
|
362
|
+
* in-process callers join before taking that lock, so a synchronous lock()
|
|
363
|
+
* cannot block the continuation that owns it. A changed key queues behind
|
|
364
|
+
* the old child instead of receiving its stale answer.
|
|
128
365
|
*/
|
|
129
|
-
export async function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
366
|
+
export async function readCargoResolve(manifestPath, cwd, indexed) {
|
|
367
|
+
let manifest = resolve(manifestPath);
|
|
368
|
+
try {
|
|
369
|
+
const root = await realpath(cwd);
|
|
370
|
+
manifest = await realpath(manifest);
|
|
371
|
+
const index = indexed ?? new Set(new WorkspaceContext(root, workspaceDataDirectoryForWorkspace(root)).glob(['**/Cargo.toml']));
|
|
372
|
+
const identity = createHash('sha256').update(`${RESOLVE_CACHE_SCHEMA}\0${root}\0${manifest}`).digest('hex');
|
|
373
|
+
const directory = join(workspaceDataDirectoryForWorkspace(root), 'cargo-resolve', identity);
|
|
374
|
+
const file = join(directory, 'entry.cache');
|
|
375
|
+
let state = resolves.get(identity);
|
|
376
|
+
if (state === undefined) {
|
|
377
|
+
const created = { ready: Promise.resolve(), cached: null };
|
|
378
|
+
created.ready = loadResolveCache(file).then((cached) => {
|
|
379
|
+
created.cached = cached;
|
|
380
|
+
});
|
|
381
|
+
resolves.set(identity, created);
|
|
382
|
+
state = created;
|
|
383
|
+
try {
|
|
384
|
+
await created.ready;
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
resolves.delete(identity);
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
else
|
|
392
|
+
await state.ready;
|
|
393
|
+
for (let joined = 0; joined <= 3; joined += 1) {
|
|
394
|
+
const key = await resolutionKey(root, manifest, state.cached?.cargo ?? null, index);
|
|
395
|
+
const pending = state.pending;
|
|
396
|
+
if (pending !== undefined) {
|
|
397
|
+
if (joined === 3)
|
|
398
|
+
break;
|
|
399
|
+
if (cargoResolveEvents.hasSubscribers)
|
|
400
|
+
cargoResolveEvents.publish({ phase: 'join', manifest });
|
|
401
|
+
try {
|
|
402
|
+
await pending.promise;
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
// Sharers of a refused key receive its refusal; a changed key still
|
|
406
|
+
// needs its own resolution after the old flight releases the lock.
|
|
407
|
+
if (pending.key === key)
|
|
408
|
+
throw error;
|
|
409
|
+
}
|
|
410
|
+
// Re-key every joiner with the discovered paths, including an external
|
|
411
|
+
// manifest edited after the flight's last validation, before publication.
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (state.cached?.key === key)
|
|
415
|
+
return state.cached.cargo;
|
|
416
|
+
if (joined === 3)
|
|
417
|
+
break;
|
|
418
|
+
const active = state;
|
|
419
|
+
const promise = resolveAndCache(root, manifest, index, directory, file, active);
|
|
420
|
+
active.pending = { key, promise };
|
|
421
|
+
try {
|
|
422
|
+
return await promise;
|
|
423
|
+
}
|
|
424
|
+
finally {
|
|
425
|
+
if (active.pending?.promise === promise)
|
|
426
|
+
delete active.pending;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
throw new Error('Cargo resolution inputs kept changing across three consecutive in-flight queries');
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
if (error instanceof CargoMetadataError)
|
|
433
|
+
throw error;
|
|
434
|
+
throw new CargoMetadataError(manifest, error);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
async function resolveAndCache(root, manifest, indexed, directory, file, state) {
|
|
438
|
+
if (IS_WASM)
|
|
439
|
+
throw new Error('Cargo resolution requires the native Nx file lock; a WASM Nx host cannot own Cargo children');
|
|
440
|
+
await mkdir(directory, { recursive: true });
|
|
441
|
+
const lockFile = join(directory, 'resolve.lock');
|
|
442
|
+
const lock = new FileLock(lockFile);
|
|
443
|
+
while (lock.check())
|
|
444
|
+
await lock.wait();
|
|
445
|
+
// Nx's lock() is synchronous: losing this inter-process check/acquire race
|
|
446
|
+
// can block for one foreign flight. Only the in-process leader reaches it.
|
|
447
|
+
lock.lock();
|
|
448
|
+
try {
|
|
449
|
+
// Another worker may have populated it while this worker waited.
|
|
450
|
+
state.cached = await loadResolveCache(file);
|
|
451
|
+
let inputs = state.cached?.cargo ?? null;
|
|
452
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
453
|
+
const before = await resolutionKey(root, manifest, inputs, indexed);
|
|
454
|
+
if (state.cached?.key === before)
|
|
455
|
+
return state.cached.cargo;
|
|
456
|
+
const knownFiles = resolutionFiles(root, manifest, inputs, indexed);
|
|
457
|
+
// A filesystem timestamp, not a sandbox's wall clock: a newly
|
|
458
|
+
// discovered external input edited during this flight requires replay.
|
|
459
|
+
await writeFile(lockFile, '');
|
|
460
|
+
const started = (await stat(lockFile)).mtimeMs;
|
|
461
|
+
const metadata = await resolveCargoMetadata(manifest, root);
|
|
462
|
+
const cargo = cargoFromMetadata(metadata);
|
|
463
|
+
// Capture the published key before validation. Reading it afterwards
|
|
464
|
+
// could pair a post-edit key with Cargo's pre-edit answer.
|
|
465
|
+
const key = await resolutionKey(root, manifest, cargo, indexed);
|
|
466
|
+
let changed = before !== (await resolutionKey(root, manifest, inputs, indexed));
|
|
467
|
+
for (const added of resolutionFiles(root, manifest, cargo, indexed)) {
|
|
468
|
+
if (knownFiles.has(added))
|
|
469
|
+
continue;
|
|
470
|
+
try {
|
|
471
|
+
if ((await stat(added)).mtimeMs >= started)
|
|
472
|
+
changed = true;
|
|
473
|
+
}
|
|
474
|
+
catch (error) {
|
|
475
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
|
|
476
|
+
throw error;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (changed) {
|
|
480
|
+
inputs = cargo;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
484
|
+
try {
|
|
485
|
+
await writeFile(temporary, `${key}\n${JSON.stringify(metadata)}\n`);
|
|
486
|
+
await rename(temporary, file);
|
|
487
|
+
}
|
|
488
|
+
finally {
|
|
489
|
+
await rm(temporary, { force: true });
|
|
490
|
+
}
|
|
491
|
+
state.cached = { key, cargo };
|
|
492
|
+
return cargo;
|
|
493
|
+
}
|
|
494
|
+
throw new Error('Cargo resolution inputs kept changing during three consecutive locked offline queries');
|
|
495
|
+
}
|
|
496
|
+
finally {
|
|
497
|
+
lock.unlock();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async function resolveCargoMetadata(manifestPath, cwd) {
|
|
501
|
+
const stdout = await runCargo(['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', manifestPath], cwd);
|
|
502
|
+
const metadata = parseCargoMetadata(stdout);
|
|
503
|
+
metadata.workspace_root = await realpath(metadata.workspace_root);
|
|
504
|
+
const members = new Set(metadata.workspace_members);
|
|
505
|
+
// Sequential: the metadata flight owns every Cargo process it starts,
|
|
506
|
+
// including the one-time governing-workspace lookups for path dependencies.
|
|
507
|
+
for (const pkg of metadata.packages) {
|
|
508
|
+
if (pkg.source !== null)
|
|
509
|
+
continue;
|
|
510
|
+
pkg.manifest_path = await realpath(pkg.manifest_path);
|
|
511
|
+
for (const target of pkg.targets)
|
|
512
|
+
target.src_path = await realpath(target.src_path);
|
|
513
|
+
pkg.governing_manifest_path = members.has(pkg.id)
|
|
514
|
+
? join(metadata.workspace_root, 'Cargo.toml')
|
|
515
|
+
: await realpath((await runCargo(['locate-project', '--workspace', '--manifest-path', pkg.manifest_path, '--message-format', 'plain'], cwd)).trim());
|
|
516
|
+
}
|
|
517
|
+
return metadata;
|
|
134
518
|
}
|
|
135
519
|
export async function hashCargoPathInputs(manifestPath, workspaceRoot, options) {
|
|
136
520
|
const root = await realpath(workspaceRoot);
|
|
@@ -159,7 +543,7 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
159
543
|
}
|
|
160
544
|
directories.add(directory);
|
|
161
545
|
files.add(pkg.manifest);
|
|
162
|
-
files.add(
|
|
546
|
+
files.add(pkg.governingManifest);
|
|
163
547
|
packageSources.push(...pkg.sources);
|
|
164
548
|
// A member can inherit edition, lint policy, dependencies and
|
|
165
549
|
// profiles from a workspace above its package directory. Those manifests
|
|
@@ -115,9 +115,9 @@ export interface CargoCrossTestTarget {
|
|
|
115
115
|
*/
|
|
116
116
|
export declare function listCargoCrossTestTargets(absoluteProjectRoot: string): CargoCrossTestTarget[];
|
|
117
117
|
/**
|
|
118
|
-
* Tests that nextest.toml singles out
|
|
119
|
-
*
|
|
120
|
-
*
|
|
118
|
+
* Tests that nextest.toml singles out use this suffix before their shard name.
|
|
119
|
+
* The class is hash-partitioned by the same declared count as the ordinary
|
|
120
|
+
* shards, so it never sits in one run that outgrows the target's bound.
|
|
121
121
|
*/
|
|
122
122
|
export declare const CARGO_TEST_EXCEPTIONS_SUFFIX = "exceptions";
|
|
123
123
|
/**
|
|
@@ -138,10 +138,10 @@ export declare function packageNameFromCargoTestTarget(targetName: string): stri
|
|
|
138
138
|
/**
|
|
139
139
|
* The tests nextest.toml singles out with an override, as one filterset.
|
|
140
140
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
141
|
+
* An override can give a test a bound of its own: a raised slow timeout
|
|
142
|
+
* identifies an expensive test that should not delay an otherwise bounded
|
|
143
|
+
* shard. Partition those tests separately, so every target keeps its time
|
|
144
|
+
* bound and each class runs beside the ordinary shards.
|
|
145
145
|
*
|
|
146
146
|
* Deriving this from the config that declares the classes, rather than
|
|
147
147
|
* restating their filters, means adding an override there is the whole change —
|
package/dist/cargo-workspace.js
CHANGED
|
@@ -567,9 +567,9 @@ export function listCargoCrossTestTargets(absoluteProjectRoot) {
|
|
|
567
567
|
return crossTargets;
|
|
568
568
|
}
|
|
569
569
|
/**
|
|
570
|
-
* Tests that nextest.toml singles out
|
|
571
|
-
*
|
|
572
|
-
*
|
|
570
|
+
* Tests that nextest.toml singles out use this suffix before their shard name.
|
|
571
|
+
* The class is hash-partitioned by the same declared count as the ordinary
|
|
572
|
+
* shards, so it never sits in one run that outgrows the target's bound.
|
|
573
573
|
*/
|
|
574
574
|
export const CARGO_TEST_EXCEPTIONS_SUFFIX = 'exceptions';
|
|
575
575
|
/**
|
|
@@ -597,16 +597,16 @@ export function packageNameFromCargoTestTarget(targetName) {
|
|
|
597
597
|
}
|
|
598
598
|
const name = targetName
|
|
599
599
|
.slice('cargo-test-'.length)
|
|
600
|
-
.replace(new RegExp(`-(shard[1-9][0-9]*|${CARGO_TEST_EXCEPTIONS_SUFFIX})$`), '');
|
|
600
|
+
.replace(new RegExp(`-(shard[1-9][0-9]*|${CARGO_TEST_EXCEPTIONS_SUFFIX}-shard[1-9][0-9]*)$`), '');
|
|
601
601
|
return name.length === 0 ? null : name;
|
|
602
602
|
}
|
|
603
603
|
/**
|
|
604
604
|
* The tests nextest.toml singles out with an override, as one filterset.
|
|
605
605
|
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
606
|
+
* An override can give a test a bound of its own: a raised slow timeout
|
|
607
|
+
* identifies an expensive test that should not delay an otherwise bounded
|
|
608
|
+
* shard. Partition those tests separately, so every target keeps its time
|
|
609
|
+
* bound and each class runs beside the ordinary shards.
|
|
610
610
|
*
|
|
611
611
|
* Deriving this from the config that declares the classes, rather than
|
|
612
612
|
* restating their filters, means adding an override there is the whole change —
|
package/dist/ensure-built.d.ts
CHANGED
|
@@ -124,6 +124,12 @@ export declare function unvouched<Entry>(entries: readonly Entry[], verdicts: re
|
|
|
124
124
|
* the workspace's own `nx` CLI unconditionally.
|
|
125
125
|
*/
|
|
126
126
|
export declare function ensureBuilt(options: EnsureBuiltOptions): Promise<EnsureBuiltResult>;
|
|
127
|
+
/**
|
|
128
|
+
* The nearest directory at or above `from` holding an `nx.json`, or null.
|
|
129
|
+
* The marker this wrapper roots a workspace at when `--workspace-root` is
|
|
130
|
+
* not given.
|
|
131
|
+
*/
|
|
132
|
+
export declare function findNxWorkspaceRoot(from: string): string | null;
|
|
127
133
|
export interface ChildExit {
|
|
128
134
|
readonly code: number | null;
|
|
129
135
|
readonly signal: NodeJS.Signals | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-built.d.ts","sourceRoot":"","sources":["../src/ensure-built.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAiDhE;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnF;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC3D;IAAE,QAAQ,CAAC,IAA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