@diffci.com/diffci 0.3.54 → 0.3.56
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-client/src/client/agent-selection.d.ts +9 -2
- package/dist-client/src/client/agent-selection.js +20 -8
- package/dist-client/src/client/agent-setup.js +1 -1
- package/dist-client/src/client/cli.js +19 -7
- package/dist-client/src/client/command-batches.js +3 -2
- package/dist-client/src/client/context.d.ts +2 -0
- package/dist-client/src/client/context.js +51 -2
- package/dist-client/src/client/coverage-map.js +6 -1
- package/dist-client/src/client/full-command.js +22 -14
- package/dist-client/src/client/gate.js +24 -10
- package/dist-client/src/client/hook.d.ts +17 -0
- package/dist-client/src/client/hook.js +53 -1
- package/dist-client/src/client/install.d.ts +6 -0
- package/dist-client/src/client/install.js +29 -1
- package/dist-client/src/client/job-summary.d.ts +1 -1
- package/dist-client/src/client/job-summary.js +2 -1
- package/dist-client/src/client/mcp.js +4 -0
- package/dist-client/src/client/observe.js +4 -3
- package/dist-client/src/client/report.d.ts +8 -1
- package/dist-client/src/client/report.js +11 -0
- package/dist-client/src/client/shared-graph-cache.js +4 -2
- package/dist-client/src/client/telemetry.js +2 -1
- package/dist-client/src/client/usage-signal.d.ts +1 -1
- package/dist-client/src/client/verify-savings.d.ts +6 -0
- package/dist-client/src/client/verify-savings.js +15 -3
- package/dist-client/src/client/verify.js +124 -22
- package/dist-client/src/client/workflow-guard.js +27 -6
- package/dist-client/src/client/workflow-templates.d.ts +11 -1
- package/dist-client/src/client/workflow-templates.js +43 -2
- package/node_modules/@diffci.com/core/README.md +17 -10
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.js +38 -5
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +26 -6
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.d.ts +2 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +7 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js +15 -8
- package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +6 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +38 -5
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +13 -1
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +64 -31
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +22 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +6 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +14 -2
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/planner.js +65 -14
- package/node_modules/@diffci.com/core/dist/planner/planner.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/rust-command.js +43 -1
- package/node_modules/@diffci.com/core/dist/planner/rust-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js +5 -2
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +17 -2
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js +27 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +71 -9
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.d.ts +9 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +259 -18
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.d.ts +3 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js +44 -6
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.d.ts +1 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +338 -24
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +10 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +16 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +76 -5
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +101 -30
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +7 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +56 -9
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/layout.js +4 -1
- package/node_modules/@diffci.com/core/dist/repo/layout.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +10 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/types.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +3 -3
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.d.ts +11 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js +208 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js +2 -2
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +65 -13
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +47 -2
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
- package/node_modules/@diffci.com/core/package.json +1 -0
- package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +38 -5
- package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +21 -6
- package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +7 -2
- package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +15 -8
- package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +6 -2
- package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +37 -5
- package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +8 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +57 -32
- package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +22 -1
- package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +13 -2
- package/node_modules/@diffci.com/core/src/planner/planner.ts +42 -14
- package/node_modules/@diffci.com/core/src/planner/rust-command.ts +37 -1
- package/node_modules/@diffci.com/core/src/planner/script-reads.ts +5 -1
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -2
- package/node_modules/@diffci.com/core/src/planner/type-program.ts +25 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +5 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +74 -9
- package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +209 -18
- package/node_modules/@diffci.com/core/src/repo/adapters/rust-invocation.ts +44 -6
- package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +264 -24
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +10 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +70 -5
- package/node_modules/@diffci.com/core/src/repo/graph.ts +82 -21
- package/node_modules/@diffci.com/core/src/repo/impact.ts +57 -8
- package/node_modules/@diffci.com/core/src/repo/layout.ts +5 -1
- package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +11 -1
- package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +4 -1
- package/node_modules/@diffci.com/core/src/repo/types.ts +3 -1
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +3 -3
- package/node_modules/@diffci.com/core/src/repo/yarn-berry-lockfile.ts +178 -0
- package/node_modules/@diffci.com/core/src/repo/yarn-lockfile.ts +2 -2
- package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +43 -13
- package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +44 -2
- package/package.json +2 -2
|
@@ -79,7 +79,8 @@ export function parseCargoMetadata(output) {
|
|
|
79
79
|
if (!object(pkg) || typeof pkg.id !== "string" || !pkg.id || typeof pkg.name !== "string"
|
|
80
80
|
|| !/^[A-Za-z0-9_][A-Za-z0-9_-]*$/.test(pkg.name) || typeof pkg.manifest_path !== "string"
|
|
81
81
|
|| !isAbsolute(pkg.manifest_path) || !Array.isArray(pkg.targets) || !pkg.targets.length
|
|
82
|
-
|| (pkg.source !== undefined && pkg.source !== null && typeof pkg.source !== "string")
|
|
82
|
+
|| (pkg.source !== undefined && pkg.source !== null && typeof pkg.source !== "string")
|
|
83
|
+
|| (pkg.version !== undefined && typeof pkg.version !== "string")) {
|
|
83
84
|
throw new Error("Invalid Cargo package metadata");
|
|
84
85
|
}
|
|
85
86
|
for (const target of pkg.targets) {
|
|
@@ -192,7 +193,9 @@ function rustInputs(source) {
|
|
|
192
193
|
return undefined;
|
|
193
194
|
continue;
|
|
194
195
|
}
|
|
195
|
-
|
|
196
|
+
// Byte and C raw strings (`br"\"`, `cr#"say "hi""#`) take no escapes either; read as a `b`/`c`
|
|
197
|
+
// identifier and an ordinary string, a backslash or quote inside would hide the code after them.
|
|
198
|
+
const raw = /^[bc]?r(#{0,255})"/.exec(source.slice(i));
|
|
196
199
|
if (raw) {
|
|
197
200
|
const start = i + raw[0].length, end = source.indexOf(`"${raw[1]}`, start);
|
|
198
201
|
if (end < 0)
|
|
@@ -238,28 +241,70 @@ function rustInputs(source) {
|
|
|
238
241
|
// build time. Report literal paths (the caller checks which crates they reach) and Cargo/rustc
|
|
239
242
|
// invocations; ordinary identifiers such as `fs`, `process`, `unsafe` or `metadata` are not inputs.
|
|
240
243
|
const inputs = [];
|
|
244
|
+
// Inline `mod name { ... }` blocks open around each token, for `#[path]` (null: any other brace).
|
|
245
|
+
const blocks = [];
|
|
241
246
|
const paths = [];
|
|
242
247
|
let compiles = false;
|
|
248
|
+
let runsPrograms = false;
|
|
243
249
|
const includeArguments = new Set();
|
|
244
250
|
for (let i = 0; i < tokens.length; i++) {
|
|
245
251
|
if (tokens[i].value === "mod" && tokens[i + 1]?.value === "target" && tokens[i + 2]?.value === ";")
|
|
246
252
|
return undefined;
|
|
253
|
+
if (tokens[i].value === "{")
|
|
254
|
+
blocks.push(tokens[i - 2]?.value === "mod" && /^[A-Za-z_]/.test(tokens[i - 1]?.value ?? "") ? tokens[i - 1].value : null);
|
|
255
|
+
if (tokens[i].value === "}")
|
|
256
|
+
blocks.pop();
|
|
247
257
|
if (tokens[i].value === "#") {
|
|
248
258
|
let j = i + 1;
|
|
249
259
|
if (tokens[j]?.value === "!")
|
|
250
260
|
j++;
|
|
251
261
|
if (tokens[j]?.value === "[") {
|
|
252
262
|
let depth = 1;
|
|
263
|
+
const paths = [];
|
|
253
264
|
for (j++; j < tokens.length && depth; j++) {
|
|
254
265
|
if (tokens[j].value === "[")
|
|
255
266
|
depth++;
|
|
256
267
|
if (tokens[j].value === "]")
|
|
257
268
|
depth--;
|
|
258
|
-
if (tokens[j].value === "path" && tokens[j + 1]?.value === "=")
|
|
259
|
-
|
|
269
|
+
if (tokens[j].value === "path" && tokens[j + 1]?.value === "=") {
|
|
270
|
+
// `#[path = "x.rs"]` or `#[cfg_attr(pred, path = "x.rs")]` with a plain literal.
|
|
271
|
+
const literal = tokens[j + 2]?.literal;
|
|
272
|
+
if (tokens[i + 1]?.value === "!" || !["[", ","].includes(tokens[j - 1]?.value ?? "") || literal === undefined
|
|
273
|
+
|| !["]", ",", ")"].includes(tokens[j + 3]?.value ?? "") || /[\0\r\n]/.test(literal))
|
|
274
|
+
return undefined;
|
|
275
|
+
paths.push(literal);
|
|
276
|
+
}
|
|
260
277
|
}
|
|
261
278
|
if (depth)
|
|
262
279
|
return undefined;
|
|
280
|
+
if (paths.length) {
|
|
281
|
+
// Only on a file module (`mod name;`), after any other attributes and visibility: on an
|
|
282
|
+
// inline module the path would move every module declared inside it.
|
|
283
|
+
let k = j;
|
|
284
|
+
for (;;) {
|
|
285
|
+
if (tokens[k]?.value === "#" && tokens[k + 1]?.value === "[") {
|
|
286
|
+
let nested = 1;
|
|
287
|
+
for (k += 2; k < tokens.length && nested; k++)
|
|
288
|
+
nested += tokens[k].value === "[" ? 1 : tokens[k].value === "]" ? -1 : 0;
|
|
289
|
+
}
|
|
290
|
+
else if (tokens[k]?.value === "pub" && tokens[k + 1]?.value === "(") {
|
|
291
|
+
k = tokens.findIndex((token, index) => index > k && token.value === ")") + 1;
|
|
292
|
+
if (!k)
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
else if (tokens[k]?.value === "pub")
|
|
296
|
+
k++;
|
|
297
|
+
else
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
if (tokens[k]?.value !== "mod" || !/^[A-Za-z_]/.test(tokens[k + 1]?.value ?? "") || tokens[k + 2]?.value !== ";")
|
|
301
|
+
return undefined;
|
|
302
|
+
const module = blocks.filter((name) => name !== null);
|
|
303
|
+
if (blocks.length !== module.length)
|
|
304
|
+
return undefined;
|
|
305
|
+
for (const path of paths)
|
|
306
|
+
inputs.push({ path, code: true, module });
|
|
307
|
+
}
|
|
263
308
|
}
|
|
264
309
|
}
|
|
265
310
|
if (tokens[i].value === "use") {
|
|
@@ -273,6 +318,15 @@ function rustInputs(source) {
|
|
|
273
318
|
if (tokens[i].value === "Command" && tokens[i + 1]?.value === ":" && tokens[i + 2]?.value === ":" && tokens[i + 3]?.value === "new"
|
|
274
319
|
&& tokens[i + 4]?.value === "(" && /^(?:cargo|rustc|rustdoc)(?:\.exe)?$|^cargo-/.test(tokens[i + 5]?.literal ?? ""))
|
|
275
320
|
compiles = true;
|
|
321
|
+
// Any other program (a script, a shell, a tool) could read files no Rust edge shows. Running the
|
|
322
|
+
// package's own binary (`env!("CARGO_BIN_EXE_name")`) is Rust code Cargo already models. This is a
|
|
323
|
+
// token heuristic: clap's `Command::new("app")` counts too, which only fails closed.
|
|
324
|
+
if (tokens[i].value === "Command" && tokens[i + 1]?.value === ":" && tokens[i + 2]?.value === ":" && tokens[i + 3]?.value === "new"
|
|
325
|
+
&& tokens[i + 4]?.value === "(" && !/^(?:cargo|rustc|rustdoc)(?:\.exe)?$|^cargo-/.test(tokens[i + 5]?.literal ?? "")
|
|
326
|
+
&& !(tokens[i + 5]?.value === "env" && tokens[i + 6]?.value === "!" && tokens[i + 7]?.value === "(" && /^CARGO_BIN_EXE_/.test(tokens[i + 8]?.literal ?? "")))
|
|
327
|
+
runsPrograms = true;
|
|
328
|
+
if (["duct", "xshell", "subprocess"].includes(tokens[i].value) || (tokens[i].value === "cmd" && tokens[i + 1]?.value === "!"))
|
|
329
|
+
runsPrograms = true;
|
|
276
330
|
// `env!("CARGO")`, `env::var("RUSTC")` and similar name the toolchain a test is about to run.
|
|
277
331
|
if (["CARGO", "RUSTC", "RUSTDOC", "RUSTC_WRAPPER"].includes(tokens[i].literal ?? ""))
|
|
278
332
|
compiles = true;
|
|
@@ -302,7 +356,7 @@ function rustInputs(source) {
|
|
|
302
356
|
});
|
|
303
357
|
const navigates = navigatesUpward(tokens);
|
|
304
358
|
// Code that climbs out of its crate can walk to README or docs without naming them.
|
|
305
|
-
return { inputs, paths, compiles, navigates, documentation: documentation || navigates };
|
|
359
|
+
return { inputs, paths, compiles, navigates, documentation: documentation || navigates, runsPrograms };
|
|
306
360
|
}
|
|
307
361
|
/** Code that climbs out of its crate directory in code (`.parent()`, `.ancestors()`, `PathBuf::pop`,
|
|
308
362
|
* or a formatted path with a `..` segment) can reach any crate without a literal naming it. Tests
|
|
@@ -322,6 +376,128 @@ function navigatesUpward(tokens) {
|
|
|
322
376
|
return token.value === "parent" || token.value === "ancestors" || (pathBuf && token.value === "pop");
|
|
323
377
|
});
|
|
324
378
|
}
|
|
379
|
+
/** Doc-comment words that keep a fenced block Rust (rustdoc's doctest attributes). Any other word
|
|
380
|
+
* (`text`, `toml`, `sh`, ...) makes the block another language unless `rust` is also given. */
|
|
381
|
+
const DOCTEST_ATTRIBUTE = /^(?:rust|ignore(?:-\S+)?|should_panic|no_run|compile_fail|edition\d{4}|standalone_crate|test_harness|allow_fail|E\d{4})$/;
|
|
382
|
+
/** Rustdoc compiles and runs the code blocks in doc comments (`///`, `//!`, `/** *\/`, `/*! *\/`)
|
|
383
|
+
* as doctests, from the crate directory. The input scan skips comments, so this returns the code of
|
|
384
|
+
* every block that may be Rust: fenced blocks with no other language and indented blocks, with
|
|
385
|
+
* rustdoc's hidden-line `# ` prefix removed. */
|
|
386
|
+
function doctestCode(source) {
|
|
387
|
+
const code = [];
|
|
388
|
+
for (const group of docComments(source)) {
|
|
389
|
+
const indent = Math.min(...group.filter(line => line.trim()).map(line => /^\s*/.exec(line)[0].length));
|
|
390
|
+
let fence;
|
|
391
|
+
let rust = false;
|
|
392
|
+
let previousBlank = true;
|
|
393
|
+
let indented = false;
|
|
394
|
+
for (const raw of group) {
|
|
395
|
+
const line = raw.slice(Number.isFinite(indent) ? indent : 0);
|
|
396
|
+
const marker = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
|
|
397
|
+
if (fence === undefined && marker) {
|
|
398
|
+
const words = marker[2].split(/[\s,{}.]+/).filter(Boolean);
|
|
399
|
+
fence = marker[1];
|
|
400
|
+
rust = !words.length || words.includes("rust") || words.every(word => DOCTEST_ATTRIBUTE.test(word));
|
|
401
|
+
}
|
|
402
|
+
else if (fence !== undefined && marker && marker[1].startsWith(fence) && !marker[2].trim())
|
|
403
|
+
fence = undefined;
|
|
404
|
+
else if (fence !== undefined) {
|
|
405
|
+
if (rust)
|
|
406
|
+
code.push(line.replace(/^\s*#(?: |$)/, ""));
|
|
407
|
+
}
|
|
408
|
+
// An indented block (four spaces after a blank line) is a doctest too.
|
|
409
|
+
else if (/^ {4}/.test(line) && (previousBlank || indented)) {
|
|
410
|
+
code.push(line.slice(4).replace(/^\s*#(?: |$)/, ""));
|
|
411
|
+
indented = true;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (line.trim())
|
|
415
|
+
indented = false;
|
|
416
|
+
previousBlank = !line.trim();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return code.join("\n");
|
|
420
|
+
}
|
|
421
|
+
/** The text of each doc comment in a file, as lines: a run of `///` or `//!` lines, or one `/** *\/`
|
|
422
|
+
* or `/*! *\/` block (leading `*` removed). Strings, character literals and plain comments are skipped
|
|
423
|
+
* the way the input scan skips them, so a `"/**"` glob or a commented-out `///` is not a doc comment. */
|
|
424
|
+
function docComments(source) {
|
|
425
|
+
const groups = [];
|
|
426
|
+
let lineGroup;
|
|
427
|
+
let lineGroupEnd = -1;
|
|
428
|
+
for (let i = 0; i < source.length;) {
|
|
429
|
+
if (source.startsWith("//", i)) {
|
|
430
|
+
const end = source.indexOf("\n", i) < 0 ? source.length : source.indexOf("\n", i);
|
|
431
|
+
const doc = /^\/\/(?:\/(?!\/)|!)(.*)$/.exec(source.slice(i, end).replace(/\r$/, ""));
|
|
432
|
+
if (doc) {
|
|
433
|
+
if (!lineGroup || !/^[ \t]*\r?\n[ \t]*$/.test(source.slice(lineGroupEnd, i)))
|
|
434
|
+
groups.push(lineGroup = []);
|
|
435
|
+
lineGroup.push(doc[1]);
|
|
436
|
+
lineGroupEnd = end;
|
|
437
|
+
}
|
|
438
|
+
i = end;
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (source.startsWith("/*", i)) {
|
|
442
|
+
const start = i;
|
|
443
|
+
let depth = 1;
|
|
444
|
+
i += 2;
|
|
445
|
+
while (i < source.length && depth) {
|
|
446
|
+
if (source.startsWith("/*", i)) {
|
|
447
|
+
depth++;
|
|
448
|
+
i += 2;
|
|
449
|
+
}
|
|
450
|
+
else if (source.startsWith("*/", i)) {
|
|
451
|
+
depth--;
|
|
452
|
+
i += 2;
|
|
453
|
+
}
|
|
454
|
+
else
|
|
455
|
+
i++;
|
|
456
|
+
}
|
|
457
|
+
if (/^\/\*(?:\*(?![*/])|!)/.test(source.slice(start, start + 4))) {
|
|
458
|
+
const lines = source.slice(start + 3, depth ? i : i - 2).split(/\r?\n/);
|
|
459
|
+
const starred = lines.slice(1).filter(line => line.trim()).every(line => /^\s*\*/.test(line));
|
|
460
|
+
groups.push(starred ? lines.map((line, index) => index ? line.replace(/^\s*\*/, "") : line) : lines);
|
|
461
|
+
}
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
const raw = /^[bc]?r(#{0,255})"/.exec(source.slice(i, i + 260));
|
|
465
|
+
if (raw) {
|
|
466
|
+
const end = source.indexOf(`"${raw[1]}`, i + raw[0].length);
|
|
467
|
+
i = end < 0 ? source.length : end + raw[1].length + 1;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
if (source[i] === '"') {
|
|
471
|
+
for (i++; i < source.length && source[i] !== '"'; i++)
|
|
472
|
+
if (source[i] === "\\")
|
|
473
|
+
i++;
|
|
474
|
+
i++;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
const character = /^'(?:\\.|[^'\\\n])'/.exec(source.slice(i, i + 4));
|
|
478
|
+
if (character) {
|
|
479
|
+
i += character[0].length;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
const identifier = /^[A-Za-z0-9_]+/.exec(source.slice(i, i + 256));
|
|
483
|
+
i += identifier ? identifier[0].length : 1;
|
|
484
|
+
}
|
|
485
|
+
return groups;
|
|
486
|
+
}
|
|
487
|
+
/** The inputs of a Rust file's code and of its doctests. */
|
|
488
|
+
function rustSourceInputs(source) {
|
|
489
|
+
const code = rustInputs(source);
|
|
490
|
+
const docs = code && rustInputs(doctestCode(source));
|
|
491
|
+
if (!code || !docs)
|
|
492
|
+
return undefined;
|
|
493
|
+
const merged = { ...code, inputs: [...code.inputs, ...docs.inputs], paths: [...code.paths, ...docs.paths] };
|
|
494
|
+
// Each flag is set when either scan sets it. Combining them by key keeps that true for a flag
|
|
495
|
+
// rustInputs gains later (such as one #250 adds), instead of silently dropping the doctests' value.
|
|
496
|
+
for (const [key, value] of Object.entries(docs))
|
|
497
|
+
if (typeof value === "boolean")
|
|
498
|
+
merged[key] = merged[key] === true || value;
|
|
499
|
+
return merged;
|
|
500
|
+
}
|
|
325
501
|
/** A string that names a file or directory rather than ordinary text. */
|
|
326
502
|
function pathLike(value) {
|
|
327
503
|
if (!value || value.length > 4096 || /[\0\r\n]/.test(value))
|
|
@@ -351,10 +527,26 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
351
527
|
if (!defaults)
|
|
352
528
|
result.blockers.push("Cargo metadata without default workspace members requires full validation; use Cargo 1.71 or later");
|
|
353
529
|
const tested = new Set(defaults ?? []);
|
|
530
|
+
result.rustAllMembersTested = defaults !== undefined && metadata.workspace_members.every(id => tested.has(id));
|
|
354
531
|
if (new Set(members.map(pkg => pkg.name)).size !== members.length) {
|
|
355
532
|
result.blockers.push("Ambiguous Cargo workspace package names require full validation");
|
|
356
533
|
return result;
|
|
357
534
|
}
|
|
535
|
+
// `cargo test -p NAME` and `cargo tree -p NAME` stop with "specification is ambiguous" when a
|
|
536
|
+
// dependency has a member's name (an older release of the same crate, say). Name such a member
|
|
537
|
+
// NAME@VERSION, which Cargo accepts, or fall back when even that cannot tell them apart.
|
|
538
|
+
const specs = new Map();
|
|
539
|
+
for (const pkg of members) {
|
|
540
|
+
const named = metadata.packages.filter(other => other.name === pkg.name);
|
|
541
|
+
if (named.length === 1)
|
|
542
|
+
specs.set(pkg.id, pkg.name);
|
|
543
|
+
else if (pkg.version && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(pkg.version) && named.filter(other => other.version === pkg.version).length === 1) {
|
|
544
|
+
specs.set(pkg.id, `${pkg.name}@${pkg.version}`);
|
|
545
|
+
}
|
|
546
|
+
else
|
|
547
|
+
result.blockers.push(`Cargo package ${pkg.name} has no unambiguous package specification; full validation required`);
|
|
548
|
+
}
|
|
549
|
+
const spec = (pkg) => specs.get(pkg.id) ?? pkg.name;
|
|
358
550
|
const packages = [];
|
|
359
551
|
for (const pkg of members) {
|
|
360
552
|
const manifest = repositoryPath(root, pkg.manifest_path, known);
|
|
@@ -375,7 +567,17 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
375
567
|
// package outside the workspace appears, no member depends on these crates: they are fixtures or
|
|
376
568
|
// excluded crates. Their files stay unmodelled, so changing one keeps the full suite (impact.ts)
|
|
377
569
|
// without blocking changes elsewhere. Otherwise the repository-wide fallback stays.
|
|
378
|
-
|
|
570
|
+
// Local path packages that are not workspace members. Inside the repository they are unmodelled
|
|
571
|
+
// boundaries like fixture crates: a change to one keeps the full suite, and dependency edges
|
|
572
|
+
// through them are followed below. Outside the repository their changes are invisible to the diff.
|
|
573
|
+
const localNonMembers = metadata.packages.filter(pkg => !metadata.workspace_members.includes(pkg.id) && (pkg.source === undefined || pkg.source === null));
|
|
574
|
+
const localInside = new Map();
|
|
575
|
+
for (const pkg of localNonMembers) {
|
|
576
|
+
const manifest = repositoryPath(root, pkg.manifest_path, known);
|
|
577
|
+
if (manifest && /(?:^|\/)Cargo\.toml$/.test(manifest) && manifest !== "Cargo.toml" && unmodeledManifests.includes(manifest))
|
|
578
|
+
localInside.set(pkg.id, manifest);
|
|
579
|
+
}
|
|
580
|
+
const localDependencyOutside = localNonMembers.some(pkg => !localInside.has(pkg.id));
|
|
379
581
|
const unmodeledBoundary = (file) => !localDependencyOutside
|
|
380
582
|
&& unmodeledManifests.some(manifest => under(file, manifest.slice(0, -"/Cargo.toml".length)));
|
|
381
583
|
if (unmodeledManifests.length && localDependencyOutside)
|
|
@@ -437,14 +639,23 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
437
639
|
continue;
|
|
438
640
|
}
|
|
439
641
|
result.testFiles.push(path);
|
|
440
|
-
result.testPackages[path] = pkg
|
|
441
|
-
|
|
642
|
+
result.testPackages[path] = spec(pkg);
|
|
643
|
+
// Plain `cargo test` builds and runs a target with `required-features` only when Cargo enabled
|
|
644
|
+
// those features for its package, and skips it silently otherwise. The planner keeps such a
|
|
645
|
+
// package whole (`-p name`, never `--test name`), so Cargo makes the same decision for the
|
|
646
|
+
// selected command as for the full run: the feature check below gives the package the full
|
|
647
|
+
// run's features.
|
|
648
|
+
const requiredFeatures = target["required-features"]?.length ? [...target["required-features"]].sort() : undefined;
|
|
649
|
+
result.rustTestTargets[path] = { name: target.name, kind, ...(requiredFeatures ? { requiredFeatures } : {}) };
|
|
442
650
|
}
|
|
443
651
|
}
|
|
444
652
|
const moduleTrees = packages.flatMap(({ pkg }) => pkg.targets.map(target => resolvedPath(root, target.src_path)))
|
|
445
653
|
.filter((path) => path !== undefined).map(path => dirname(path) === "." ? "" : dirname(path));
|
|
446
654
|
if (!completeRustInventory(root, known, moduleTrees))
|
|
447
655
|
result.blockers.push("Incomplete Rust source inventory or symlinked inputs require full validation");
|
|
656
|
+
// Crate roots, for `#[path]` inside inline modules; directories of `#[path]` modules, checked below.
|
|
657
|
+
const targetRoots = new Set(packages.flatMap(({ pkg }) => pkg.targets.map(target => resolvedPath(root, target.src_path))));
|
|
658
|
+
const pathModuleTrees = [];
|
|
448
659
|
result.sourcePaths = [...new Set(result.sourcePaths)].sort();
|
|
449
660
|
result.testFiles.sort();
|
|
450
661
|
if (!result.testFiles.length)
|
|
@@ -463,6 +674,55 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
463
674
|
if (anchor && anchor !== file)
|
|
464
675
|
result.edges.push({ from: anchor, to: file, kind: "import" }, { from: file, to: anchor, kind: "import" });
|
|
465
676
|
}
|
|
677
|
+
// Every in-repository local package that is not a workspace member (a vendored or excluded
|
|
678
|
+
// "bridge" crate) is scanned up front, whether or not a member reaches it. Its build scripts and
|
|
679
|
+
// documentation readers count as readers, as members' do, so a docs change keeps the full suite;
|
|
680
|
+
// code that runs programs turns off crate scoping; and code that could read other crates' files
|
|
681
|
+
// makes the members that reach it depend on every workspace crate (below). What cannot be scanned
|
|
682
|
+
// counts as all three.
|
|
683
|
+
const bridgeOpaque = new Map();
|
|
684
|
+
for (const [id, manifest] of localInside) {
|
|
685
|
+
const directory = manifest.slice(0, -"/Cargo.toml".length);
|
|
686
|
+
const pkg = localNonMembers.find(candidate => candidate.id === id);
|
|
687
|
+
const bridgeRoots = new Set(pkg.targets.map(target => resolvedPath(root, target.src_path)));
|
|
688
|
+
let isOpaque = false;
|
|
689
|
+
for (const target of pkg.targets.filter(target => target.kind.includes("custom-build"))) {
|
|
690
|
+
isOpaque = true;
|
|
691
|
+
(result.rustDocumentationReaders ??= []).push(repositoryPath(root, target.src_path, known) ?? manifest);
|
|
692
|
+
}
|
|
693
|
+
for (const file of context.files.filter(file => file.endsWith(".rs") && under(file, directory))) {
|
|
694
|
+
let scanned;
|
|
695
|
+
try {
|
|
696
|
+
scanned = rustInputs(readFileSync(resolve(root, file), "utf8"));
|
|
697
|
+
}
|
|
698
|
+
catch {
|
|
699
|
+
scanned = undefined;
|
|
700
|
+
}
|
|
701
|
+
if (!scanned) {
|
|
702
|
+
isOpaque = true;
|
|
703
|
+
(result.rustDocumentationReaders ??= []).push(file);
|
|
704
|
+
result.rustRunsPrograms = true;
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
if (scanned.documentation)
|
|
708
|
+
(result.rustDocumentationReaders ??= []).push(file);
|
|
709
|
+
if (scanned.runsPrograms)
|
|
710
|
+
result.rustRunsPrograms = true;
|
|
711
|
+
// `#[path]` is relative to the file's directory, and inside inline modules to their names as
|
|
712
|
+
// well, which is only resolvable from a crate root or mod.rs (as for members, below).
|
|
713
|
+
const modRs = bridgeRoots.has(file) || /(?:^|\/)mod\.rs$/.test(file);
|
|
714
|
+
if (scanned.compiles || scanned.navigates || scanned.documentation || scanned.paths.length > 0
|
|
715
|
+
|| scanned.inputs.some(input => {
|
|
716
|
+
if (input.module?.length && !modRs)
|
|
717
|
+
return true;
|
|
718
|
+
const base = input.module ? posix.join(dirname(file), ...input.module) : dirname(file);
|
|
719
|
+
const path = repositoryPath(root, resolve(root, base, input.path), known);
|
|
720
|
+
return !path || !under(path, directory);
|
|
721
|
+
}))
|
|
722
|
+
isOpaque = true;
|
|
723
|
+
}
|
|
724
|
+
bridgeOpaque.set(id, isOpaque);
|
|
725
|
+
}
|
|
466
726
|
// Cargo resolves all target platforms unless --filter-platform is supplied.
|
|
467
727
|
// --all-features below unions optional dependencies too; cfg(feature) code
|
|
468
728
|
// stays crate-granular and does not itself make the graph unsafe.
|
|
@@ -475,23 +735,51 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
475
735
|
result.blockers.push("Cargo dependency resolution is missing or incomplete; full validation required");
|
|
476
736
|
}
|
|
477
737
|
else {
|
|
738
|
+
// A member can depend on another member through packages outside the workspace (a local path
|
|
739
|
+
// package that itself depends on a member, or a `[patch]`ed crate). Follow dependencies through
|
|
740
|
+
// non-members until they reach members. An in-repository local package whose own code could
|
|
741
|
+
// read other crates' files (a build script, Cargo or program runs, climbing out of its
|
|
742
|
+
// directory, path literals or includes) makes the member depend on every workspace crate.
|
|
743
|
+
const byId = new Map(nodes.map(node => [node.id, node]));
|
|
744
|
+
const opaque = new Map([...localInside.keys()].map(id => [id, bridgeOpaque.get(id) === true]));
|
|
745
|
+
const opaqueLocal = (id) => opaque.get(id) === true;
|
|
478
746
|
for (const node of nodes) {
|
|
479
747
|
const anchor = anchors.get(node.id);
|
|
480
748
|
if (!anchor)
|
|
481
749
|
continue;
|
|
482
|
-
|
|
750
|
+
const reached = new Set();
|
|
751
|
+
let everything = false;
|
|
752
|
+
const seen = new Set([node.id]);
|
|
753
|
+
const pending = [...node.dependencies];
|
|
754
|
+
while (pending.length) {
|
|
755
|
+
const dependency = pending.pop();
|
|
756
|
+
if (seen.has(dependency))
|
|
757
|
+
continue;
|
|
758
|
+
seen.add(dependency);
|
|
483
759
|
const target = anchors.get(dependency);
|
|
484
|
-
if (target
|
|
485
|
-
|
|
760
|
+
if (target) {
|
|
761
|
+
reached.add(target);
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
if (opaqueLocal(dependency))
|
|
765
|
+
everything = true;
|
|
766
|
+
pending.push(...(byId.get(dependency)?.dependencies ?? []));
|
|
486
767
|
}
|
|
768
|
+
if (everything)
|
|
769
|
+
for (const other of packages)
|
|
770
|
+
reached.add(other.manifest);
|
|
771
|
+
reached.delete(anchor);
|
|
772
|
+
for (const target of reached)
|
|
773
|
+
result.edges.push({ from: anchor, to: target, kind: "import" });
|
|
487
774
|
}
|
|
488
775
|
}
|
|
489
776
|
// Registry and Git dependencies are locked and immutable unless Cargo.lock changes, and a
|
|
490
777
|
// Cargo.lock change keeps the full suite. Their build scripts and procedural macros run the same
|
|
491
778
|
// code for the selected and the full invocation; anything they read from this repository outside
|
|
492
779
|
// modelled Rust sources is a changed path that keeps the full suite. A local path dependency that
|
|
493
|
-
// is not a workspace member
|
|
494
|
-
|
|
780
|
+
// is not a workspace member and lives outside the repository can change without the diff showing it,
|
|
781
|
+
// so it still blocks the repository; one inside the repository is an unmodelled boundary (above).
|
|
782
|
+
const localOutside = localNonMembers.filter(pkg => !localInside.has(pkg.id));
|
|
495
783
|
if (localOutside.length) {
|
|
496
784
|
result.blockers.push(`Local Cargo path dependencies outside the workspace require full validation: ${localOutside.map(pkg => pkg.name).sort().join(", ")}`);
|
|
497
785
|
}
|
|
@@ -505,14 +793,11 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
505
793
|
if (other.manifest !== anchor)
|
|
506
794
|
result.edges.push({ from: anchor, to: other.manifest, kind: "import" });
|
|
507
795
|
}
|
|
508
|
-
if (packages.some(({ pkg }) => pkg.targets.some(target => target["required-features"]?.length))) {
|
|
509
|
-
result.blockers.push("Cargo targets requiring features need an explicitly supported test invocation; full validation required");
|
|
510
|
-
}
|
|
511
796
|
for (const source of result.sourcePaths.filter(path => path.endsWith(".rs"))) {
|
|
512
797
|
const sourceOwner = owner(source);
|
|
513
798
|
if (!sourceOwner)
|
|
514
799
|
continue;
|
|
515
|
-
const scanned =
|
|
800
|
+
const scanned = rustSourceInputs(readFileSync(resolve(root, source), "utf8"));
|
|
516
801
|
if (scanned === undefined) {
|
|
517
802
|
result.blockers.push(`Rust computed includes or path attributes require full validation: ${source}`);
|
|
518
803
|
continue;
|
|
@@ -523,6 +808,8 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
523
808
|
// Model these as dependencies of this crate instead of blocking the repository.
|
|
524
809
|
if (scanned.documentation)
|
|
525
810
|
(result.rustDocumentationReaders ??= []).push(source);
|
|
811
|
+
if (scanned.runsPrograms)
|
|
812
|
+
result.rustRunsPrograms = true;
|
|
526
813
|
const reached = new Set();
|
|
527
814
|
if (scanned.compiles || scanned.navigates)
|
|
528
815
|
for (const other of packages)
|
|
@@ -531,11 +818,16 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
531
818
|
const clean = literal.replace(/\\/g, "/").replace(/^(?:[A-Za-z]:)?\/+/, "");
|
|
532
819
|
const glob = clean.search(/[*?[{]/);
|
|
533
820
|
const prefix = glob < 0 ? clean : clean.slice(0, clean.lastIndexOf("/", glob) + 1);
|
|
534
|
-
|
|
821
|
+
// Also from the workspace root: rustc and proc macros run there, and `[env]` paths such as
|
|
822
|
+
// CARGO_WORKSPACE_DIR start there. From the root, only a path below it names a crate.
|
|
823
|
+
const bases = [sourceOwner.directory, dirname(source) === "." ? "" : dirname(source)];
|
|
824
|
+
for (const [index, base] of [...bases, ""].entries()) {
|
|
535
825
|
const joined = posix.normalize(posix.join(base || ".", prefix || "."));
|
|
536
826
|
if (joined === ".." || joined.startsWith("../"))
|
|
537
827
|
continue;
|
|
538
828
|
const rel = joined === "." ? "" : joined.replace(/\/+$/, "");
|
|
829
|
+
if (index === bases.length && !rel)
|
|
830
|
+
continue;
|
|
539
831
|
const inside = rel ? owner(rel) ?? owner(`${rel}/`) : packages.find(pkg => pkg.directory === "");
|
|
540
832
|
if (inside)
|
|
541
833
|
reached.add(inside.manifest);
|
|
@@ -548,7 +840,15 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
548
840
|
for (const manifest of reached)
|
|
549
841
|
result.edges.push({ from: sourceOwner.manifest, to: manifest, kind: "import" });
|
|
550
842
|
for (const input of scanned.inputs) {
|
|
551
|
-
|
|
843
|
+
// A `#[path]` is relative to the file's directory; inside inline modules, also to their
|
|
844
|
+
// names, below the file's stem unless it is a crate root or mod.rs.
|
|
845
|
+
const modRs = targetRoots.has(source) || /(?:^|\/)mod\.rs$/.test(source);
|
|
846
|
+
if (input.module?.length && !modRs) {
|
|
847
|
+
result.blockers.push(`Rust computed includes or path attributes require full validation: ${source}`);
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
const base = input.module ? posix.join(dirname(source), ...input.module) : dirname(source);
|
|
851
|
+
const path = repositoryPath(root, resolve(root, base, input.path), known);
|
|
552
852
|
if (!path || owner(path)?.pkg.id !== sourceOwner.pkg.id) {
|
|
553
853
|
result.blockers.push(`Rust include outside its crate or unavailable requires full validation: ${source}`);
|
|
554
854
|
continue;
|
|
@@ -557,30 +857,41 @@ export function analyzeRustMetadata(context, output, resolveFeatures) {
|
|
|
557
857
|
result.blockers.push(`Rust include code with a non-Rust extension requires full validation: ${source}`);
|
|
558
858
|
continue;
|
|
559
859
|
}
|
|
860
|
+
if (input.module) {
|
|
861
|
+
// Module source of the same crate: already a source of it. What it declares is looked up
|
|
862
|
+
// from its own directory, so that tree must be complete too.
|
|
863
|
+
pathModuleTrees.push(dirname(path) === "." ? "" : dirname(path));
|
|
864
|
+
result.edges.push({ from: source, to: path, kind: "import" });
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
560
867
|
if (!result.sourcePaths.includes(path))
|
|
561
868
|
result.assetPaths.push(path);
|
|
562
869
|
result.edges.push({ from: source, to: path, kind: "asset" });
|
|
563
870
|
}
|
|
564
871
|
}
|
|
872
|
+
if (pathModuleTrees.length && !completeRustInventory(root, known, pathModuleTrees))
|
|
873
|
+
result.blockers.push("Incomplete Rust source inventory or symlinked inputs require full validation");
|
|
565
874
|
result.assetPaths = [...new Set(result.assetPaths)].sort();
|
|
875
|
+
result.rustCrateDirectories = [...new Set(packages.map(({ directory }) => directory))].sort();
|
|
876
|
+
result.rustRunsPrograms ??= false;
|
|
566
877
|
// Selective commands must give every package the features the full invocation gives it. Cargo
|
|
567
878
|
// resolves each tested crate alone and with its dependents (what a change to it selects); the
|
|
568
879
|
// planner checks each selected set against those units.
|
|
569
880
|
if (!cargoFeaturesVary(metadata))
|
|
570
881
|
result.rustFeatureCoverage = { deficits: {}, units: [] };
|
|
571
882
|
else {
|
|
572
|
-
const testedNames = packages.filter(({ pkg }) => tested.has(pkg.id)).map(({ pkg }) => pkg
|
|
883
|
+
const testedNames = packages.filter(({ pkg }) => tested.has(pkg.id)).map(({ pkg }) => spec(pkg));
|
|
573
884
|
const dependents = new Map();
|
|
574
885
|
for (const edge of result.edges) {
|
|
575
886
|
if (edge.from.endsWith("Cargo.toml") && edge.to.endsWith("Cargo.toml") && edge.from !== edge.to) {
|
|
576
887
|
dependents.set(edge.to, [...(dependents.get(edge.to) ?? []), edge.from]);
|
|
577
888
|
}
|
|
578
889
|
}
|
|
579
|
-
const byManifest = new Map(packages.map(({ pkg, manifest }) => [manifest, pkg
|
|
890
|
+
const byManifest = new Map(packages.map(({ pkg, manifest }) => [manifest, spec(pkg)]));
|
|
580
891
|
const units = new Map();
|
|
581
892
|
for (const { pkg, manifest } of packages) {
|
|
582
893
|
if (tested.has(pkg.id))
|
|
583
|
-
units.set(pkg
|
|
894
|
+
units.set(spec(pkg), [spec(pkg)]);
|
|
584
895
|
const seen = new Set([manifest]);
|
|
585
896
|
const pending = [manifest];
|
|
586
897
|
while (pending.length)
|
|
@@ -627,11 +938,14 @@ function cargoFeatureResolver(repoPath) {
|
|
|
627
938
|
/** Configuration keys that change how crates are compiled, which code is compiled or what runs the
|
|
628
939
|
* tests. Aliases, registries, network, terminal, `[env]` and target-dir settings apply equally to
|
|
629
940
|
* the selected and the full invocation, so they do not block. */
|
|
630
|
-
const BUILD_CONFIG = /^\s*(?:build\s*\.\s*)?(?:rustflags|rustdocflags|target|rustc|rustdoc|rustc-wrapper|rustc-workspace-wrapper)\s*=|^\s*\[\s*(?:target|patch|unstable)\b|^\s*(?:target|patch|unstable)\s*\.|^\s*(?:paths|include)\s*=/m;
|
|
941
|
+
const BUILD_CONFIG = /^\s*(?:build\s*\.\s*)?(?:rustflags|rustdocflags|target|rustc|rustdoc|rustc-wrapper|rustc-workspace-wrapper)\s*=|^\s*\[\s*(?:target|patch|unstable)\b|^\s*(?:target|patch|unstable)\s*\.|^\s*(?:paths|include)\s*=|^\s*(?:build|patch|unstable)\s*=/m;
|
|
631
942
|
const COMPILER_ENVIRONMENT = /^(?:RUSTFLAGS|RUSTDOCFLAGS|CARGO_ENCODED_RUST(?:DOC)?FLAGS|CARGO_BUILD_RUST(?:DOC)?FLAGS|CARGO_BUILD_TARGET|RUSTC|RUSTDOC|RUSTC_WRAPPER|RUSTC_WORKSPACE_WRAPPER|CARGO_BUILD_RUSTC(?:_WRAPPER|_WORKSPACE_WRAPPER)?|CARGO_BUILD_RUSTDOC|CARGO_TARGET_.+_(?:RUNNER|RUSTFLAGS))$/;
|
|
943
|
+
/** TOML spells the same key bare, quoted (`"build".rustflags`) or as an inline table
|
|
944
|
+
* (`build = { rustflags = [...] }`); Cargo reads them all. Unquote simple keys before matching, and
|
|
945
|
+
* treat a whole `build`, `patch` or `unstable` inline table as build-changing. */
|
|
632
946
|
function changesBuild(path) {
|
|
633
947
|
try {
|
|
634
|
-
return BUILD_CONFIG.test(readFileSync(path, "utf8"));
|
|
948
|
+
return BUILD_CONFIG.test(readFileSync(path, "utf8").replace(/(["'])([A-Za-z0-9_-]+)\1/g, "$2"));
|
|
635
949
|
}
|
|
636
950
|
catch {
|
|
637
951
|
return existsSync(path);
|