3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-06-19 06:43:41 +00:00

Only key by Cargo.toml and Cargo.lock files of workspace members (#180)

This commit is contained in:
Max Heller 2023-12-03 05:57:51 -05:00 committed by GitHub
parent b1db5f9d5f
commit d30f1144e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 62 deletions

View file

@ -8,26 +8,33 @@ const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
export class Workspace {
constructor(public root: string, public target: string) {}
public async getPackages(): Promise<Packages> {
async getPackages(filter: ((p: Meta['packages'][0]) => boolean), ...extraArgs: string[]): Promise<Packages> {
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"], {
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
cwd: this.root,
}),
);
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
for (const pkg of meta.packages) {
if (pkg.manifest_path.startsWith(this.root)) {
continue;
}
for (const pkg of meta.packages.filter(filter)) {
const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name);
packages.push({ name: pkg.name, version: pkg.version, targets, path: path.dirname(pkg.manifest_path) });
}
} catch {}
} catch (err) {
console.error(err);
}
return packages;
}
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
}
public async getWorkspaceMembers(): Promise<Packages> {
return await this.getPackages(_ => true, "--no-deps");
}
}
export interface PackageDefinition {