mirror of
https://github.com/Swatinem/rust-cache
synced 2025-08-12 00:00:55 +00:00
prepare v2
This commit is contained in:
parent
0497f9301f
commit
622616010e
12 changed files with 106 additions and 65 deletions
|
@ -31,8 +31,8 @@ export async function cleanTargetDir(targetDir: string, packages: Packages) {
|
|||
}
|
||||
|
||||
async function cleanProfileTarget(profileDir: string, packages: Packages) {
|
||||
await io.rmRF(path.join(profileDir, "examples"));
|
||||
await io.rmRF(path.join(profileDir, "incremental"));
|
||||
await rmRF(path.join(profileDir, "examples"));
|
||||
await rmRF(path.join(profileDir, "incremental"));
|
||||
|
||||
let dir: fs.Dir;
|
||||
// remove all *files* from the profile directory
|
||||
|
@ -94,8 +94,7 @@ export async function cleanBin() {
|
|||
export async function cleanRegistry(packages: Packages) {
|
||||
// `.cargo/registry/src`
|
||||
// we can remove this completely, as cargo will recreate this from `cache`
|
||||
const srcDir = path.join(CARGO_HOME, "registry", "src");
|
||||
await io.rmRF(srcDir);
|
||||
await rmRF(path.join(CARGO_HOME, "registry", "src"));
|
||||
|
||||
// `.cargo/registry/index`
|
||||
const indexDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "index"));
|
||||
|
@ -107,7 +106,7 @@ export async function cleanRegistry(packages: Packages) {
|
|||
|
||||
// for a git registry, we can remove `.cache`, as cargo will recreate it from git
|
||||
if (await exists(path.join(dir.path, ".git"))) {
|
||||
await io.rmRF(path.join(dir.path, ".cache"));
|
||||
await rmRF(path.join(dir.path, ".cache"));
|
||||
}
|
||||
// TODO: else, clean `.cache` based on the `packages`
|
||||
}
|
||||
|
@ -183,7 +182,7 @@ export async function cleanGit(packages: Packages) {
|
|||
|
||||
const ONE_WEEK = 7 * 24 * 3600 * 1000;
|
||||
|
||||
export async function rmExcept(dirName: string, keepPrefix: Set<string>) {
|
||||
async function rmExcept(dirName: string, keepPrefix: Set<string>) {
|
||||
const dir = await fs.promises.opendir(dirName);
|
||||
for await (const dirent of dir) {
|
||||
let name = dirent.name;
|
||||
|
@ -200,7 +199,7 @@ export async function rmExcept(dirName: string, keepPrefix: Set<string>) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function rm(parent: string, dirent: fs.Dirent) {
|
||||
async function rm(parent: string, dirent: fs.Dirent) {
|
||||
try {
|
||||
const fileName = path.join(parent, dirent.name);
|
||||
core.debug(`deleting "${fileName}"`);
|
||||
|
@ -212,6 +211,11 @@ export async function rm(parent: string, dirent: fs.Dirent) {
|
|||
} catch {}
|
||||
}
|
||||
|
||||
async function rmRF(dirName: string) {
|
||||
core.debug(`deleting "${dirName}"`);
|
||||
await io.rmRF(dirName);
|
||||
}
|
||||
|
||||
async function exists(path: string) {
|
||||
try {
|
||||
await fs.promises.access(path);
|
||||
|
|
|
@ -47,12 +47,12 @@ export class CacheConfig {
|
|||
const self = new CacheConfig();
|
||||
|
||||
// Construct key prefix:
|
||||
// This uses either the `sharedKey` input,
|
||||
// This uses either the `shared-key` input,
|
||||
// or the `key` input combined with the `job` key.
|
||||
|
||||
let key = `v0-rust`;
|
||||
|
||||
const sharedKey = core.getInput("sharedKey");
|
||||
const sharedKey = core.getInput("shared-key");
|
||||
if (sharedKey) {
|
||||
key += `-${sharedKey}`;
|
||||
} else {
|
||||
|
@ -72,7 +72,7 @@ export class CacheConfig {
|
|||
// Construct environment portion of the key:
|
||||
// This consists of a hash that considers the rust version
|
||||
// as well as all the environment variables as given by a default list
|
||||
// and the `envVars` input.
|
||||
// and the `env-vars` input.
|
||||
// The env vars are sorted, matched by prefix and hashed into the
|
||||
// resulting environment hash.
|
||||
|
||||
|
@ -87,8 +87,8 @@ export class CacheConfig {
|
|||
self.keyRust = keyRust;
|
||||
|
||||
// these prefixes should cover most of the compiler / rust / cargo keys
|
||||
const envPrefixes = ["CARGO", "CC", "CXX", "CMAKE", "RUST"];
|
||||
envPrefixes.push(...core.getInput("envVars").split(/\s+/).filter(Boolean));
|
||||
const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"];
|
||||
envPrefixes.push(...core.getInput("env-vars").split(/\s+/).filter(Boolean));
|
||||
|
||||
// sort the available env vars so we have a more stable hash
|
||||
const keyEnvs = [];
|
||||
|
@ -147,7 +147,7 @@ export class CacheConfig {
|
|||
const workspaces: Array<Workspace> = [];
|
||||
const workspacesInput = core.getInput("workspaces") || ".";
|
||||
for (const workspace of workspacesInput.trim().split("\n")) {
|
||||
let [root, target = "target"] = workspace.split(" -> ");
|
||||
let [root, target = "target"] = workspace.split("->").map((s) => s.trim());
|
||||
root = path.resolve(root);
|
||||
target = path.join(root, target);
|
||||
workspaces.push(new Workspace(root, target));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue