3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-06-22 16:23:42 +00:00

update registry cleaning

This commit is contained in:
Arpad Borsos 2022-07-09 18:51:34 +02:00
parent 911d8e9e55
commit 7b8626742a
No known key found for this signature in database
GPG key ID: FC7BCA77824B3298
7 changed files with 188 additions and 212 deletions

View file

@ -8,6 +8,9 @@ import path from "path";
import { getCmdOutput } from "./utils";
import { Workspace } from "./workspace";
const HOME = os.homedir();
export const CARGO_HOME = process.env.CARGO_HOME || path.join(HOME, ".cargo");
const STATE_LOCKFILE_HASH = "RUST_CACHE_LOCKFILE_HASH";
const STATE_LOCKFILES = "RUST_CACHE_LOCKFILES";
export const STATE_BINS = "RUST_CACHE_BINS";
@ -21,14 +24,6 @@ export class CacheConfig {
/** The secondary (restore) key that only contains the prefix and environment */
public restoreKey = "";
/** The `~/.cargo` directory */
public cargoHome = "";
/** The cargo registry index directory */
public cargoIndex = "";
/** The cargo registry cache directory */
public cargoCache = "";
/** The cargo git checkouts directory */
public cargoGit = "";
/** The workspace configurations */
public workspaces: Array<Workspace> = [];
@ -146,16 +141,9 @@ export class CacheConfig {
key += `-${lockHash}`;
self.cacheKey = key;
// Constructs some generic paths, workspace config and paths to restore:
// Constructs the workspace config and paths to restore:
// The workspaces are given using a `$workspace -> $target` syntax.
const home = os.homedir();
const cargoHome = process.env.CARGO_HOME || path.join(home, ".cargo");
self.cargoHome = cargoHome;
self.cargoIndex = path.join(cargoHome, "registry/index");
self.cargoCache = path.join(cargoHome, "registry/cache");
self.cargoGit = path.join(cargoHome, "git");
const workspaces: Array<Workspace> = [];
const workspacesInput = core.getInput("workspaces") || ".";
for (const workspace of workspacesInput.trim().split("\n")) {
@ -166,15 +154,7 @@ export class CacheConfig {
}
self.workspaces = workspaces;
self.cachePaths = [
path.join(cargoHome, "bin"),
path.join(cargoHome, ".crates2.json"),
path.join(cargoHome, ".crates.toml"),
self.cargoIndex,
self.cargoCache,
self.cargoGit,
...workspaces.map((ws) => ws.target),
];
self.cachePaths = [CARGO_HOME, ...workspaces.map((ws) => ws.target)];
return self;
}
@ -206,21 +186,6 @@ export class CacheConfig {
}
core.endGroup();
}
public async getCargoBins(): Promise<Set<string>> {
const bins = new Set<string>();
try {
const { installs }: { installs: { [key: string]: { bins: Array<string> } } } = JSON.parse(
await fs.promises.readFile(path.join(this.cargoHome, ".crates2.json"), "utf8"),
);
for (const pkg of Object.values(installs)) {
for (const bin of pkg.bins) {
bins.add(bin);
}
}
} catch {}
return bins;
}
}
interface RustVersion {