@smoothbricks/nx-plugin 0.4.26 → 0.4.27
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 +994 -117
- package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-bound-failures.js +31 -0
- package/dist/bin/smoo-nx-cargo-hash.js +28 -3
- package/dist/bin/smoo-nx-exec.js +15 -73
- package/dist/bin/smoo-nx-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-failures.js +3 -0
- package/dist/bin/smoo-nx-nextest-extract.js +3 -2
- package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-walks.js +34 -0
- package/dist/bounded-test-policy.d.ts +7 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +101 -40
- package/dist/build-state-output-policy.d.ts +25 -0
- package/dist/build-state-output-policy.d.ts.map +1 -0
- package/dist/build-state-output-policy.js +64 -0
- package/dist/cargo-closure-input.d.ts +3 -2
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +16 -15
- package/dist/cargo-dev-profile.d.ts +37 -0
- package/dist/cargo-dev-profile.d.ts.map +1 -0
- package/dist/cargo-dev-profile.js +108 -0
- package/dist/cargo-source-hash.d.ts +43 -6
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +309 -73
- package/dist/cargo-toolchain-policy.d.ts +4 -0
- package/dist/cargo-toolchain-policy.d.ts.map +1 -1
- package/dist/cargo-toolchain-policy.js +5 -0
- package/dist/cargo-workspace.d.ts +101 -5
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +291 -10
- package/dist/cross-check-policy.d.ts +21 -3
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +24 -6
- package/dist/disk-command-policy.d.ts +7 -0
- package/dist/disk-command-policy.d.ts.map +1 -0
- package/dist/disk-command-policy.js +98 -0
- package/dist/ensure-built-receipt.d.ts +25 -0
- package/dist/ensure-built-receipt.d.ts.map +1 -0
- package/dist/ensure-built-receipt.js +261 -0
- package/dist/ensure-built-witness.d.ts +57 -0
- package/dist/ensure-built-witness.d.ts.map +1 -0
- package/dist/ensure-built-witness.js +412 -0
- package/dist/ensure-built.d.ts +207 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +576 -202
- package/dist/eslint-file-set.d.ts +7 -0
- package/dist/eslint-file-set.d.ts.map +1 -0
- package/dist/eslint-file-set.js +12 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool.js +379 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/disk-lease.js +91 -0
- package/dist/executors/bounded-exec/executor.d.ts +45 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +447 -52
- package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/gateway-lease.js +143 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
- package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
- package/dist/executors/bounded-exec/progress.d.ts +35 -0
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
- package/dist/executors/bounded-exec/progress.js +79 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp.js +1528 -0
- package/dist/executors/bounded-exec/schema.d.ts +29 -11
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.d.ts +162 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
- package/dist/executors/bounded-exec/verdict.js +318 -0
- package/dist/executors/shard-timings/executor.d.ts +14 -0
- package/dist/executors/shard-timings/executor.d.ts.map +1 -0
- package/dist/executors/shard-timings/executor.js +25 -0
- package/dist/executors/shard-timings/schema.d.ts +4 -0
- package/dist/executors/shard-timings/schema.d.ts.map +1 -0
- package/dist/executors/shard-timings/schema.js +1 -0
- package/dist/failure-summary.d.ts +5 -0
- package/dist/failure-summary.d.ts.map +1 -0
- package/dist/failure-summary.js +118 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +6 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +370 -138
- package/dist/managed-files/ci-workflow.d.ts +13 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +44 -13
- package/dist/managed-files/files.d.ts +7 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +62 -8
- package/dist/managed-files/json-edit.d.ts +21 -0
- package/dist/managed-files/json-edit.d.ts.map +1 -0
- package/dist/managed-files/json-edit.js +295 -0
- package/dist/managed-files/managed-format.d.ts +33 -1
- package/dist/managed-files/managed-format.d.ts.map +1 -1
- package/dist/managed-files/managed-format.js +82 -2
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +231 -48
- package/dist/managed-files/tree.d.ts +5 -0
- package/dist/managed-files/tree.d.ts.map +1 -1
- package/dist/managed-files/tree.js +5 -3
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +2 -5
- package/dist/nextest-code-bound.d.ts +62 -0
- package/dist/nextest-code-bound.d.ts.map +1 -0
- package/dist/nextest-code-bound.js +154 -0
- package/dist/nextest-extraction.d.ts +24 -8
- package/dist/nextest-extraction.d.ts.map +1 -1
- package/dist/nextest-extraction.js +42 -7
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +3 -5
- package/dist/release-config-policy.d.ts.map +1 -1
- package/dist/release-config-policy.js +3 -5
- package/dist/runtime-input.d.ts +14 -0
- package/dist/runtime-input.d.ts.map +1 -0
- package/dist/runtime-input.js +15 -0
- package/dist/rust-tokens.d.ts +11 -0
- package/dist/rust-tokens.d.ts.map +1 -0
- package/dist/rust-tokens.js +81 -0
- package/dist/task-results.d.ts +6 -0
- package/dist/task-results.d.ts.map +1 -0
- package/dist/task-results.js +61 -0
- package/dist/test-program.d.ts +54 -0
- package/dist/test-program.d.ts.map +1 -0
- package/dist/test-program.js +292 -0
- package/dist/test-timings.d.ts +71 -0
- package/dist/test-timings.d.ts.map +1 -0
- package/dist/test-timings.js +393 -0
- package/dist/test-walk-policy.d.ts +103 -0
- package/dist/test-walk-policy.d.ts.map +1 -0
- package/dist/test-walk-policy.js +657 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +824 -0
- package/dist/type-guards.d.ts +3 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +4 -0
- package/dist/typecheck-test-policy.d.ts +8 -5
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +113 -100
- package/dist/workspace-config-policy.d.ts +8 -0
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +175 -63
- package/dist/workspace-index.d.ts +12 -0
- package/dist/workspace-index.d.ts.map +1 -0
- package/dist/workspace-index.js +17 -0
- package/dist/workspace-manifest.d.ts +37 -0
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -67
- package/managed/raw/git-format-staged.yml +30 -35
- package/managed/raw/patches/nx@23.2.1.patch +3484 -0
- package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
- package/managed/raw/tooling/direnv/developer-links.ts +569 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
- package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
- package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
- package/managed/raw/tooling/direnv/repo-path +14 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +962 -148
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
- package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
- package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
- package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
- package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
- package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
- package/managed/templates/github/actions/cache-nx/action.yml +1 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
- package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
- package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
- package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
- package/managed/templates/github/workflows/managed-files.yml +1 -2
- package/nextest.toml +8 -41
- package/package.json +74 -12
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo.ts +33 -14
- package/src/__tests__/fixture-nx-env.ts +111 -46
- package/src/__tests__/progress-clock.ts +43 -0
- package/src/__tests__/runtime-input.ts +23 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
- package/src/bin/smoo-nx-bound-failures.ts +33 -0
- package/src/bin/smoo-nx-cargo-hash.ts +28 -3
- package/src/bin/smoo-nx-exec.ts +16 -74
- package/src/bin/smoo-nx-failures.ts +4 -0
- package/src/bin/smoo-nx-nextest-extract.ts +3 -2
- package/src/bin/smoo-nx-test-walks.ts +42 -0
- package/src/bounded-test-policy.test.ts +268 -21
- package/src/bounded-test-policy.ts +114 -42
- package/src/build-state-output-policy.test.ts +115 -0
- package/src/build-state-output-policy.ts +90 -0
- package/src/bun-bootstrap.test.ts +57 -3
- package/src/bun-file-packages.test.ts +47 -0
- package/src/cargo-closure-input.test.ts +138 -66
- package/src/cargo-closure-input.ts +17 -15
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +70 -1
- package/src/cargo-source-hash.test.ts +193 -97
- package/src/cargo-source-hash.ts +345 -68
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +336 -10
- package/src/cross-check-policy.test.ts +59 -1
- package/src/cross-check-policy.ts +25 -6
- package/src/disk-command-policy.test.ts +61 -0
- package/src/disk-command-policy.ts +107 -0
- package/src/ensure-built-receipt.test.ts +184 -0
- package/src/ensure-built-receipt.ts +263 -0
- package/src/ensure-built-witness.test.ts +344 -0
- package/src/ensure-built-witness.ts +252 -0
- package/src/ensure-built.test.ts +1036 -578
- package/src/ensure-built.ts +820 -224
- package/src/eslint-file-set.ts +9 -0
- package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
- package/src/executors/bounded-exec/cpu-pool.ts +417 -0
- package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
- package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
- package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
- package/src/executors/bounded-exec/disk-lease.ts +139 -0
- package/src/executors/bounded-exec/executor-host.test.ts +778 -0
- package/src/executors/bounded-exec/executor.test.ts +1116 -63
- package/src/executors/bounded-exec/executor.ts +565 -67
- package/src/executors/bounded-exec/gateway-lease.ts +176 -0
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
- package/src/executors/bounded-exec/progress.test.ts +79 -0
- package/src/executors/bounded-exec/progress.ts +118 -0
- package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
- package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
- package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
- package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
- package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
- package/src/executors/bounded-exec/ram-temp.ts +1918 -0
- package/src/executors/bounded-exec/schema.json +11 -5
- package/src/executors/bounded-exec/schema.ts +27 -11
- package/src/executors/bounded-exec/verdict.test.ts +440 -0
- package/src/executors/bounded-exec/verdict.ts +433 -0
- package/src/executors/shard-timings/executor.ts +36 -0
- package/src/executors/shard-timings/schema.json +21 -0
- package/src/executors/shard-timings/schema.ts +4 -0
- package/src/failure-summary.ts +119 -0
- package/src/generators/bounded-test-targets/generator.test.ts +4 -4
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/create-package/generator.test.ts +6 -0
- package/src/generators/create-package/generator.ts +6 -2
- package/src/host-controller-wiring.test.ts +31 -0
- package/src/index.test.ts +909 -295
- package/src/index.ts +441 -143
- package/src/linked-snapshots.nx.test.ts +172 -0
- package/src/managed-files/ci-workflow.ts +54 -13
- package/src/managed-files/files.ts +65 -9
- package/src/managed-files/forgejo-artifact.test.ts +395 -0
- package/src/managed-files/generator.test.ts +60 -1
- package/src/managed-files/json-edit.test.ts +216 -0
- package/src/managed-files/json-edit.ts +290 -0
- package/src/managed-files/managed-format-json.test.ts +308 -0
- package/src/managed-files/managed-format.ts +90 -2
- package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
- package/src/managed-files/publish-workflow.ts +285 -67
- package/src/managed-files/repo-path.test.ts +129 -0
- package/src/managed-files/trace-db-artifact.test.ts +7 -0
- package/src/managed-files/tree.ts +11 -3
- package/src/manifest-hash.ts +2 -6
- package/src/nextest-code-bound.test.ts +155 -0
- package/src/nextest-code-bound.ts +195 -0
- package/src/nextest-extraction.test.ts +37 -5
- package/src/nextest-extraction.ts +51 -9
- package/src/nextest-partitions.test.ts +427 -82
- package/src/nx-cache-bound.test.ts +5 -10
- package/src/nx-cache-restore-mtime.test.ts +170 -0
- package/src/nx-daemon-claim.test.ts +277 -0
- package/src/nx-daemon-idle-cpu.test.ts +81 -0
- package/src/nx-daemon-idle-policy.test.ts +51 -0
- package/src/nx-daemon-ignore-files.test.ts +210 -0
- package/src/nx-daemon-root-normalization.test.ts +105 -0
- package/src/nx-daemon-validity.test.ts +925 -0
- package/src/nx-dot-input-policy.test.ts +353 -0
- package/src/nx-failure-life-cycles.test.ts +207 -0
- package/src/nx-files-archive-racy.test.ts +97 -0
- package/src/nx-foreign-workspace-env.test.ts +329 -0
- package/src/nx-incomplete-run-summary.test.ts +70 -0
- package/src/nx-plugin-load-errors.test.ts +120 -0
- package/src/nx-project-resolution-cache.test.ts +176 -0
- package/src/nx-raw-inputs.test.ts +166 -0
- package/src/nx-resident-graph-workers.test.ts +7 -16
- package/src/nx-run-information.test.ts +118 -0
- package/src/nx-skipped-task-exit.test.ts +180 -0
- package/src/nx-state-location.test.ts +63 -0
- package/src/nx-store-resolution.test.ts +26 -25
- package/src/nx-task-graph-cycles.test.ts +148 -0
- package/src/nx-task-output-lease.test.ts +414 -0
- package/src/nx-use-local.test.ts +103 -0
- package/src/package-target-policy.ts +3 -6
- package/src/release-config-policy.ts +3 -6
- package/src/runtime-input.test.ts +215 -0
- package/src/runtime-input.ts +17 -0
- package/src/rust-tokens.ts +78 -0
- package/src/serial-group-wiring.test.ts +326 -0
- package/src/task-history-namespace.test.ts +87 -89
- package/src/task-results.test.ts +226 -0
- package/src/task-results.ts +75 -0
- package/src/test-program.test.ts +303 -0
- package/src/test-program.ts +341 -0
- package/src/test-timings.test.ts +240 -0
- package/src/test-timings.ts +311 -0
- package/src/test-walk-policy.test.ts +585 -0
- package/src/test-walk-policy.ts +731 -0
- package/src/testing.test.ts +509 -0
- package/src/testing.ts +922 -0
- package/src/type-guards.ts +4 -0
- package/src/typecheck-test-policy.test.ts +496 -11
- package/src/typecheck-test-policy.ts +137 -103
- package/src/workspace-config-policy.test.ts +212 -13
- package/src/workspace-config-policy.ts +101 -73
- package/src/workspace-index.ts +18 -0
- package/src/workspace-manifest.ts +41 -0
- package/test-timings.json +85 -30
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
package/src/cargo-source-hash.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type ChildProcess, execFileSync, spawn, spawnSync } from 'node:child_process';
|
|
1
|
+
import { type ChildProcess, type ChildProcessByStdio, execFileSync, spawn, spawnSync } from 'node:child_process';
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { channel } from 'node:diagnostics_channel';
|
|
4
|
-
import { constants, realpathSync, statSync } from 'node:fs';
|
|
4
|
+
import { constants, existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
5
5
|
import {
|
|
6
6
|
access,
|
|
7
7
|
lstat,
|
|
@@ -15,13 +15,16 @@ import {
|
|
|
15
15
|
stat,
|
|
16
16
|
writeFile,
|
|
17
17
|
} from 'node:fs/promises';
|
|
18
|
+
import { createRequire } from 'node:module';
|
|
18
19
|
import { homedir } from 'node:os';
|
|
19
20
|
import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
21
|
+
import type { Readable } from 'node:stream';
|
|
20
22
|
import native from 'nx/src/native/index.js';
|
|
21
23
|
import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory.js';
|
|
22
24
|
import { CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
|
|
25
|
+
import { rustTokens } from './rust-tokens.js';
|
|
23
26
|
|
|
24
|
-
const {
|
|
27
|
+
const { IS_WASM, WorkspaceContext } = native;
|
|
25
28
|
|
|
26
29
|
const cargoResolveEvents = channel('@smoothbricks/nx-plugin:cargo-resolve');
|
|
27
30
|
|
|
@@ -29,6 +32,8 @@ const cargoResolveEvents = channel('@smoothbricks/nx-plugin:cargo-resolve');
|
|
|
29
32
|
interface CargoMetadata {
|
|
30
33
|
packages: {
|
|
31
34
|
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
version: string;
|
|
32
37
|
source: string | null;
|
|
33
38
|
manifest_path: string;
|
|
34
39
|
targets: { src_path: string }[];
|
|
@@ -61,6 +66,8 @@ function parseCargoMetadata(json: string): CargoMetadata {
|
|
|
61
66
|
return {
|
|
62
67
|
packages: list(member(document, 'packages'), 'packages').map((pkg) => ({
|
|
63
68
|
id: text(member(pkg, 'id'), 'package id'),
|
|
69
|
+
name: text(member(pkg, 'name'), 'package name'),
|
|
70
|
+
version: text(member(pkg, 'version'), 'package version'),
|
|
64
71
|
source: member(pkg, 'source') === null ? null : text(member(pkg, 'source'), 'package source'),
|
|
65
72
|
manifest_path: text(member(pkg, 'manifest_path'), 'package manifest_path'),
|
|
66
73
|
targets: list(member(pkg, 'targets'), 'package targets').map((target) => ({
|
|
@@ -91,6 +98,8 @@ function parseCargoMetadata(json: string): CargoMetadata {
|
|
|
91
98
|
/** A mutable (path) package in Cargo's locked resolve. Every path is canonical. */
|
|
92
99
|
export interface LocalCargoPackage {
|
|
93
100
|
readonly id: string;
|
|
101
|
+
readonly name: string;
|
|
102
|
+
readonly version: string;
|
|
94
103
|
readonly directory: string;
|
|
95
104
|
readonly manifest: string;
|
|
96
105
|
/** Every target's source file: library, binaries, tests, build script. A target may live outside `directory`. */
|
|
@@ -124,6 +133,9 @@ export interface CargoPathInputsOptions {
|
|
|
124
133
|
* Cargo groups. Standalone callers need signal forwarding after detaching
|
|
125
134
|
* Cargo from the terminal; handlers are installed only where the caller has
|
|
126
135
|
* not already chosen a signal disposition, and removed after the last child.
|
|
136
|
+
* The hooks are in place before the first child is spawned: a child runs as
|
|
137
|
+
* soon as it is spawned, and a signal that reached this process before its
|
|
138
|
+
* hooks would end it on the default action with Cargo's group left running.
|
|
127
139
|
* Uncatchable SIGKILL cannot execute either hook.
|
|
128
140
|
*/
|
|
129
141
|
const cargoChildren = new Set<ChildProcess>();
|
|
@@ -172,6 +184,11 @@ function ownCargoChildren(): void {
|
|
|
172
184
|
}
|
|
173
185
|
}
|
|
174
186
|
|
|
187
|
+
function disownCargoChildren(): void {
|
|
188
|
+
process.removeListener('exit', killCargoChildren);
|
|
189
|
+
removeCargoSignalHandlers();
|
|
190
|
+
}
|
|
191
|
+
|
|
175
192
|
/**
|
|
176
193
|
* Cargo's stdout, or its failure with Cargo's stderr in the message. Not
|
|
177
194
|
* `promisify` from `node:util`: importing that module makes Node probe color
|
|
@@ -180,15 +197,25 @@ function ownCargoChildren(): void {
|
|
|
180
197
|
* under its own pid, which a runtime input would hash as a new digest on
|
|
181
198
|
* every run.
|
|
182
199
|
*/
|
|
183
|
-
function runCargo(args: readonly string[], cwd: string): Promise<string> {
|
|
200
|
+
function runCargo(args: readonly string[], cwd: string, boundMs: number = CARGO_RESOLVE_BOUND_MS): Promise<string> {
|
|
184
201
|
// spawn forwards detached groups; execFile does not. The public ES2022
|
|
185
202
|
// library API requires the constructor form, not Promise.withResolvers.
|
|
186
203
|
return new Promise((settle, reject) => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
204
|
+
// Hooks first: a signal caught from here on runs its listener after this
|
|
205
|
+
// synchronous body, by which time the child is in `cargoChildren`.
|
|
206
|
+
if (cargoChildren.size === 0) ownCargoChildren();
|
|
207
|
+
let child: ChildProcessByStdio<null, Readable, Readable>;
|
|
208
|
+
try {
|
|
209
|
+
child = spawn('cargo', args, {
|
|
210
|
+
cwd,
|
|
211
|
+
detached: process.platform !== 'win32',
|
|
212
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
213
|
+
});
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (cargoChildren.size === 0) disownCargoChildren();
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
cargoChildren.add(child);
|
|
192
219
|
let stdout = '';
|
|
193
220
|
let stderr = '';
|
|
194
221
|
let stdoutBytes = 0;
|
|
@@ -198,6 +225,16 @@ function runCargo(args: readonly string[], cwd: string): Promise<string> {
|
|
|
198
225
|
failure ??= error;
|
|
199
226
|
killCargoChild(child);
|
|
200
227
|
};
|
|
228
|
+
const timer = setTimeout(
|
|
229
|
+
() =>
|
|
230
|
+
fail(
|
|
231
|
+
new Error(
|
|
232
|
+
`cargo ${args.join(' ')} in ${cwd} did not finish within ${boundMs}ms; killed it, ` +
|
|
233
|
+
'because an unbounded Cargo wait hangs every project-graph construction with no output',
|
|
234
|
+
),
|
|
235
|
+
),
|
|
236
|
+
boundMs,
|
|
237
|
+
);
|
|
201
238
|
child.stdout.setEncoding('utf8');
|
|
202
239
|
child.stderr.setEncoding('utf8');
|
|
203
240
|
child.stdout.on('data', (chunk: string) => {
|
|
@@ -224,18 +261,14 @@ function runCargo(args: readonly string[], cwd: string): Promise<string> {
|
|
|
224
261
|
child.stdout.on('error', fail);
|
|
225
262
|
child.stderr.on('error', fail);
|
|
226
263
|
child.on('close', (code, signal) => {
|
|
264
|
+
clearTimeout(timer);
|
|
227
265
|
cargoChildren.delete(child);
|
|
228
|
-
if (cargoChildren.size === 0)
|
|
229
|
-
process.removeListener('exit', killCargoChildren);
|
|
230
|
-
removeCargoSignalHandlers();
|
|
231
|
-
}
|
|
266
|
+
if (cargoChildren.size === 0) disownCargoChildren();
|
|
232
267
|
if (failure !== undefined) reject(failure);
|
|
233
268
|
else if (code !== 0) {
|
|
234
269
|
reject(new Error(`cargo ${args.join(' ')} failed (${signal ?? code}): ${stderr.trim()}`));
|
|
235
270
|
} else settle(stdout);
|
|
236
271
|
});
|
|
237
|
-
if (cargoChildren.size === 0) ownCargoChildren();
|
|
238
|
-
cargoChildren.add(child);
|
|
239
272
|
});
|
|
240
273
|
}
|
|
241
274
|
|
|
@@ -244,6 +277,7 @@ export const HASH_SKIPPED_DIRECTORIES = [
|
|
|
244
277
|
'target',
|
|
245
278
|
'.git',
|
|
246
279
|
'node_modules',
|
|
280
|
+
'.nx',
|
|
247
281
|
'.cache',
|
|
248
282
|
'.cowshed',
|
|
249
283
|
'.fseventsd',
|
|
@@ -266,8 +300,8 @@ export const CARGO_ANCESTOR_INPUTS = ['Cargo.toml', '.cargo/config', '.cargo/con
|
|
|
266
300
|
* directory actually depend on, so an edit to an unrelated workspace member
|
|
267
301
|
* leaves the digest alone.
|
|
268
302
|
*
|
|
269
|
-
* This covers Rust sources and Cargo configuration,
|
|
270
|
-
* in-workspace Rust inputs. Build scripts' other data/environment inputs remain
|
|
303
|
+
* This covers Rust sources, literal compiled-in files and Cargo configuration,
|
|
304
|
+
* matching the plugin's in-workspace Rust inputs. Build scripts' other data/environment inputs remain
|
|
271
305
|
* explicit Nx inputs, just as they are for in-workspace crates. Files git
|
|
272
306
|
* ignores beneath a package are left out, like Nx's own file inputs: a
|
|
273
307
|
* generated source is its producer's output, which the consuming target hashes
|
|
@@ -282,6 +316,20 @@ export const CARGO_ANCESTOR_INPUTS = ['Cargo.toml', '.cargo/config', '.cargo/con
|
|
|
282
316
|
// rejected error. Git runs under the same rule.
|
|
283
317
|
const CHILD_STDIO: ['ignore', 'pipe', 'pipe'] = ['ignore', 'pipe', 'pipe'];
|
|
284
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Git reads only the repository, never the operator's home (cowshed
|
|
321
|
+
* `04_sandbox.md`, runtime inputs). A host client's runtime input runs in a
|
|
322
|
+
* workspace's sandboxed daemon with the host's HOME: git dies on the global
|
|
323
|
+
* configuration the sandbox denies, and its global ignore file
|
|
324
|
+
* (`~/.config/git/ignore`, read even without a global configuration) would
|
|
325
|
+
* decide which sources the key covers. Neither belongs to the tree.
|
|
326
|
+
*/
|
|
327
|
+
const ISOLATED_GIT_ARGS = ['-c', 'core.excludesFile=/dev/null'] as const;
|
|
328
|
+
|
|
329
|
+
function isolatedGitEnv(): NodeJS.ProcessEnv {
|
|
330
|
+
return { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' };
|
|
331
|
+
}
|
|
332
|
+
|
|
285
333
|
/** A Cargo resolution refusal: no stale closure or runtime whole-workspace substitute is safe. */
|
|
286
334
|
export class CargoMetadataError extends Error {
|
|
287
335
|
readonly manifestPath: string;
|
|
@@ -309,7 +357,16 @@ interface ResolveState {
|
|
|
309
357
|
pending?: { readonly key: string; readonly promise: Promise<CargoResolve> };
|
|
310
358
|
}
|
|
311
359
|
const resolves = new Map<string, ResolveState>();
|
|
312
|
-
|
|
360
|
+
// v2 retains package name/version for checkout-independent artifact input identities.
|
|
361
|
+
const RESOLVE_CACHE_SCHEMA = 'cargo-resolve-v2';
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* The longest one Cargo child, or one wait for a foreign resolve flight's lock, may take.
|
|
365
|
+
* Both waits sit on every project-graph construction, so an unbounded one is a silent,
|
|
366
|
+
* output-free hang of every gate that resolves the graph (a stopped lock holder, a Cargo
|
|
367
|
+
* process convoy): at the bound the wait fails, naming what it waited on and for how long.
|
|
368
|
+
*/
|
|
369
|
+
export const CARGO_RESOLVE_BOUND_MS = 300_000;
|
|
313
370
|
|
|
314
371
|
/**
|
|
315
372
|
* The full manifest SET, not merely the last closure: adding a glob workspace
|
|
@@ -407,6 +464,8 @@ function cargoFromMetadata(metadata: CargoMetadata): CargoResolve {
|
|
|
407
464
|
if (pkg.governing_manifest_path === undefined) throw new Error('Cargo cache omitted a governing manifest');
|
|
408
465
|
return {
|
|
409
466
|
id: pkg.id,
|
|
467
|
+
name: pkg.name,
|
|
468
|
+
version: pkg.version,
|
|
410
469
|
directory: dirname(pkg.manifest_path),
|
|
411
470
|
manifest: pkg.manifest_path,
|
|
412
471
|
sources: pkg.targets.map((target) => target.src_path),
|
|
@@ -444,15 +503,15 @@ async function loadResolveCache(file: string): Promise<ResolveCache | null> {
|
|
|
444
503
|
|
|
445
504
|
/**
|
|
446
505
|
* One content-keyed resolution per Cargo workspace, across concurrent graph
|
|
447
|
-
* calls and workers. Nx's kernel FileLock
|
|
448
|
-
* in-process callers join before
|
|
449
|
-
*
|
|
450
|
-
* the old child instead of receiving its stale answer.
|
|
506
|
+
* calls and workers. A bounded child owns Nx's kernel FileLock while the
|
|
507
|
+
* resolution runs; in-process callers join before asking for that lease.
|
|
508
|
+
* A changed key queues behind the old child instead of receiving its stale answer.
|
|
451
509
|
*/
|
|
452
510
|
export async function readCargoResolve(
|
|
453
511
|
manifestPath: string,
|
|
454
512
|
cwd: string,
|
|
455
513
|
indexed?: ReadonlySet<string>,
|
|
514
|
+
boundMs: number = CARGO_RESOLVE_BOUND_MS,
|
|
456
515
|
): Promise<CargoResolve> {
|
|
457
516
|
let manifest = resolve(manifestPath);
|
|
458
517
|
try {
|
|
@@ -498,7 +557,7 @@ export async function readCargoResolve(
|
|
|
498
557
|
if (state.cached?.key === key) return state.cached.cargo;
|
|
499
558
|
if (joined === 3) break;
|
|
500
559
|
const active = state;
|
|
501
|
-
const promise = resolveAndCache(root, manifest, index, directory, file, active);
|
|
560
|
+
const promise = resolveAndCache(root, manifest, index, directory, file, active, boundMs);
|
|
502
561
|
active.pending = { key, promise };
|
|
503
562
|
try {
|
|
504
563
|
return await promise;
|
|
@@ -520,16 +579,20 @@ async function resolveAndCache(
|
|
|
520
579
|
directory: string,
|
|
521
580
|
file: string,
|
|
522
581
|
state: ResolveState,
|
|
582
|
+
boundMs: number = CARGO_RESOLVE_BOUND_MS,
|
|
523
583
|
): Promise<CargoResolve> {
|
|
524
584
|
if (IS_WASM)
|
|
525
585
|
throw new Error('Cargo resolution requires the native Nx file lock; a WASM Nx host cannot own Cargo children');
|
|
526
586
|
await mkdir(directory, { recursive: true });
|
|
587
|
+
// A warm cache answers with no lock: reading it and keying it spawns nothing and
|
|
588
|
+
// waits for nobody, so an unchanged workspace never queues behind a foreign flight.
|
|
589
|
+
state.cached = await loadResolveCache(file);
|
|
590
|
+
{
|
|
591
|
+
const key = await resolutionKey(root, manifest, state.cached?.cargo ?? null, indexed);
|
|
592
|
+
if (state.cached?.key === key) return state.cached.cargo;
|
|
593
|
+
}
|
|
527
594
|
const lockFile = join(directory, 'resolve.lock');
|
|
528
|
-
const lock =
|
|
529
|
-
while (lock.check()) await lock.wait();
|
|
530
|
-
// Nx's lock() is synchronous: losing this inter-process check/acquire race
|
|
531
|
-
// can block for one foreign flight. Only the in-process leader reaches it.
|
|
532
|
-
lock.lock();
|
|
595
|
+
const lock = await acquireCargoResolveLock(lockFile, boundMs);
|
|
533
596
|
try {
|
|
534
597
|
// Another worker may have populated it while this worker waited.
|
|
535
598
|
state.cached = await loadResolveCache(file);
|
|
@@ -542,7 +605,7 @@ async function resolveAndCache(
|
|
|
542
605
|
// discovered external input edited during this flight requires replay.
|
|
543
606
|
await writeFile(lockFile, '');
|
|
544
607
|
const started = (await stat(lockFile)).mtimeMs;
|
|
545
|
-
const metadata = await resolveCargoMetadata(manifest, root);
|
|
608
|
+
const metadata = await resolveCargoMetadata(manifest, root, boundMs);
|
|
546
609
|
const cargo = cargoFromMetadata(metadata);
|
|
547
610
|
// Capture the published key before validation. Reading it afterwards
|
|
548
611
|
// could pair a post-edit key with Cargo's pre-edit answer.
|
|
@@ -572,14 +635,128 @@ async function resolveAndCache(
|
|
|
572
635
|
}
|
|
573
636
|
throw new Error('Cargo resolution inputs kept changing during three consecutive locked offline queries');
|
|
574
637
|
} finally {
|
|
575
|
-
lock.
|
|
638
|
+
await lock.release();
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/** A failed acquisition names the lock, elapsed wait, and the reaped waiter. */
|
|
643
|
+
export class CargoResolveLockError extends Error {
|
|
644
|
+
constructor(
|
|
645
|
+
readonly lockFile: string,
|
|
646
|
+
readonly boundMs: number,
|
|
647
|
+
readonly waitedMs: number,
|
|
648
|
+
readonly waiterPid: number | undefined,
|
|
649
|
+
) {
|
|
650
|
+
super(
|
|
651
|
+
`waited ${waitedMs}ms for the Cargo resolve lock ${lockFile} (bound ${boundMs}ms; holder pid unknown); ` +
|
|
652
|
+
`killed and reaped lock waiter pid ${waiterPid ?? 'unavailable'} because an unbounded wait hangs project-graph construction`,
|
|
653
|
+
);
|
|
654
|
+
this.name = 'CargoResolveLockError';
|
|
576
655
|
}
|
|
577
656
|
}
|
|
578
657
|
|
|
579
|
-
|
|
658
|
+
/**
|
|
659
|
+
* The pinned Nx binding has only blocking acquisition. Isolate that syscall in
|
|
660
|
+
* one child per cold flight so the caller's deadline can kill and reap it.
|
|
661
|
+
* Closing stdin releases a successful lease; warm cache reads spawn no child.
|
|
662
|
+
*/
|
|
663
|
+
export function acquireCargoResolveLock(
|
|
664
|
+
lockFile: string,
|
|
665
|
+
boundMs: number,
|
|
666
|
+
): Promise<{ readonly pid: number; release(): Promise<void> }> {
|
|
667
|
+
const nativeModule = createRequire(import.meta.url).resolve('nx/src/native/index.js');
|
|
668
|
+
const program = [
|
|
669
|
+
`const { FileLock } = require(${JSON.stringify(nativeModule)});`,
|
|
670
|
+
`const lock = new FileLock(${JSON.stringify(lockFile)});`,
|
|
671
|
+
'lock.lock();',
|
|
672
|
+
"process.stdout.write('locked\\n');",
|
|
673
|
+
'process.stdin.resume();',
|
|
674
|
+
"process.stdin.on('end', () => { lock.unlock(); process.exit(0); });",
|
|
675
|
+
].join('\n');
|
|
676
|
+
// The public ES2022 library API requires the constructor form, not Promise.withResolvers.
|
|
677
|
+
return new Promise((settle, reject) => {
|
|
678
|
+
const started = performance.now();
|
|
679
|
+
const child = spawn(process.execPath, ['--eval', program], {
|
|
680
|
+
detached: process.platform !== 'win32',
|
|
681
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
682
|
+
});
|
|
683
|
+
let acquired = false;
|
|
684
|
+
let releasing = false;
|
|
685
|
+
let failure: Error | undefined;
|
|
686
|
+
let stdout = '';
|
|
687
|
+
let stderr = '';
|
|
688
|
+
const fail = (error: Error): void => {
|
|
689
|
+
failure ??= error;
|
|
690
|
+
killCargoChild(child);
|
|
691
|
+
};
|
|
692
|
+
const timer = setTimeout(
|
|
693
|
+
() => fail(new CargoResolveLockError(lockFile, boundMs, Math.ceil(performance.now() - started), child.pid)),
|
|
694
|
+
boundMs,
|
|
695
|
+
);
|
|
696
|
+
const closed = new Promise<void>((finish) => {
|
|
697
|
+
child.on('close', (code, signal) => {
|
|
698
|
+
clearTimeout(timer);
|
|
699
|
+
cargoChildren.delete(child);
|
|
700
|
+
if (cargoChildren.size === 0) {
|
|
701
|
+
process.removeListener('exit', killCargoChildren);
|
|
702
|
+
removeCargoSignalHandlers();
|
|
703
|
+
}
|
|
704
|
+
if (failure === undefined && (!releasing || code !== 0)) {
|
|
705
|
+
failure = new Error(
|
|
706
|
+
`Cargo resolve lock ${lockFile} waiter pid ${child.pid} exited (${signal ?? code}): ${stderr.trim()}`,
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
if (!acquired) reject(failure);
|
|
710
|
+
finish();
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
child.stdout.setEncoding('utf8');
|
|
714
|
+
child.stderr.setEncoding('utf8');
|
|
715
|
+
child.stdout.on('data', (chunk: string) => {
|
|
716
|
+
stdout += chunk;
|
|
717
|
+
if (failure !== undefined || acquired || stdout !== 'locked\n') return;
|
|
718
|
+
const waitedMs = Math.ceil(performance.now() - started);
|
|
719
|
+
if (waitedMs >= boundMs) {
|
|
720
|
+
fail(new CargoResolveLockError(lockFile, boundMs, waitedMs, child.pid));
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (child.pid === undefined) {
|
|
724
|
+
fail(new Error(`Cargo resolve lock ${lockFile} acquired without a child pid`));
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
acquired = true;
|
|
728
|
+
clearTimeout(timer);
|
|
729
|
+
settle({
|
|
730
|
+
pid: child.pid,
|
|
731
|
+
release: async () => {
|
|
732
|
+
releasing = true;
|
|
733
|
+
child.stdin.end();
|
|
734
|
+
await closed;
|
|
735
|
+
if (failure !== undefined) throw failure;
|
|
736
|
+
},
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
child.stderr.on('data', (chunk: string) => {
|
|
740
|
+
stderr += chunk;
|
|
741
|
+
});
|
|
742
|
+
child.on('error', fail);
|
|
743
|
+
child.stdin.on('error', fail);
|
|
744
|
+
child.stdout.on('error', fail);
|
|
745
|
+
child.stderr.on('error', fail);
|
|
746
|
+
if (cargoChildren.size === 0) ownCargoChildren();
|
|
747
|
+
cargoChildren.add(child);
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
async function resolveCargoMetadata(
|
|
752
|
+
manifestPath: string,
|
|
753
|
+
cwd: string,
|
|
754
|
+
boundMs: number = CARGO_RESOLVE_BOUND_MS,
|
|
755
|
+
): Promise<CargoMetadata> {
|
|
580
756
|
const stdout = await runCargo(
|
|
581
757
|
['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', manifestPath],
|
|
582
758
|
cwd,
|
|
759
|
+
boundMs,
|
|
583
760
|
);
|
|
584
761
|
const metadata = parseCargoMetadata(stdout);
|
|
585
762
|
metadata.workspace_root = await realpath(metadata.workspace_root);
|
|
@@ -597,6 +774,7 @@ async function resolveCargoMetadata(manifestPath: string, cwd: string): Promise<
|
|
|
597
774
|
await runCargo(
|
|
598
775
|
['locate-project', '--workspace', '--manifest-path', pkg.manifest_path, '--message-format', 'plain'],
|
|
599
776
|
cwd,
|
|
777
|
+
boundMs,
|
|
600
778
|
)
|
|
601
779
|
).trim(),
|
|
602
780
|
);
|
|
@@ -612,13 +790,32 @@ export async function hashCargoPathInputs(
|
|
|
612
790
|
const root = await realpath(workspaceRoot);
|
|
613
791
|
const cargo = await readCargoResolve(manifestPath, root);
|
|
614
792
|
const members = options?.closure === undefined ? undefined : await dependencyClosure(cargo, resolve(options.closure));
|
|
615
|
-
|
|
616
|
-
const
|
|
617
|
-
|
|
793
|
+
type InputRole = 'manifest' | 'workspace' | 'ancestor' | 'target' | 'file' | 'link' | 'include';
|
|
794
|
+
const inputKey = (pkg: LocalCargoPackage, role: InputRole, path: string) =>
|
|
795
|
+
JSON.stringify([pkg.name, pkg.version, role, path.split(sep).join('/')]);
|
|
796
|
+
const directories = new Map<string, LocalCargoPackage>();
|
|
797
|
+
const files = new Map<string, string>();
|
|
618
798
|
const ancestors = new Set<string>();
|
|
619
|
-
const links = new Map<string, string>();
|
|
620
|
-
const packageSources: string[] = [];
|
|
621
|
-
|
|
799
|
+
const links = new Map<string, { key: string; target: string }>();
|
|
800
|
+
const packageSources: { file: string; key: string }[] = [];
|
|
801
|
+
// Read shared bytes once. The smallest declared identity makes multiple owners
|
|
802
|
+
// deterministic without using a consuming checkout's mount path as an input.
|
|
803
|
+
const includeFile = (file: string, key: string) => {
|
|
804
|
+
const prior = files.get(file);
|
|
805
|
+
if (prior === undefined || key < prior) files.set(file, key);
|
|
806
|
+
};
|
|
807
|
+
const packages = [...cargo.local].sort((left, right) =>
|
|
808
|
+
left.name < right.name
|
|
809
|
+
? -1
|
|
810
|
+
: left.name > right.name
|
|
811
|
+
? 1
|
|
812
|
+
: left.version < right.version
|
|
813
|
+
? -1
|
|
814
|
+
: left.version > right.version
|
|
815
|
+
? 1
|
|
816
|
+
: 0,
|
|
817
|
+
);
|
|
818
|
+
for (const pkg of packages) {
|
|
622
819
|
if (members !== undefined && !members.has(pkg.id)) continue;
|
|
623
820
|
const directory = pkg.directory;
|
|
624
821
|
if (!options?.includeWorkspace) {
|
|
@@ -626,37 +823,39 @@ export async function hashCargoPathInputs(
|
|
|
626
823
|
const fromCargo = relative(cargo.root, directory);
|
|
627
824
|
if (
|
|
628
825
|
fromRoot !== '..' &&
|
|
629
|
-
!fromRoot.startsWith(
|
|
826
|
+
!fromRoot.startsWith('..' + sep) &&
|
|
630
827
|
!isAbsolute(fromRoot) &&
|
|
631
828
|
fromCargo !== '..' &&
|
|
632
|
-
!fromCargo.startsWith(
|
|
829
|
+
!fromCargo.startsWith('..' + sep) &&
|
|
633
830
|
!isAbsolute(fromCargo) &&
|
|
634
831
|
!fromRoot.split(sep).includes('node_modules')
|
|
635
832
|
)
|
|
636
833
|
continue;
|
|
637
834
|
}
|
|
638
|
-
directories.
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
835
|
+
directories.set(directory, pkg);
|
|
836
|
+
includeFile(pkg.manifest, inputKey(pkg, 'manifest', 'Cargo.toml'));
|
|
837
|
+
includeFile(pkg.governingManifest, inputKey(pkg, 'workspace', 'Cargo.toml'));
|
|
838
|
+
for (const [index, file] of pkg.sources.entries())
|
|
839
|
+
packageSources.push({ file, key: inputKey(pkg, 'target', String(index)) });
|
|
840
|
+
for (
|
|
841
|
+
let ancestor = dirname(directory), depth = 1;
|
|
842
|
+
!ancestors.has(ancestor);
|
|
843
|
+
ancestor = dirname(ancestor), depth += 1
|
|
844
|
+
) {
|
|
646
845
|
ancestors.add(ancestor);
|
|
647
846
|
for (const name of CARGO_ANCESTOR_INPUTS) {
|
|
648
847
|
const file = join(ancestor, name);
|
|
649
|
-
if (statSync(file, { throwIfNoEntry: false })?.isFile())
|
|
848
|
+
if (statSync(file, { throwIfNoEntry: false })?.isFile()) {
|
|
849
|
+
includeFile(await realpath(file), inputKey(pkg, 'ancestor', depth + '/' + name));
|
|
850
|
+
}
|
|
650
851
|
}
|
|
651
852
|
}
|
|
652
853
|
}
|
|
653
|
-
|
|
654
|
-
const
|
|
655
|
-
for (const source of packageSources) if (!ignored(source)) files.add(source);
|
|
854
|
+
const ignored = gitIgnoredBeneath([...directories.keys()]);
|
|
855
|
+
for (const { file, key } of packageSources) if (!ignored(file)) includeFile(file, key);
|
|
656
856
|
const skipped: ReadonlySet<string> = new Set(HASH_SKIPPED_DIRECTORIES);
|
|
657
|
-
// Overlapping packages (a facade root plus its child crates) share one walk.
|
|
658
857
|
const visited = new Set<string>();
|
|
659
|
-
async function walk(directory: string): Promise<void> {
|
|
858
|
+
async function walk(directory: string, owner: LocalCargoPackage, within: string): Promise<void> {
|
|
660
859
|
const canonical = await realpath(directory);
|
|
661
860
|
if (visited.has(canonical)) return;
|
|
662
861
|
visited.add(canonical);
|
|
@@ -664,34 +863,48 @@ export async function hashCargoPathInputs(
|
|
|
664
863
|
if (skipped.has(entry.name)) continue;
|
|
665
864
|
const path = join(canonical, entry.name);
|
|
666
865
|
if (ignored(path)) continue;
|
|
667
|
-
|
|
866
|
+
const localPath = within === '' ? entry.name : within + '/' + entry.name;
|
|
867
|
+
if (entry.isSymbolicLink())
|
|
868
|
+
links.set(path, { key: inputKey(owner, 'link', localPath), target: await readlink(path) });
|
|
668
869
|
const info = entry.isSymbolicLink() ? await lstat(await realpath(path)) : entry;
|
|
669
870
|
if (info.isDirectory()) {
|
|
670
|
-
await walk(path);
|
|
871
|
+
await walk(path, owner, localPath);
|
|
671
872
|
} else if (
|
|
672
873
|
info.isFile() &&
|
|
673
874
|
(entry.name.endsWith('.rs') ||
|
|
674
875
|
entry.name === 'Cargo.toml' ||
|
|
675
|
-
(
|
|
876
|
+
((within === '.cargo' || within.endsWith('/.cargo')) &&
|
|
877
|
+
(entry.name === 'config' || entry.name === 'config.toml')))
|
|
676
878
|
) {
|
|
677
|
-
|
|
879
|
+
includeFile(await realpath(path), inputKey(owner, 'file', localPath));
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
for (const [directory, owner] of directories) await walk(directory, owner, '');
|
|
884
|
+
const compiledCache = new Map<string, CompiledCargoInput[]>();
|
|
885
|
+
for (const [directory, owner] of directories) {
|
|
886
|
+
for (const input of compiledInFiles(directory, compiledCache)) {
|
|
887
|
+
if (!ignored(input.file)) {
|
|
888
|
+
includeFile(
|
|
889
|
+
await realpath(input.file),
|
|
890
|
+
inputKey(owner, 'include', relative(directory, input.source) + '\0' + input.literal),
|
|
891
|
+
);
|
|
678
892
|
}
|
|
679
893
|
}
|
|
680
894
|
}
|
|
681
|
-
for (const directory of directories) await walk(directory);
|
|
682
895
|
const hash = createHash('sha256');
|
|
683
|
-
hash.update('cargo-path-inputs-
|
|
684
|
-
for (const
|
|
685
|
-
|
|
896
|
+
hash.update('cargo-path-inputs-v2\0');
|
|
897
|
+
for (const { key, target } of [...links.values()].sort((left, right) =>
|
|
898
|
+
left.key < right.key ? -1 : left.key > right.key ? 1 : 0,
|
|
899
|
+
)) {
|
|
900
|
+
hash.update(key);
|
|
686
901
|
hash.update('\0symlink\0');
|
|
687
902
|
hash.update(target);
|
|
688
903
|
hash.update('\0');
|
|
689
904
|
}
|
|
690
|
-
for (const file of [...files].sort()) {
|
|
905
|
+
for (const [file, key] of [...files].sort((left, right) => (left[1] < right[1] ? -1 : left[1] > right[1] ? 1 : 0))) {
|
|
691
906
|
const bytes = await readFile(file);
|
|
692
|
-
|
|
693
|
-
// when its contents are unchanged. Length framing makes boundaries unique.
|
|
694
|
-
hash.update(relative(root, file));
|
|
907
|
+
hash.update(key);
|
|
695
908
|
hash.update('\0');
|
|
696
909
|
hash.update(String(bytes.length));
|
|
697
910
|
hash.update('\0');
|
|
@@ -749,6 +962,7 @@ function gitIgnoredBeneath(directories: readonly string[]): (path: string) => bo
|
|
|
749
962
|
const listing = execFileSync(
|
|
750
963
|
'git',
|
|
751
964
|
[
|
|
965
|
+
...ISOLATED_GIT_ARGS,
|
|
752
966
|
'--literal-pathspecs',
|
|
753
967
|
'-C',
|
|
754
968
|
repository,
|
|
@@ -761,7 +975,7 @@ function gitIgnoredBeneath(directories: readonly string[]): (path: string) => bo
|
|
|
761
975
|
'--',
|
|
762
976
|
...sourceRoots,
|
|
763
977
|
],
|
|
764
|
-
{ encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: CHILD_STDIO },
|
|
978
|
+
{ encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: CHILD_STDIO, env: isolatedGitEnv() },
|
|
765
979
|
);
|
|
766
980
|
for (const entry of listing.split('\0')) {
|
|
767
981
|
if (entry.length === 0) continue;
|
|
@@ -779,10 +993,11 @@ function gitIgnoredBeneath(directories: readonly string[]): (path: string) => bo
|
|
|
779
993
|
|
|
780
994
|
/** The members of `paths` (relative to `repository`) that git ignores, own patterns or an ancestor's. */
|
|
781
995
|
function gitCheckIgnore(repository: string, paths: readonly string[]): string[] {
|
|
782
|
-
const result = spawnSync('git', ['-C', repository, 'check-ignore', '-z', '--stdin'], {
|
|
996
|
+
const result = spawnSync('git', [...ISOLATED_GIT_ARGS, '-C', repository, 'check-ignore', '-z', '--stdin'], {
|
|
783
997
|
input: `${paths.join('\0')}\0`,
|
|
784
998
|
encoding: 'utf8',
|
|
785
999
|
maxBuffer: 64 * 1024 * 1024,
|
|
1000
|
+
env: isolatedGitEnv(),
|
|
786
1001
|
});
|
|
787
1002
|
// check-ignore answers 1 when nothing is ignored; only 0 carries a listing.
|
|
788
1003
|
if (result.status === 1) return [];
|
|
@@ -797,9 +1012,10 @@ function gitRepository(directory: string): string | undefined {
|
|
|
797
1012
|
try {
|
|
798
1013
|
// The walk compares realpaths, so git's answer is canonicalized the same way.
|
|
799
1014
|
return realpathSync(
|
|
800
|
-
execFileSync('git', ['-C', directory, 'rev-parse', '--show-toplevel'], {
|
|
1015
|
+
execFileSync('git', [...ISOLATED_GIT_ARGS, '-C', directory, 'rev-parse', '--show-toplevel'], {
|
|
801
1016
|
encoding: 'utf8',
|
|
802
1017
|
stdio: CHILD_STDIO,
|
|
1018
|
+
env: isolatedGitEnv(),
|
|
803
1019
|
}).trim(),
|
|
804
1020
|
);
|
|
805
1021
|
} catch (error) {
|
|
@@ -815,3 +1031,64 @@ function gitRepository(directory: string): string | undefined {
|
|
|
815
1031
|
throw error;
|
|
816
1032
|
}
|
|
817
1033
|
}
|
|
1034
|
+
|
|
1035
|
+
/** A compiled-in value, with the source spelling that identifies it across checkouts. */
|
|
1036
|
+
export interface CompiledCargoInput {
|
|
1037
|
+
readonly file: string;
|
|
1038
|
+
readonly source: string;
|
|
1039
|
+
readonly literal: string;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// A tokenized literal macro, never text inside a comment or another string.
|
|
1043
|
+
const INCLUDE_CLOSERS: Readonly<Record<string, string>> = { '(': ')', '[': ']', '{': '}' };
|
|
1044
|
+
const INCLUDE_STRING = /^"([^"\\\r\n]*)"$/u;
|
|
1045
|
+
const INCLUDE_RAW_STRING = /^r(#*)"([\s\S]*)"\1$/u;
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Existing literal include_str!/include_bytes! files read by this package's Rust sources.
|
|
1049
|
+
* One graph owns the memo; runtime hashes use a fresh memo. Nested packages own their
|
|
1050
|
+
* sources separately. Computed paths and arbitrary build-script reads remain explicit inputs.
|
|
1051
|
+
*/
|
|
1052
|
+
export function compiledInFiles(root: string, cache: Map<string, CompiledCargoInput[]>): CompiledCargoInput[] {
|
|
1053
|
+
const cached = cache.get(root);
|
|
1054
|
+
if (cached !== undefined) return cached;
|
|
1055
|
+
const found = new Map<string, CompiledCargoInput>();
|
|
1056
|
+
const skipped: readonly string[] = HASH_SKIPPED_DIRECTORIES;
|
|
1057
|
+
const scan = [root];
|
|
1058
|
+
while (scan.length > 0) {
|
|
1059
|
+
const current = scan.pop();
|
|
1060
|
+
if (current === undefined || !existsSync(current)) continue;
|
|
1061
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
1062
|
+
const child = join(current, entry.name);
|
|
1063
|
+
if (entry.isDirectory()) {
|
|
1064
|
+
if (!skipped.includes(entry.name) && !existsSync(join(child, 'Cargo.toml'))) scan.push(child);
|
|
1065
|
+
} else if (entry.isFile() && entry.name.endsWith('.rs')) {
|
|
1066
|
+
const text = readFileSync(child, 'utf8');
|
|
1067
|
+
if (!text.includes('include_')) continue;
|
|
1068
|
+
const tokens = rustTokens(text);
|
|
1069
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
1070
|
+
if (tokens[index]?.text !== 'include_str' && tokens[index]?.text !== 'include_bytes') continue;
|
|
1071
|
+
if (tokens[index + 1]?.text !== '!') continue;
|
|
1072
|
+
const closing = INCLUDE_CLOSERS[tokens[index + 2]?.text ?? ''];
|
|
1073
|
+
const end = tokens[index + 4]?.text === ',' ? index + 5 : index + 4;
|
|
1074
|
+
if (closing === undefined || tokens[end]?.text !== closing) continue;
|
|
1075
|
+
const literal = tokens[index + 3]?.text ?? '';
|
|
1076
|
+
const path = INCLUDE_STRING.exec(literal)?.[1] ?? INCLUDE_RAW_STRING.exec(literal)?.[2];
|
|
1077
|
+
if (path === undefined || path === '') continue;
|
|
1078
|
+
const file = resolve(current, path);
|
|
1079
|
+
if (statSync(file, { throwIfNoEntry: false })?.isFile()) {
|
|
1080
|
+
const prior = found.get(file);
|
|
1081
|
+
if (prior === undefined || child < prior.source || (child === prior.source && path < prior.literal)) {
|
|
1082
|
+
found.set(file, { file, source: child, literal: path });
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
const files = [...found.values()].sort((left, right) =>
|
|
1090
|
+
left.file < right.file ? -1 : left.file > right.file ? 1 : 0,
|
|
1091
|
+
);
|
|
1092
|
+
cache.set(root, files);
|
|
1093
|
+
return files;
|
|
1094
|
+
}
|