mirror of
https://github.com/Swatinem/rust-cache
synced 2025-04-10 22:57:07 +00:00
only key by Cargo.toml and Cargo.lock files of workspace members
This commit is contained in:
parent
b1db5f9d5f
commit
542fe36d5b
26
dist/restore/index.js
vendored
26
dist/restore/index.js
vendored
|
@ -87018,25 +87018,30 @@ class Workspace {
|
|||
this.root = root;
|
||||
this.target = target;
|
||||
}
|
||||
async getPackages() {
|
||||
async getPackages(filter, ...extraArgs) {
|
||||
let packages = [];
|
||||
try {
|
||||
lib_core.debug(`collecting metadata for "${this.root}"`);
|
||||
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], {
|
||||
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
|
||||
cwd: this.root,
|
||||
}));
|
||||
lib_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: external_path_default().dirname(pkg.manifest_path) });
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return packages;
|
||||
}
|
||||
async getPackagesOutsideWorkspaceRoot() {
|
||||
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
|
||||
}
|
||||
async getWorkspaceMembers() {
|
||||
return await this.getPackages(_ => true, "--no-deps");
|
||||
}
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/config.ts
|
||||
|
@ -87152,7 +87157,8 @@ class CacheConfig {
|
|||
for (const workspace of workspaces) {
|
||||
const root = workspace.root;
|
||||
keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
|
||||
const cargo_manifests = sort_and_uniq(await globFiles(`${root}/**/Cargo.toml`));
|
||||
const workspaceMembers = await workspace.getWorkspaceMembers();
|
||||
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => external_path_default().join(member.path, "Cargo.toml")));
|
||||
for (const cargo_manifest of cargo_manifests) {
|
||||
try {
|
||||
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
|
||||
|
@ -87193,7 +87199,9 @@ class CacheConfig {
|
|||
keyFiles.push(cargo_manifest);
|
||||
}
|
||||
}
|
||||
const cargo_locks = sort_and_uniq(await globFiles(`${root}/**/Cargo.lock`));
|
||||
const cargo_locks = sort_and_uniq(workspaceMembers
|
||||
.map(member => external_path_default().join(member.path, "Cargo.lock"))
|
||||
.filter((external_fs_default()).existsSync));
|
||||
for (const cargo_lock of cargo_locks) {
|
||||
try {
|
||||
const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" });
|
||||
|
|
28
dist/save/index.js
vendored
28
dist/save/index.js
vendored
|
@ -87018,25 +87018,30 @@ class Workspace {
|
|||
this.root = root;
|
||||
this.target = target;
|
||||
}
|
||||
async getPackages() {
|
||||
async getPackages(filter, ...extraArgs) {
|
||||
let packages = [];
|
||||
try {
|
||||
core.debug(`collecting metadata for "${this.root}"`);
|
||||
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], {
|
||||
const meta = JSON.parse(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: external_path_default().dirname(pkg.manifest_path) });
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return packages;
|
||||
}
|
||||
async getPackagesOutsideWorkspaceRoot() {
|
||||
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
|
||||
}
|
||||
async getWorkspaceMembers() {
|
||||
return await this.getPackages(_ => true, "--no-deps");
|
||||
}
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/config.ts
|
||||
|
@ -87152,7 +87157,8 @@ class CacheConfig {
|
|||
for (const workspace of workspaces) {
|
||||
const root = workspace.root;
|
||||
keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
|
||||
const cargo_manifests = sort_and_uniq(await globFiles(`${root}/**/Cargo.toml`));
|
||||
const workspaceMembers = await workspace.getWorkspaceMembers();
|
||||
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => external_path_default().join(member.path, "Cargo.toml")));
|
||||
for (const cargo_manifest of cargo_manifests) {
|
||||
try {
|
||||
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
|
||||
|
@ -87193,7 +87199,9 @@ class CacheConfig {
|
|||
keyFiles.push(cargo_manifest);
|
||||
}
|
||||
}
|
||||
const cargo_locks = sort_and_uniq(await globFiles(`${root}/**/Cargo.lock`));
|
||||
const cargo_locks = sort_and_uniq(workspaceMembers
|
||||
.map(member => external_path_default().join(member.path, "Cargo.lock"))
|
||||
.filter((external_fs_default()).existsSync));
|
||||
for (const cargo_lock of cargo_locks) {
|
||||
try {
|
||||
const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" });
|
||||
|
@ -87678,7 +87686,7 @@ async function run() {
|
|||
await macOsWorkaround();
|
||||
const allPackages = [];
|
||||
for (const workspace of config.workspaces) {
|
||||
const packages = await workspace.getPackages();
|
||||
const packages = await workspace.getPackagesOutsideWorkspaceRoot();
|
||||
allPackages.push(...packages);
|
||||
try {
|
||||
core.info(`... Cleaning ${workspace.target} ...`);
|
||||
|
|
|
@ -142,7 +142,9 @@ export class CacheConfig {
|
|||
)),
|
||||
);
|
||||
|
||||
const cargo_manifests = sort_and_uniq(await globFiles(`${root}/**/Cargo.toml`));
|
||||
const workspaceMembers = await workspace.getWorkspaceMembers();
|
||||
|
||||
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => path.join(member.path, "Cargo.toml")));
|
||||
|
||||
for (const cargo_manifest of cargo_manifests) {
|
||||
try {
|
||||
|
@ -189,7 +191,10 @@ export class CacheConfig {
|
|||
}
|
||||
}
|
||||
|
||||
const cargo_locks = sort_and_uniq(await globFiles(`${root}/**/Cargo.lock`));
|
||||
const cargo_locks = sort_and_uniq(workspaceMembers
|
||||
.map(member => path.join(member.path, "Cargo.lock"))
|
||||
.filter(fs.existsSync)
|
||||
);
|
||||
|
||||
for (const cargo_lock of cargo_locks) {
|
||||
try {
|
||||
|
|
|
@ -36,7 +36,7 @@ async function run() {
|
|||
|
||||
const allPackages = [];
|
||||
for (const workspace of config.workspaces) {
|
||||
const packages = await workspace.getPackages();
|
||||
const packages = await workspace.getPackagesOutsideWorkspaceRoot();
|
||||
allPackages.push(...packages);
|
||||
try {
|
||||
core.info(`... Cleaning ${workspace.target} ...`);
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue