mirror of
https://github.com/Swatinem/rust-cache
synced 2025-04-22 03:26:42 +00:00
Update getPackages
This commit is contained in:
parent
b6a2848a50
commit
971fd2148b
4 changed files with 21 additions and 10 deletions
|
@ -14,6 +14,9 @@ inputs:
|
|||
target-dir:
|
||||
description: "The target dir that should be cleaned and persisted, defaults to `./target`"
|
||||
required: false
|
||||
workspace-paths:
|
||||
description: "Paths to multiple Cargo workspaces, separated by newlines"
|
||||
required: false
|
||||
cache-on-failure:
|
||||
description: "Cache even if the build fails. Defaults to false"
|
||||
required: false
|
||||
|
|
|
@ -186,16 +186,24 @@ interface Meta {
|
|||
}>;
|
||||
}
|
||||
|
||||
export async function getPackages(): Promise<Packages> {
|
||||
export async function getPackages(workspacePaths: Array<string>): Promise<Packages> {
|
||||
const cwd = process.cwd();
|
||||
const meta: Meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"]));
|
||||
|
||||
return meta.packages
|
||||
.filter((p) => !p.manifest_path.startsWith(cwd))
|
||||
.map((p) => {
|
||||
const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
|
||||
return { name: p.name, version: p.version, targets, path: path.dirname(p.manifest_path) };
|
||||
});
|
||||
let allPackages: Packages = [];
|
||||
for (const workspacePath of workspacePaths) {
|
||||
process.chdir(workspacePath);
|
||||
const meta: Meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"]));
|
||||
const workspacePackages = meta.packages
|
||||
.filter((p) => !p.manifest_path.startsWith(cwd))
|
||||
.map((p) => {
|
||||
const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
|
||||
return { name: p.name, version: p.version, targets, path: path.dirname(p.manifest_path) };
|
||||
});
|
||||
allPackages = allPackages.concat(workspacePackages);
|
||||
}
|
||||
|
||||
process.chdir(cwd);
|
||||
return allPackages;
|
||||
}
|
||||
|
||||
export async function cleanTarget(targetDir: string, packages: Packages) {
|
||||
|
|
|
@ -33,7 +33,7 @@ async function run() {
|
|||
|
||||
if (restoreKey !== key) {
|
||||
// pre-clean the target directory on cache mismatch
|
||||
const packages = await getPackages();
|
||||
const packages = await getPackages(workspaces);
|
||||
|
||||
for (const workspace of workspaces) {
|
||||
const target = path.join(workspace, "target");
|
||||
|
|
|
@ -35,7 +35,7 @@ async function run() {
|
|||
await macOsWorkaround();
|
||||
|
||||
const registryName = await getRegistryName();
|
||||
const packages = await getPackages();
|
||||
const packages = await getPackages(workspaces);
|
||||
|
||||
if (registryName) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue