]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/metadata.rs
Auto merge of #107000 - GuillaumeGomez:fix-items-in-doc-hidden-block, r=notriddle...
[rust.git] / src / bootstrap / metadata.rs
1 use std::path::PathBuf;
2 use std::process::Command;
3
4 use serde::Deserialize;
5
6 use crate::cache::INTERNER;
7 use crate::util::output;
8 use crate::{Build, Crate};
9
10 #[derive(Deserialize)]
11 struct Output {
12     packages: Vec<Package>,
13 }
14
15 #[derive(Deserialize)]
16 struct Package {
17     name: String,
18     source: Option<String>,
19     manifest_path: String,
20     dependencies: Vec<Dependency>,
21 }
22
23 #[derive(Deserialize)]
24 struct Dependency {
25     name: String,
26     source: Option<String>,
27 }
28
29 pub fn build(build: &mut Build) {
30     // Run `cargo metadata` to figure out what crates we're testing.
31     let mut cargo = Command::new(&build.initial_cargo);
32     cargo
33         .arg("metadata")
34         .arg("--format-version")
35         .arg("1")
36         .arg("--no-deps")
37         .arg("--manifest-path")
38         .arg(build.src.join("Cargo.toml"));
39     let output = output(&mut cargo);
40     let output: Output = serde_json::from_str(&output).unwrap();
41     for package in output.packages {
42         if package.source.is_none() {
43             let name = INTERNER.intern_string(package.name);
44             let mut path = PathBuf::from(package.manifest_path);
45             path.pop();
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();
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");
57         }
58     }
59 }