Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
max-heller committed Nov 25, 2023
1 parent 7b1d730 commit 86473ee
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
20 changes: 13 additions & 7 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87018,25 +87018,30 @@ class Workspace {
this.root = root;
this.target = target;
}
async getPackages(...extraArgs) {
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", ...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
Expand Down Expand Up @@ -87152,8 +87157,9 @@ 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 workspaceMembers = await workspace.getPackages("--no-deps");
const workspaceMembers = await workspace.getWorkspaceMembers();
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => external_path_default().join(member.path, "Cargo.toml")));
console.log(cargo_manifests);
for (const cargo_manifest of cargo_manifests) {
try {
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
Expand Down
22 changes: 14 additions & 8 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87018,25 +87018,30 @@ class Workspace {
this.root = root;
this.target = target;
}
async getPackages(...extraArgs) {
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", ...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
Expand Down Expand Up @@ -87152,8 +87157,9 @@ 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 workspaceMembers = await workspace.getPackages("--no-deps");
const workspaceMembers = await workspace.getWorkspaceMembers();
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => external_path_default().join(member.path, "Cargo.toml")));
console.log(cargo_manifests);
for (const cargo_manifest of cargo_manifests) {
try {
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
Expand Down Expand Up @@ -87681,7 +87687,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} ...`);
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ export class CacheConfig {
)),
);

const workspaceMembers = await workspace.getPackages("--no-deps");
const workspaceMembers = await workspace.getWorkspaceMembers();

const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => path.join(member.path, "Cargo.toml")));
console.log(cargo_manifests);

for (const cargo_manifest of cargo_manifests) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} ...`);
Expand Down
19 changes: 13 additions & 6 deletions src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
export class Workspace {
constructor(public root: string, public target: string) {}

public async getPackages(...extraArgs: string[]): 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}"`);
Expand All @@ -18,16 +18,23 @@ export class Workspace {
}),
);
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 {
Expand Down

0 comments on commit 86473ee

Please sign in to comment.