3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2026-01-12 22:56:18 +00:00

Add support for running rust-cache commands from within a Nix shell (#290)

This commit is contained in:
marc0246 2025-12-01 19:56:12 +01:00 committed by GitHub
parent 779680da71
commit 151eeee51b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 167 additions and 43 deletions

View file

@ -8,12 +8,13 @@ const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
export class Workspace {
constructor(public root: string, public target: string) {}
async getPackages(filter: (p: Meta["packages"][0]) => boolean, ...extraArgs: string[]): Promise<Packages> {
async getPackages(cmdFormat: string, filter: (p: Meta["packages"][0]) => boolean, extraArgs?: string): Promise<Packages> {
const cmd = "cargo metadata --all-features --format-version 1" + (extraArgs ? ` ${extraArgs}` : "");
let packages: Packages = [];
try {
core.debug(`collecting metadata for "${this.root}"`);
const meta: Meta = JSON.parse(
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
await getCmdOutput(cmdFormat, cmd, {
cwd: this.root,
env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" },
}),
@ -29,12 +30,12 @@ export class Workspace {
return packages;
}
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
public async getPackagesOutsideWorkspaceRoot(cmdFormat: string): Promise<Packages> {
return await this.getPackages(cmdFormat, (pkg) => !pkg.manifest_path.startsWith(this.root));
}
public async getWorkspaceMembers(): Promise<Packages> {
return await this.getPackages((_) => true, "--no-deps");
public async getWorkspaceMembers(cmdFormat: string): Promise<Packages> {
return await this.getPackages(cmdFormat, (_) => true, "--no-deps");
}
}