(cmdFormat: string, filter: (p: Meta["packages"][0]) => boolean, extraArgs?: string)
| 9 | constructor(public root: string, public target: string) {} |
| 10 | |
| 11 | async getPackages(cmdFormat: string, filter: (p: Meta["packages"][0]) => boolean, extraArgs?: string): Promise<Packages> { |
| 12 | const cmd = "cargo metadata --all-features --format-version 1" + (extraArgs ? ` ${extraArgs}` : ""); |
| 13 | let packages: Packages = []; |
| 14 | try { |
| 15 | core.debug(`collecting metadata for "${this.root}"`); |
| 16 | const meta: Meta = JSON.parse( |
| 17 | await getCmdOutput(cmdFormat, cmd, { |
| 18 | cwd: this.root, |
| 19 | env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" }, |
| 20 | }), |
| 21 | ); |
| 22 | core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`); |
| 23 | for (const pkg of meta.packages.filter(filter)) { |
| 24 | const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name); |
| 25 | packages.push({ name: pkg.name, version: pkg.version, targets, path: path.dirname(pkg.manifest_path) }); |
| 26 | } |
| 27 | } catch (err) { |
| 28 | console.error(err); |
| 29 | } |
| 30 | return packages; |
| 31 | } |
| 32 | |
| 33 | public async getPackagesOutsideWorkspaceRoot(cmdFormat: string): Promise<Packages> { |
| 34 | return await this.getPackages(cmdFormat, (pkg) => !pkg.manifest_path.startsWith(this.root)); |
no test coverage detected