Skip to content

Commit

Permalink
lol, dependency check was reversed
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Jul 9, 2022
1 parent 7c190ef commit 07a2ee7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 53 deletions.
23 changes: 7 additions & 16 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61646,7 +61646,7 @@ class Workspace {
cwd: this.root,
}));
for (const pkg of meta.packages) {
if (!pkg.manifest_path.startsWith(this.root)) {
if (pkg.manifest_path.startsWith(this.root)) {
continue;
}
const targets = pkg.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
Expand Down Expand Up @@ -61875,7 +61875,7 @@ async function cleanTargetDir(targetDir, packages) {
if (dirent.isDirectory()) {
let dirName = external_path_default().join(dir.path, dirent.name);
// is it a profile dir, or a nested target dir?
let isNestedTarget = await exists(external_path_default().join(dirName, "CACHEDIR.TAG"));
let isNestedTarget = (await exists(external_path_default().join(dirName, "CACHEDIR.TAG"))) || (await exists(external_path_default().join(dirName, ".rustc_info.json")));
try {
if (isNestedTarget) {
await cleanTargetDir(dirName, packages);
Expand All @@ -61891,19 +61891,10 @@ async function cleanTargetDir(targetDir, packages) {
}
}
await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json"));
// TODO: remove all unknown files, clean all directories like profiles
try {
await cleanProfileTarget(external_path_default().join(targetDir, "debug"), packages);
}
catch { }
try {
await cleanProfileTarget(external_path_default().join(targetDir, "release"), packages);
}
catch { }
}
async function cleanProfileTarget(profileDir, packages) {
await lib_io.rmRF(external_path_default().join(profileDir, "./examples"));
await lib_io.rmRF(external_path_default().join(profileDir, "./incremental"));
await lib_io.rmRF(external_path_default().join(profileDir, "examples"));
await lib_io.rmRF(external_path_default().join(profileDir, "incremental"));
let dir;
// remove all *files* from the profile directory
dir = await external_fs_default().promises.opendir(profileDir);
Expand All @@ -61913,8 +61904,8 @@ async function cleanProfileTarget(profileDir, packages) {
}
}
const keepPkg = new Set(packages.map((p) => p.name));
await rmExcept(external_path_default().join(profileDir, "./build"), keepPkg);
await rmExcept(external_path_default().join(profileDir, "./.fingerprint"), keepPkg);
await rmExcept(external_path_default().join(profileDir, "build"), keepPkg);
await rmExcept(external_path_default().join(profileDir, ".fingerprint"), keepPkg);
const keepDeps = new Set(packages.flatMap((p) => {
const names = [];
for (const n of [p.name, ...p.targets]) {
Expand All @@ -61923,7 +61914,7 @@ async function cleanProfileTarget(profileDir, packages) {
}
return names;
}));
await rmExcept(external_path_default().join(profileDir, "./deps"), keepDeps);
await rmExcept(external_path_default().join(profileDir, "deps"), keepDeps);
}
async function cleanBin(config) {
const bins = await config.getCargoBins();
Expand Down
30 changes: 12 additions & 18 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61646,7 +61646,7 @@ class Workspace {
cwd: this.root,
}));
for (const pkg of meta.packages) {
if (!pkg.manifest_path.startsWith(this.root)) {
if (pkg.manifest_path.startsWith(this.root)) {
continue;
}
const targets = pkg.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
Expand Down Expand Up @@ -61875,7 +61875,7 @@ async function cleanTargetDir(targetDir, packages) {
if (dirent.isDirectory()) {
let dirName = external_path_default().join(dir.path, dirent.name);
// is it a profile dir, or a nested target dir?
let isNestedTarget = await exists(external_path_default().join(dirName, "CACHEDIR.TAG"));
let isNestedTarget = (await exists(external_path_default().join(dirName, "CACHEDIR.TAG"))) || (await exists(external_path_default().join(dirName, ".rustc_info.json")));
try {
if (isNestedTarget) {
await cleanTargetDir(dirName, packages);
Expand All @@ -61891,19 +61891,10 @@ async function cleanTargetDir(targetDir, packages) {
}
}
await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json"));
// TODO: remove all unknown files, clean all directories like profiles
try {
await cleanProfileTarget(external_path_default().join(targetDir, "debug"), packages);
}
catch { }
try {
await cleanProfileTarget(external_path_default().join(targetDir, "release"), packages);
}
catch { }
}
async function cleanProfileTarget(profileDir, packages) {
await io.rmRF(external_path_default().join(profileDir, "./examples"));
await io.rmRF(external_path_default().join(profileDir, "./incremental"));
await io.rmRF(external_path_default().join(profileDir, "examples"));
await io.rmRF(external_path_default().join(profileDir, "incremental"));
let dir;
// remove all *files* from the profile directory
dir = await external_fs_default().promises.opendir(profileDir);
Expand All @@ -61913,8 +61904,8 @@ async function cleanProfileTarget(profileDir, packages) {
}
}
const keepPkg = new Set(packages.map((p) => p.name));
await rmExcept(external_path_default().join(profileDir, "./build"), keepPkg);
await rmExcept(external_path_default().join(profileDir, "./.fingerprint"), keepPkg);
await rmExcept(external_path_default().join(profileDir, "build"), keepPkg);
await rmExcept(external_path_default().join(profileDir, ".fingerprint"), keepPkg);
const keepDeps = new Set(packages.flatMap((p) => {
const names = [];
for (const n of [p.name, ...p.targets]) {
Expand All @@ -61923,7 +61914,7 @@ async function cleanProfileTarget(profileDir, packages) {
}
return names;
}));
await rmExcept(external_path_default().join(profileDir, "./deps"), keepDeps);
await rmExcept(external_path_default().join(profileDir, "deps"), keepDeps);
}
async function cleanBin(config) {
const bins = await config.getCargoBins();
Expand Down Expand Up @@ -62062,34 +62053,37 @@ async function run() {
}
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
await macOsWorkaround();
core.info(`... Cleaning Cache ...`);
const registryName = await getRegistryName(config);
const allPackages = [];
for (const workspace of config.workspaces) {
const packages = await workspace.getPackages();
allPackages.push(...packages);
try {
core.info(`... Cleaning ${workspace.target} ...`);
await cleanTargetDir(workspace.target, packages);
}
catch (e) {
core.info(`[warning] ${e.stack}`);
}
}
const registryName = await getRegistryName(config);
if (registryName) {
try {
core.info(`... Cleaning cargo registry ...`);
await cleanRegistry(config, registryName, allPackages);
}
catch (e) {
core.info(`[warning] ${e.stack}`);
}
}
try {
core.info(`... Cleaning cargo/bin ...`);
await cleanBin(config);
}
catch (e) {
core.info(`[warning] ${e.stack}`);
}
try {
core.info(`... Cleaning cargo git cache ...`);
await cleanGit(config, allPackages);
}
catch (e) {
Expand Down
21 changes: 7 additions & 14 deletions src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export async function cleanTargetDir(targetDir: string, packages: Packages) {
if (dirent.isDirectory()) {
let dirName = path.join(dir.path, dirent.name);
// is it a profile dir, or a nested target dir?
let isNestedTarget = await exists(path.join(dirName, "CACHEDIR.TAG"));
let isNestedTarget =
(await exists(path.join(dirName, "CACHEDIR.TAG"))) || (await exists(path.join(dirName, ".rustc_info.json")));

try {
if (isNestedTarget) {
Expand All @@ -29,19 +30,11 @@ export async function cleanTargetDir(targetDir: string, packages: Packages) {
}

await fs.promises.unlink(path.join(targetDir, "./.rustc_info.json"));

// TODO: remove all unknown files, clean all directories like profiles
try {
await cleanProfileTarget(path.join(targetDir, "debug"), packages);
} catch {}
try {
await cleanProfileTarget(path.join(targetDir, "release"), packages);
} catch {}
}

async function cleanProfileTarget(profileDir: string, packages: Packages) {
await io.rmRF(path.join(profileDir, "./examples"));
await io.rmRF(path.join(profileDir, "./incremental"));
await io.rmRF(path.join(profileDir, "examples"));
await io.rmRF(path.join(profileDir, "incremental"));

let dir: fs.Dir;
// remove all *files* from the profile directory
Expand All @@ -53,8 +46,8 @@ async function cleanProfileTarget(profileDir: string, packages: Packages) {
}

const keepPkg = new Set(packages.map((p) => p.name));
await rmExcept(path.join(profileDir, "./build"), keepPkg);
await rmExcept(path.join(profileDir, "./.fingerprint"), keepPkg);
await rmExcept(path.join(profileDir, "build"), keepPkg);
await rmExcept(path.join(profileDir, ".fingerprint"), keepPkg);

const keepDeps = new Set(
packages.flatMap((p) => {
Expand All @@ -66,7 +59,7 @@ async function cleanProfileTarget(profileDir: string, packages: Packages) {
return names;
}),
);
await rmExcept(path.join(profileDir, "./deps"), keepDeps);
await rmExcept(path.join(profileDir, "deps"), keepDeps);
}

export async function cleanBin(config: CacheConfig) {
Expand Down
9 changes: 5 additions & 4 deletions src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,37 @@ async function run() {
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
await macOsWorkaround();

core.info(`... Cleaning Cache ...`);

const registryName = await getRegistryName(config);

const allPackages = [];
for (const workspace of config.workspaces) {
const packages = await workspace.getPackages();
allPackages.push(...packages);
try {
core.info(`... Cleaning ${workspace.target} ...`);
await cleanTargetDir(workspace.target, packages);
} catch (e) {
core.info(`[warning] ${(e as any).stack}`);
}
}

const registryName = await getRegistryName(config);
if (registryName) {
try {
core.info(`... Cleaning cargo registry ...`);
await cleanRegistry(config, registryName, allPackages);
} catch (e) {
core.info(`[warning] ${(e as any).stack}`);
}
}

try {
core.info(`... Cleaning cargo/bin ...`);
await cleanBin(config);
} catch (e) {
core.info(`[warning] ${(e as any).stack}`);
}

try {
core.info(`... Cleaning cargo git cache ...`);
await cleanGit(config, allPackages);
} catch (e) {
core.info(`[warning] ${(e as any).stack}`);
Expand Down
2 changes: 1 addition & 1 deletion src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Workspace {
}),
);
for (const pkg of meta.packages) {
if (!pkg.manifest_path.startsWith(this.root)) {
if (pkg.manifest_path.startsWith(this.root)) {
continue;
}
const targets = pkg.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
Expand Down

0 comments on commit 07a2ee7

Please sign in to comment.