@rightkit/release 0.2.107 → 0.2.109
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/cargo-contract.mjs +230 -230
- package/cargo-target.mjs +53 -53
- package/cli/right-release.mjs +10 -1
- package/development.mjs +230 -0
- package/hardeningscan.mjs +144 -144
- package/macos-signing-identity.mjs +13 -13
- package/managed-cargo.mjs +29 -29
- package/package.json +1 -1
- package/portable-development.mjs +181 -0
- package/preflight.mjs +12 -6
- package/rightkit-versions.json +144 -142
package/cargo-contract.mjs
CHANGED
|
@@ -1,230 +1,230 @@
|
|
|
1
|
-
import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { spawnSync } from "./background-process.mjs";
|
|
5
|
-
import { managedRuntimeClient, runCargoSync } from "./managed-cargo.mjs";
|
|
6
|
-
|
|
7
|
-
const SKIP_DIRECTORIES = new Set([".audit", ".cache", ".git", ".claude", ".right-release", ".worktrees", "node_modules", "target", "vendor"]);
|
|
8
|
-
const CRATES_IO_SOURCES = new Set([
|
|
9
|
-
"registry+https://github.com/rust-lang/crates.io-index",
|
|
10
|
-
"registry+https://index.crates.io/",
|
|
11
|
-
]);
|
|
12
|
-
const CACHE_V2_ENVIRONMENT = ["CARGO_HOME", "CARGO_TARGET_DIR", "RUSTC_WRAPPER", "SCCACHE_DIR", "SCCACHE_BASEDIRS", "RIGHT_RELEASE_CACHE_OWNER"];
|
|
13
|
-
|
|
14
|
-
export function managedCargoShimOnPath(env = process.env, platform = process.platform, exists = existsSync) {
|
|
15
|
-
const pathApi = platform === "win32" ? path.win32 : path.posix;
|
|
16
|
-
const delimiter = platform === "win32" ? ";" : ":";
|
|
17
|
-
const extensions = platform === "win32"
|
|
18
|
-
? String(env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)
|
|
19
|
-
: [""];
|
|
20
|
-
for (const directory of String(env.PATH ?? "").split(delimiter).filter(Boolean)) {
|
|
21
|
-
for (const extension of extensions) {
|
|
22
|
-
const candidate = pathApi.join(directory, `cargo${extension.toLowerCase()}`);
|
|
23
|
-
if (!exists(candidate)) continue;
|
|
24
|
-
return /(?:^|\/)(?:\.rightkit-managed|rightkitmanagedagent)\/agent-bin\/cargo(?:\.[^/]*)?$/i
|
|
25
|
-
.test(candidate.replaceAll("\\", "/"));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function brokerManagedHost(env = process.env, platform = process.platform, exists = existsSync) {
|
|
32
|
-
return Boolean(managedRuntimeClient(env, platform, exists)) || Boolean(env.RIGHTKIT_BUILD_BROKER_SOCKET) || managedCargoShimOnPath(env, platform, exists);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function isolatedCargoMetadataEnv(cargoHome, env = process.env, platform = process.platform, exists = existsSync) {
|
|
36
|
-
const metadataEnv = { ...env };
|
|
37
|
-
for (const name of CACHE_V2_ENVIRONMENT) delete metadataEnv[name];
|
|
38
|
-
if (brokerManagedHost(metadataEnv, platform, exists)) return metadataEnv;
|
|
39
|
-
return { ...metadataEnv, CARGO_HOME: cargoHome };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function cargoExecutable(platform = process.platform) {
|
|
43
|
-
return "cargo";
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function cargoArguments(args, platform = process.platform) {
|
|
47
|
-
return args;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function validateRightKitCargoContract(root, publishedVersions, label = path.basename(root)) {
|
|
51
|
-
const scanRoot = path.resolve(root);
|
|
52
|
-
const boundary = findRepositoryRoot(scanRoot);
|
|
53
|
-
const published = publishedVersions instanceof Map
|
|
54
|
-
? publishedVersions
|
|
55
|
-
: new Map(Object.entries(publishedVersions ?? {}));
|
|
56
|
-
const manifests = findCargoManifests(scanRoot);
|
|
57
|
-
const cargoHome = mkdtempSync(path.join(tmpdir(), "rightkit-cargo-home-"));
|
|
58
|
-
try {
|
|
59
|
-
for (const manifestPath of manifests) {
|
|
60
|
-
const manifestLabel = path.relative(boundary, manifestPath) || "Cargo.toml";
|
|
61
|
-
assertNoRightKitCargoOverrides(manifestPath, boundary, `${label}/${manifestLabel}`);
|
|
62
|
-
const dependencies = readCargoManifestDependencies(manifestPath, cargoHome, `${label}/${manifestLabel}`);
|
|
63
|
-
assertPublishedRightKitCargoDependencies(dependencies, published, `${label}/${manifestLabel}`);
|
|
64
|
-
}
|
|
65
|
-
} finally {
|
|
66
|
-
rmSync(cargoHome, { recursive: true, force: true });
|
|
67
|
-
}
|
|
68
|
-
return manifests.length;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function assertPublishedRightKitCargoDependencies(dependencies, published, label) {
|
|
72
|
-
let checked = 0;
|
|
73
|
-
for (const dependency of dependencies.filter(({ name }) => name.startsWith("rightkit-"))) {
|
|
74
|
-
checked += 1;
|
|
75
|
-
const configured = published.get(dependency.name);
|
|
76
|
-
if (!configured) throw new Error(`${label} ${dependency.name} is not a published RightKit crate`);
|
|
77
|
-
const allowed = configured instanceof Set ? configured : new Set(Array.isArray(configured) ? configured : [configured]);
|
|
78
|
-
const exactVersions = new Set([...allowed].map((version) => `=${version}`));
|
|
79
|
-
if (!CRATES_IO_SOURCES.has(dependency.source) || dependency.path || dependency.registry || !exactVersions.has(dependency.req)) {
|
|
80
|
-
throw new Error(`${label} ${dependency.name} must use exact crates.io versions (${[...exactVersions].join(" or ")})`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return checked;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function assertNoRightKitCargoOverrides(manifestPath, repoRoot, label) {
|
|
87
|
-
const boundary = path.resolve(repoRoot);
|
|
88
|
-
const manifest = path.resolve(manifestPath);
|
|
89
|
-
assertInsideBoundary(manifest, boundary);
|
|
90
|
-
assertNoRightKitOverrides(readToml(manifest, label), label, path.relative(boundary, manifest) || "Cargo.toml");
|
|
91
|
-
|
|
92
|
-
for (const configPath of findRepoCargoConfigs(path.dirname(manifest), boundary)) {
|
|
93
|
-
const source = path.relative(boundary, configPath);
|
|
94
|
-
const parsed = readToml(configPath, source);
|
|
95
|
-
assertNoRightKitOverrides(parsed, label, source);
|
|
96
|
-
const cratesIo = parsed.source?.["crates-io"];
|
|
97
|
-
if (cratesIo && typeof cratesIo === "object"
|
|
98
|
-
&& ["replace-with", "directory", "git", "registry", "local-registry"].some((key) => key in cratesIo)) {
|
|
99
|
-
throw new Error(`${label} has forbidden crates.io source replacement in ${source}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function readCargoManifestDependencies(manifestPath, cargoHome, label) {
|
|
105
|
-
const result = runCargoSync(
|
|
106
|
-
cargoArguments(["metadata", "--no-deps", "--offline", "--format-version", "1", "--manifest-path", manifestPath]),
|
|
107
|
-
{
|
|
108
|
-
cwd: path.dirname(manifestPath),
|
|
109
|
-
encoding: "utf8",
|
|
110
|
-
env: isolatedCargoMetadataEnv(cargoHome),
|
|
111
|
-
windowsHide: true,
|
|
112
|
-
},
|
|
113
|
-
);
|
|
114
|
-
if (result.error) {
|
|
115
|
-
// spawnSync failed to launch the process at all (no exit code, no stderr) -
|
|
116
|
-
// a missing/unspawnable binary, not cargo rejecting the manifest. Reporting
|
|
117
|
-
// this as a version-contract violation sent a real diagnosis (a Windows
|
|
118
|
-
// rustup-proxy binary that can't be spawned from a non-console session)
|
|
119
|
-
// down the wrong path: it read as "fix your Cargo.toml" instead of "cargo
|
|
120
|
-
// could not be launched here".
|
|
121
|
-
throw new Error(`${label} could not launch ${cargoExecutable()} to read Cargo metadata: ${result.error.message}`);
|
|
122
|
-
}
|
|
123
|
-
if (result.status !== 0) {
|
|
124
|
-
throw new Error(`${label} Cargo metadata rejected manifest; RightKit dependencies must use exact crates.io versions: ${String(result.stderr ?? "").trim()}`);
|
|
125
|
-
}
|
|
126
|
-
const metadata = JSON.parse(result.stdout);
|
|
127
|
-
const expectedPath = path.resolve(manifestPath).toLowerCase();
|
|
128
|
-
const pkg = metadata.packages.find(({ manifest_path: candidate }) => path.resolve(candidate).toLowerCase() === expectedPath);
|
|
129
|
-
if (!pkg && path.resolve(metadata.workspace_root, "Cargo.toml").toLowerCase() === expectedPath) return [];
|
|
130
|
-
if (!pkg) throw new Error(`${label} was not returned by Cargo metadata`);
|
|
131
|
-
return pkg.dependencies;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function assertNoRightKitOverrides(parsed, label, source) {
|
|
135
|
-
for (const overrides of Object.values(parsed.patch ?? {})) {
|
|
136
|
-
if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) continue;
|
|
137
|
-
for (const [name, specifier] of Object.entries(overrides)) {
|
|
138
|
-
const packageName = typeof specifier === "object" && specifier ? specifier.package : undefined;
|
|
139
|
-
if (name.startsWith("rightkit-") || packageName?.startsWith("rightkit-")) {
|
|
140
|
-
throw new Error(`${label} has forbidden RightKit Cargo override ${name} in ${source}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
for (const [name, specifier] of Object.entries(parsed.replace ?? {})) {
|
|
145
|
-
const packageName = typeof specifier === "object" && specifier ? specifier.package : undefined;
|
|
146
|
-
if (name.split(":", 1)[0].startsWith("rightkit-") || packageName?.startsWith("rightkit-")) {
|
|
147
|
-
throw new Error(`${label} has forbidden RightKit Cargo override ${name} in ${source}`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// `tomllib` is Python 3.11+. Windows pins `py -3.11`, but a bare `python3` on macOS is the system
|
|
153
|
-
// 3.9, which has no tomllib — so every app's release:doctor died on a stock Mac, and reported the
|
|
154
|
-
// manifest as invalid TOML when the real problem was the interpreter. Probe for one that can.
|
|
155
|
-
let tomlRunner;
|
|
156
|
-
function resolveTomlRunner() {
|
|
157
|
-
if (tomlRunner) return tomlRunner;
|
|
158
|
-
const probe = "import sys,tomllib";
|
|
159
|
-
const candidates =
|
|
160
|
-
process.platform === "win32"
|
|
161
|
-
? [["py", ["-3.11"]], ["py", ["-3"]], ["python", []]]
|
|
162
|
-
: [["python3.13", []], ["python3.12", []], ["python3.11", []], ["python3", []]];
|
|
163
|
-
for (const [command, prefix] of candidates) {
|
|
164
|
-
const check = spawnSync(command, [...prefix, "-c", probe], { encoding: "utf8", windowsHide: true });
|
|
165
|
-
if (check.status === 0) {
|
|
166
|
-
tomlRunner = { command, prefix };
|
|
167
|
-
return tomlRunner;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
throw new Error(
|
|
171
|
-
"no Python with tomllib found (needs 3.11+). Install one, or put it on PATH: the release " +
|
|
172
|
-
"contract reads Cargo manifests through it.",
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function readToml(file, label) {
|
|
177
|
-
const script = "import json,pathlib,sys,tomllib; json.dump(tomllib.loads(pathlib.Path(sys.argv[1]).read_text(encoding='utf-8')),sys.stdout,default=str)";
|
|
178
|
-
const { command, prefix } = resolveTomlRunner();
|
|
179
|
-
const result = spawnSync(command, [...prefix, "-c", script, file], { encoding: "utf8", windowsHide: true });
|
|
180
|
-
if (result.status !== 0) throw new Error(`${label} is not valid TOML: ${String(result.stderr ?? "").trim()}`);
|
|
181
|
-
return JSON.parse(result.stdout);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function findCargoManifests(root) {
|
|
185
|
-
const found = [];
|
|
186
|
-
const visit = (dir) => {
|
|
187
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
188
|
-
if (entry.isDirectory() && SKIP_DIRECTORIES.has(entry.name)) continue;
|
|
189
|
-
const full = path.join(dir, entry.name);
|
|
190
|
-
if (entry.isDirectory()) visit(full);
|
|
191
|
-
else if (entry.isFile() && entry.name === "Cargo.toml") found.push(full);
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
visit(root);
|
|
195
|
-
return found;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function findRepoCargoConfigs(start, repoRoot) {
|
|
199
|
-
const boundary = path.resolve(repoRoot);
|
|
200
|
-
let current = path.resolve(start);
|
|
201
|
-
assertInsideBoundary(current, boundary);
|
|
202
|
-
const configs = [];
|
|
203
|
-
while (true) {
|
|
204
|
-
for (const filename of ["config", "config.toml"]) {
|
|
205
|
-
const candidate = path.join(current, ".cargo", filename);
|
|
206
|
-
if (existsSync(candidate)) configs.push(candidate);
|
|
207
|
-
}
|
|
208
|
-
if (current.toLowerCase() === boundary.toLowerCase()) break;
|
|
209
|
-
current = path.dirname(current);
|
|
210
|
-
}
|
|
211
|
-
return configs;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function assertInsideBoundary(candidate, boundary) {
|
|
215
|
-
const relative = path.relative(boundary, candidate);
|
|
216
|
-
if (relative !== "" && (relative.startsWith("..") || path.isAbsolute(relative))) {
|
|
217
|
-
throw new Error(`${candidate} is outside ${boundary}`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function findRepositoryRoot(start) {
|
|
222
|
-
const original = path.resolve(start);
|
|
223
|
-
let current = original;
|
|
224
|
-
while (true) {
|
|
225
|
-
if (existsSync(path.join(current, ".git"))) return current;
|
|
226
|
-
const parent = path.dirname(current);
|
|
227
|
-
if (parent === current) return original;
|
|
228
|
-
current = parent;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
1
|
+
import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { spawnSync } from "./background-process.mjs";
|
|
5
|
+
import { managedRuntimeClient, runCargoSync } from "./managed-cargo.mjs";
|
|
6
|
+
|
|
7
|
+
const SKIP_DIRECTORIES = new Set([".audit", ".cache", ".git", ".claude", ".right-release", ".worktrees", "node_modules", "target", "vendor"]);
|
|
8
|
+
const CRATES_IO_SOURCES = new Set([
|
|
9
|
+
"registry+https://github.com/rust-lang/crates.io-index",
|
|
10
|
+
"registry+https://index.crates.io/",
|
|
11
|
+
]);
|
|
12
|
+
const CACHE_V2_ENVIRONMENT = ["CARGO_HOME", "CARGO_TARGET_DIR", "RUSTC_WRAPPER", "SCCACHE_DIR", "SCCACHE_BASEDIRS", "RIGHT_RELEASE_CACHE_OWNER"];
|
|
13
|
+
|
|
14
|
+
export function managedCargoShimOnPath(env = process.env, platform = process.platform, exists = existsSync) {
|
|
15
|
+
const pathApi = platform === "win32" ? path.win32 : path.posix;
|
|
16
|
+
const delimiter = platform === "win32" ? ";" : ":";
|
|
17
|
+
const extensions = platform === "win32"
|
|
18
|
+
? String(env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)
|
|
19
|
+
: [""];
|
|
20
|
+
for (const directory of String(env.PATH ?? "").split(delimiter).filter(Boolean)) {
|
|
21
|
+
for (const extension of extensions) {
|
|
22
|
+
const candidate = pathApi.join(directory, `cargo${extension.toLowerCase()}`);
|
|
23
|
+
if (!exists(candidate)) continue;
|
|
24
|
+
return /(?:^|\/)(?:\.rightkit-managed|rightkitmanagedagent)\/agent-bin\/cargo(?:\.[^/]*)?$/i
|
|
25
|
+
.test(candidate.replaceAll("\\", "/"));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function brokerManagedHost(env = process.env, platform = process.platform, exists = existsSync) {
|
|
32
|
+
return Boolean(managedRuntimeClient(env, platform, exists)) || Boolean(env.RIGHTKIT_BUILD_BROKER_SOCKET) || managedCargoShimOnPath(env, platform, exists);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isolatedCargoMetadataEnv(cargoHome, env = process.env, platform = process.platform, exists = existsSync) {
|
|
36
|
+
const metadataEnv = { ...env };
|
|
37
|
+
for (const name of CACHE_V2_ENVIRONMENT) delete metadataEnv[name];
|
|
38
|
+
if (brokerManagedHost(metadataEnv, platform, exists)) return metadataEnv;
|
|
39
|
+
return { ...metadataEnv, CARGO_HOME: cargoHome };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function cargoExecutable(platform = process.platform) {
|
|
43
|
+
return "cargo";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function cargoArguments(args, platform = process.platform) {
|
|
47
|
+
return args;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function validateRightKitCargoContract(root, publishedVersions, label = path.basename(root)) {
|
|
51
|
+
const scanRoot = path.resolve(root);
|
|
52
|
+
const boundary = findRepositoryRoot(scanRoot);
|
|
53
|
+
const published = publishedVersions instanceof Map
|
|
54
|
+
? publishedVersions
|
|
55
|
+
: new Map(Object.entries(publishedVersions ?? {}));
|
|
56
|
+
const manifests = findCargoManifests(scanRoot);
|
|
57
|
+
const cargoHome = mkdtempSync(path.join(tmpdir(), "rightkit-cargo-home-"));
|
|
58
|
+
try {
|
|
59
|
+
for (const manifestPath of manifests) {
|
|
60
|
+
const manifestLabel = path.relative(boundary, manifestPath) || "Cargo.toml";
|
|
61
|
+
assertNoRightKitCargoOverrides(manifestPath, boundary, `${label}/${manifestLabel}`);
|
|
62
|
+
const dependencies = readCargoManifestDependencies(manifestPath, cargoHome, `${label}/${manifestLabel}`);
|
|
63
|
+
assertPublishedRightKitCargoDependencies(dependencies, published, `${label}/${manifestLabel}`);
|
|
64
|
+
}
|
|
65
|
+
} finally {
|
|
66
|
+
rmSync(cargoHome, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
return manifests.length;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function assertPublishedRightKitCargoDependencies(dependencies, published, label) {
|
|
72
|
+
let checked = 0;
|
|
73
|
+
for (const dependency of dependencies.filter(({ name }) => name.startsWith("rightkit-"))) {
|
|
74
|
+
checked += 1;
|
|
75
|
+
const configured = published.get(dependency.name);
|
|
76
|
+
if (!configured) throw new Error(`${label} ${dependency.name} is not a published RightKit crate`);
|
|
77
|
+
const allowed = configured instanceof Set ? configured : new Set(Array.isArray(configured) ? configured : [configured]);
|
|
78
|
+
const exactVersions = new Set([...allowed].map((version) => `=${version}`));
|
|
79
|
+
if (!CRATES_IO_SOURCES.has(dependency.source) || dependency.path || dependency.registry || !exactVersions.has(dependency.req)) {
|
|
80
|
+
throw new Error(`${label} ${dependency.name} must use exact crates.io versions (${[...exactVersions].join(" or ")})`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return checked;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function assertNoRightKitCargoOverrides(manifestPath, repoRoot, label) {
|
|
87
|
+
const boundary = path.resolve(repoRoot);
|
|
88
|
+
const manifest = path.resolve(manifestPath);
|
|
89
|
+
assertInsideBoundary(manifest, boundary);
|
|
90
|
+
assertNoRightKitOverrides(readToml(manifest, label), label, path.relative(boundary, manifest) || "Cargo.toml");
|
|
91
|
+
|
|
92
|
+
for (const configPath of findRepoCargoConfigs(path.dirname(manifest), boundary)) {
|
|
93
|
+
const source = path.relative(boundary, configPath);
|
|
94
|
+
const parsed = readToml(configPath, source);
|
|
95
|
+
assertNoRightKitOverrides(parsed, label, source);
|
|
96
|
+
const cratesIo = parsed.source?.["crates-io"];
|
|
97
|
+
if (cratesIo && typeof cratesIo === "object"
|
|
98
|
+
&& ["replace-with", "directory", "git", "registry", "local-registry"].some((key) => key in cratesIo)) {
|
|
99
|
+
throw new Error(`${label} has forbidden crates.io source replacement in ${source}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function readCargoManifestDependencies(manifestPath, cargoHome, label) {
|
|
105
|
+
const result = runCargoSync(
|
|
106
|
+
cargoArguments(["metadata", "--no-deps", "--offline", "--format-version", "1", "--manifest-path", manifestPath]),
|
|
107
|
+
{
|
|
108
|
+
cwd: path.dirname(manifestPath),
|
|
109
|
+
encoding: "utf8",
|
|
110
|
+
env: isolatedCargoMetadataEnv(cargoHome),
|
|
111
|
+
windowsHide: true,
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
if (result.error) {
|
|
115
|
+
// spawnSync failed to launch the process at all (no exit code, no stderr) -
|
|
116
|
+
// a missing/unspawnable binary, not cargo rejecting the manifest. Reporting
|
|
117
|
+
// this as a version-contract violation sent a real diagnosis (a Windows
|
|
118
|
+
// rustup-proxy binary that can't be spawned from a non-console session)
|
|
119
|
+
// down the wrong path: it read as "fix your Cargo.toml" instead of "cargo
|
|
120
|
+
// could not be launched here".
|
|
121
|
+
throw new Error(`${label} could not launch ${cargoExecutable()} to read Cargo metadata: ${result.error.message}`);
|
|
122
|
+
}
|
|
123
|
+
if (result.status !== 0) {
|
|
124
|
+
throw new Error(`${label} Cargo metadata rejected manifest; RightKit dependencies must use exact crates.io versions: ${String(result.stderr ?? "").trim()}`);
|
|
125
|
+
}
|
|
126
|
+
const metadata = JSON.parse(result.stdout);
|
|
127
|
+
const expectedPath = path.resolve(manifestPath).toLowerCase();
|
|
128
|
+
const pkg = metadata.packages.find(({ manifest_path: candidate }) => path.resolve(candidate).toLowerCase() === expectedPath);
|
|
129
|
+
if (!pkg && path.resolve(metadata.workspace_root, "Cargo.toml").toLowerCase() === expectedPath) return [];
|
|
130
|
+
if (!pkg) throw new Error(`${label} was not returned by Cargo metadata`);
|
|
131
|
+
return pkg.dependencies;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function assertNoRightKitOverrides(parsed, label, source) {
|
|
135
|
+
for (const overrides of Object.values(parsed.patch ?? {})) {
|
|
136
|
+
if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) continue;
|
|
137
|
+
for (const [name, specifier] of Object.entries(overrides)) {
|
|
138
|
+
const packageName = typeof specifier === "object" && specifier ? specifier.package : undefined;
|
|
139
|
+
if (name.startsWith("rightkit-") || packageName?.startsWith("rightkit-")) {
|
|
140
|
+
throw new Error(`${label} has forbidden RightKit Cargo override ${name} in ${source}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const [name, specifier] of Object.entries(parsed.replace ?? {})) {
|
|
145
|
+
const packageName = typeof specifier === "object" && specifier ? specifier.package : undefined;
|
|
146
|
+
if (name.split(":", 1)[0].startsWith("rightkit-") || packageName?.startsWith("rightkit-")) {
|
|
147
|
+
throw new Error(`${label} has forbidden RightKit Cargo override ${name} in ${source}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// `tomllib` is Python 3.11+. Windows pins `py -3.11`, but a bare `python3` on macOS is the system
|
|
153
|
+
// 3.9, which has no tomllib — so every app's release:doctor died on a stock Mac, and reported the
|
|
154
|
+
// manifest as invalid TOML when the real problem was the interpreter. Probe for one that can.
|
|
155
|
+
let tomlRunner;
|
|
156
|
+
function resolveTomlRunner() {
|
|
157
|
+
if (tomlRunner) return tomlRunner;
|
|
158
|
+
const probe = "import sys,tomllib";
|
|
159
|
+
const candidates =
|
|
160
|
+
process.platform === "win32"
|
|
161
|
+
? [["py", ["-3.11"]], ["py", ["-3"]], ["python", []]]
|
|
162
|
+
: [["python3.13", []], ["python3.12", []], ["python3.11", []], ["python3", []]];
|
|
163
|
+
for (const [command, prefix] of candidates) {
|
|
164
|
+
const check = spawnSync(command, [...prefix, "-c", probe], { encoding: "utf8", windowsHide: true });
|
|
165
|
+
if (check.status === 0) {
|
|
166
|
+
tomlRunner = { command, prefix };
|
|
167
|
+
return tomlRunner;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
throw new Error(
|
|
171
|
+
"no Python with tomllib found (needs 3.11+). Install one, or put it on PATH: the release " +
|
|
172
|
+
"contract reads Cargo manifests through it.",
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function readToml(file, label) {
|
|
177
|
+
const script = "import json,pathlib,sys,tomllib; json.dump(tomllib.loads(pathlib.Path(sys.argv[1]).read_text(encoding='utf-8')),sys.stdout,default=str)";
|
|
178
|
+
const { command, prefix } = resolveTomlRunner();
|
|
179
|
+
const result = spawnSync(command, [...prefix, "-c", script, file], { encoding: "utf8", windowsHide: true });
|
|
180
|
+
if (result.status !== 0) throw new Error(`${label} is not valid TOML: ${String(result.stderr ?? "").trim()}`);
|
|
181
|
+
return JSON.parse(result.stdout);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function findCargoManifests(root) {
|
|
185
|
+
const found = [];
|
|
186
|
+
const visit = (dir) => {
|
|
187
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
188
|
+
if (entry.isDirectory() && SKIP_DIRECTORIES.has(entry.name)) continue;
|
|
189
|
+
const full = path.join(dir, entry.name);
|
|
190
|
+
if (entry.isDirectory()) visit(full);
|
|
191
|
+
else if (entry.isFile() && entry.name === "Cargo.toml") found.push(full);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
visit(root);
|
|
195
|
+
return found;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function findRepoCargoConfigs(start, repoRoot) {
|
|
199
|
+
const boundary = path.resolve(repoRoot);
|
|
200
|
+
let current = path.resolve(start);
|
|
201
|
+
assertInsideBoundary(current, boundary);
|
|
202
|
+
const configs = [];
|
|
203
|
+
while (true) {
|
|
204
|
+
for (const filename of ["config", "config.toml"]) {
|
|
205
|
+
const candidate = path.join(current, ".cargo", filename);
|
|
206
|
+
if (existsSync(candidate)) configs.push(candidate);
|
|
207
|
+
}
|
|
208
|
+
if (current.toLowerCase() === boundary.toLowerCase()) break;
|
|
209
|
+
current = path.dirname(current);
|
|
210
|
+
}
|
|
211
|
+
return configs;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function assertInsideBoundary(candidate, boundary) {
|
|
215
|
+
const relative = path.relative(boundary, candidate);
|
|
216
|
+
if (relative !== "" && (relative.startsWith("..") || path.isAbsolute(relative))) {
|
|
217
|
+
throw new Error(`${candidate} is outside ${boundary}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function findRepositoryRoot(start) {
|
|
222
|
+
const original = path.resolve(start);
|
|
223
|
+
let current = original;
|
|
224
|
+
while (true) {
|
|
225
|
+
if (existsSync(path.join(current, ".git"))) return current;
|
|
226
|
+
const parent = path.dirname(current);
|
|
227
|
+
if (parent === current) return original;
|
|
228
|
+
current = parent;
|
|
229
|
+
}
|
|
230
|
+
}
|
package/cargo-target.mjs
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Resolves the Cargo target directory for a manifest by asking Cargo itself.
|
|
3
|
-
//
|
|
4
|
-
// `cargo metadata` is authoritative on BOTH broker-managed and unmanaged
|
|
5
|
-
// hosts: through a managed shim it reports the broker's own workspace target
|
|
6
|
-
// directory; without one it reports the local `target/` directory. LOCATING
|
|
7
|
-
// the target directory therefore never needs broker detection — the metadata
|
|
8
|
-
// command already reflects whichever host it runs on. `brokerManagedHost()`
|
|
9
|
-
// (see cargo-contract.mjs) remains a separate, cache-policy-only decision:
|
|
10
|
-
// whether Cache V2's lease/slot/prune/floor machinery should run at all, not
|
|
11
|
-
// where the target directory lives.
|
|
12
|
-
import { execFileSync } from "./background-process.mjs";
|
|
13
|
-
import { runCargoSync } from "./managed-cargo.mjs";
|
|
14
|
-
import path from "node:path";
|
|
15
|
-
import { fileURLToPath } from "node:url";
|
|
16
|
-
|
|
17
|
-
export function resolveTargetRoot(manifestPath, options = {}) {
|
|
18
|
-
if (!manifestPath) throw new Error("resolveTargetRoot requires a Cargo.toml manifest path");
|
|
19
|
-
const execute = options.execFileSync ?? execFileSync;
|
|
20
|
-
let output;
|
|
21
|
-
try {
|
|
22
|
-
const args = ["metadata", "--offline", "--format-version", "1", "--no-deps", "--manifest-path", manifestPath];
|
|
23
|
-
if (options.execFileSync) {
|
|
24
|
-
output = execute("cargo", args, { cwd: path.dirname(manifestPath), encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
25
|
-
} else {
|
|
26
|
-
const result = runCargoSync(args, { cwd: path.dirname(manifestPath), encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
27
|
-
if (result.error) throw result.error;
|
|
28
|
-
if (result.status !== 0) throw new Error(String(result.stderr ?? "").trim() || `exited ${result.status}`);
|
|
29
|
-
output = result.stdout;
|
|
30
|
-
}
|
|
31
|
-
} catch (error) {
|
|
32
|
-
throw new Error(`metadata failed for ${manifestPath}: ${error.message}`);
|
|
33
|
-
}
|
|
34
|
-
const { target_directory: directory } = JSON.parse(output);
|
|
35
|
-
if (typeof directory !== "string" || directory.length === 0 || !path.isAbsolute(directory)) {
|
|
36
|
-
throw new Error(`metadata for ${manifestPath} did not report an absolute target_directory`);
|
|
37
|
-
}
|
|
38
|
-
return path.resolve(directory);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
|
|
42
|
-
const manifestPath = process.argv[2];
|
|
43
|
-
if (!manifestPath) {
|
|
44
|
-
console.error("usage: cargo-target.mjs <path-to-Cargo.toml>");
|
|
45
|
-
process.exit(1);
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
process.stdout.write(`${resolveTargetRoot(manifestPath)}\n`);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error(error.message);
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Resolves the Cargo target directory for a manifest by asking Cargo itself.
|
|
3
|
+
//
|
|
4
|
+
// `cargo metadata` is authoritative on BOTH broker-managed and unmanaged
|
|
5
|
+
// hosts: through a managed shim it reports the broker's own workspace target
|
|
6
|
+
// directory; without one it reports the local `target/` directory. LOCATING
|
|
7
|
+
// the target directory therefore never needs broker detection — the metadata
|
|
8
|
+
// command already reflects whichever host it runs on. `brokerManagedHost()`
|
|
9
|
+
// (see cargo-contract.mjs) remains a separate, cache-policy-only decision:
|
|
10
|
+
// whether Cache V2's lease/slot/prune/floor machinery should run at all, not
|
|
11
|
+
// where the target directory lives.
|
|
12
|
+
import { execFileSync } from "./background-process.mjs";
|
|
13
|
+
import { runCargoSync } from "./managed-cargo.mjs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
|
|
17
|
+
export function resolveTargetRoot(manifestPath, options = {}) {
|
|
18
|
+
if (!manifestPath) throw new Error("resolveTargetRoot requires a Cargo.toml manifest path");
|
|
19
|
+
const execute = options.execFileSync ?? execFileSync;
|
|
20
|
+
let output;
|
|
21
|
+
try {
|
|
22
|
+
const args = ["metadata", "--offline", "--format-version", "1", "--no-deps", "--manifest-path", manifestPath];
|
|
23
|
+
if (options.execFileSync) {
|
|
24
|
+
output = execute("cargo", args, { cwd: path.dirname(manifestPath), encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
25
|
+
} else {
|
|
26
|
+
const result = runCargoSync(args, { cwd: path.dirname(manifestPath), encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
27
|
+
if (result.error) throw result.error;
|
|
28
|
+
if (result.status !== 0) throw new Error(String(result.stderr ?? "").trim() || `exited ${result.status}`);
|
|
29
|
+
output = result.stdout;
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw new Error(`metadata failed for ${manifestPath}: ${error.message}`);
|
|
33
|
+
}
|
|
34
|
+
const { target_directory: directory } = JSON.parse(output);
|
|
35
|
+
if (typeof directory !== "string" || directory.length === 0 || !path.isAbsolute(directory)) {
|
|
36
|
+
throw new Error(`metadata for ${manifestPath} did not report an absolute target_directory`);
|
|
37
|
+
}
|
|
38
|
+
return path.resolve(directory);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
|
|
42
|
+
const manifestPath = process.argv[2];
|
|
43
|
+
if (!manifestPath) {
|
|
44
|
+
console.error("usage: cargo-target.mjs <path-to-Cargo.toml>");
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
process.stdout.write(`${resolveTargetRoot(manifestPath)}\n`);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(error.message);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
}
|
package/cli/right-release.mjs
CHANGED
|
@@ -26,6 +26,12 @@ const commands = new Map([
|
|
|
26
26
|
|
|
27
27
|
const args = process.argv.slice(2);
|
|
28
28
|
const first = args[0];
|
|
29
|
+
if (first === "dev") {
|
|
30
|
+
import("../development.mjs").then(({ main }) => main(args.slice(1))).catch((error) => {
|
|
31
|
+
console.error(`right-release dev: ${error.message}`);
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
29
35
|
const githubBuildCommands = new Set(["release", "build", "package", "sign-windows", "sign-updater", "create-mac-updater", "cargo-target"]);
|
|
30
36
|
|
|
31
37
|
try {
|
|
@@ -143,6 +149,8 @@ function printHelp() {
|
|
|
143
149
|
Commands:
|
|
144
150
|
build [--platform mac|win] [--skip-checks] [--resume-from <phase>]
|
|
145
151
|
Resume macOS at prepackage, sign, package, post-sign, or harden
|
|
152
|
+
dev --platform win|mac [--config <path>] [--dry-run] [--build-only]
|
|
153
|
+
Incremental unsigned build & optional local install
|
|
146
154
|
upload --release <id> --platform mac|win --tier patch|update
|
|
147
155
|
Upload one sealed release; never builds
|
|
148
156
|
release Compatibility alias for build
|
|
@@ -169,5 +177,6 @@ Commands:
|
|
|
169
177
|
Attach sealed signed artifacts to a verified GitHub Release
|
|
170
178
|
|
|
171
179
|
Direct flags are treated as: right-release build <flags>.
|
|
172
|
-
Build is tier-neutral. Upload requires an explicit tier.
|
|
180
|
+
Build is tier-neutral. Upload requires an explicit tier. Dev builds are incremental and unsigned.`);
|
|
181
|
+
}
|
|
173
182
|
}
|