| 197 | |
| 198 | /// Get the workspace's full list of member crates. |
| 199 | async function getWorkspaceMembers() { |
| 200 | // Spawn a `cargo metadata` subprocess, accumulate its JSON output from |
| 201 | // `stdout`, and wait for it to exit. |
| 202 | const child = spawn("cargo", ["metadata"], { encoding: "utf8" }); |
| 203 | let data = ""; |
| 204 | child.stdout.on("data", chunk => data += chunk); |
| 205 | await new Promise((resolve, reject) => { |
| 206 | child.on("close", resolve); |
| 207 | child.on("error", reject); |
| 208 | }); |
| 209 | |
| 210 | // Get the names of the crates in the workspace from the JSON metadata by |
| 211 | // building a package-id to name map and then translating the package-ids |
| 212 | // listed as workspace members. |
| 213 | const metadata = JSON.parse(data); |
| 214 | const id_to_name = {}; |
| 215 | for (const pkg of metadata.packages) { |
| 216 | id_to_name[pkg.id] = pkg.name; |
| 217 | } |
| 218 | return metadata.workspace_members.map(m => id_to_name[m]); |
| 219 | } |
| 220 | |
| 221 | /// For each given target configuration, shard the workspace's crates into |
| 222 | /// buckets across that config. |