]> git.proxmox.com Git - rustc.git/blame - src/bootstrap/metadata.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / bootstrap / metadata.rs
CommitLineData
dfeec247
XL
1use std::path::PathBuf;
2use std::process::Command;
c30ab7b3 3
48663c56 4use serde::Deserialize;
c30ab7b3 5
0731742a 6use crate::cache::INTERNER;
5e7ed085 7use crate::util::output;
dfeec247 8use crate::{Build, Crate};
c30ab7b3 9
3b2f2976 10#[derive(Deserialize)]
c30ab7b3
SL
11struct Output {
12 packages: Vec<Package>,
c30ab7b3
SL
13}
14
3b2f2976 15#[derive(Deserialize)]
c30ab7b3 16struct Package {
c30ab7b3
SL
17 name: String,
18 source: Option<String>,
19 manifest_path: String,
f035d41b 20 dependencies: Vec<Dependency>,
c30ab7b3
SL
21}
22
3b2f2976 23#[derive(Deserialize)]
f035d41b
XL
24struct Dependency {
25 name: String,
26 source: Option<String>,
c30ab7b3
SL
27}
28
29pub fn build(build: &mut Build) {
c30ab7b3 30 // Run `cargo metadata` to figure out what crates we're testing.
041b39d2 31 let mut cargo = Command::new(&build.initial_cargo);
dfeec247
XL
32 cargo
33 .arg("metadata")
34 .arg("--format-version")
35 .arg("1")
f035d41b 36 .arg("--no-deps")
dfeec247 37 .arg("--manifest-path")
f035d41b 38 .arg(build.src.join("Cargo.toml"));
c30ab7b3 39 let output = output(&mut cargo);
3b2f2976 40 let output: Output = serde_json::from_str(&output).unwrap();
c30ab7b3
SL
41 for package in output.packages {
42 if package.source.is_none() {
3b2f2976 43 let name = INTERNER.intern_string(package.name);
c30ab7b3
SL
44 let mut path = PathBuf::from(package.manifest_path);
45 path.pop();
f035d41b
XL
46 let deps = package
47 .dependencies
48 .into_iter()
49 .filter(|dep| dep.source.is_none())
50 .map(|dep| INTERNER.intern_string(dep.name))
51 .collect();
04454e1e
FG
52 let krate = Crate { name, deps, path };
53 let relative_path = krate.local_path(build);
54 build.crates.insert(name, krate);
55 let existing_path = build.crate_paths.insert(relative_path, name);
56 assert!(existing_path.is_none(), "multiple crates with the same path");
c30ab7b3
SL
57 }
58 }
c30ab7b3 59}