Skip to content

Commit 607e851

Browse files
committed
Switch bootstrap metadata to --no-deps.
This should run much faster. There are also some drive-by cleanups here to try to simplify things. Also, the paths for in-tree crates are now displayed as relative in `x.py test -h -v`.
1 parent 0687b78 commit 607e851

File tree

5 files changed

+37
-77
lines changed

5 files changed

+37
-77
lines changed

src/bootstrap/builder.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,17 @@ impl<'a> ShouldRun<'a> {
255255
pub fn all_krates(mut self, name: &str) -> Self {
256256
let mut set = BTreeSet::new();
257257
for krate in self.builder.in_tree_crates(name) {
258-
set.insert(PathBuf::from(&krate.path));
258+
let path = krate.local_path(self.builder);
259+
set.insert(path);
259260
}
260261
self.paths.insert(PathSet::Set(set));
261262
self
262263
}
263264

264265
pub fn krate(mut self, name: &str) -> Self {
265266
for krate in self.builder.in_tree_crates(name) {
266-
self.paths.insert(PathSet::one(&krate.path));
267+
let path = krate.local_path(self.builder);
268+
self.paths.insert(PathSet::one(path));
267269
}
268270
self
269271
}

src/bootstrap/doc.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ impl Step for Rustc {
548548
// Find dependencies for top level crates.
549549
let mut compiler_crates = HashSet::new();
550550
for root_crate in &["rustc_driver", "rustc_codegen_llvm", "rustc_codegen_ssa"] {
551-
let interned_root_crate = INTERNER.intern_str(root_crate);
552-
find_compiler_crates(builder, &interned_root_crate, &mut compiler_crates);
551+
compiler_crates
552+
.extend(builder.in_tree_crates(root_crate).into_iter().map(|krate| krate.name));
553553
}
554554

555555
for krate in &compiler_crates {
@@ -564,22 +564,6 @@ impl Step for Rustc {
564564
}
565565
}
566566

567-
fn find_compiler_crates(
568-
builder: &Builder<'_>,
569-
name: &Interned<String>,
570-
crates: &mut HashSet<Interned<String>>,
571-
) {
572-
// Add current crate.
573-
crates.insert(*name);
574-
575-
// Look for dependencies.
576-
for dep in builder.crates.get(name).unwrap().deps.iter() {
577-
if builder.crates.get(dep).unwrap().is_local(builder) {
578-
find_compiler_crates(builder, dep, crates);
579-
}
580-
}
581-
}
582-
583567
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
584568
pub struct Rustdoc {
585569
stage: u32,

src/bootstrap/lib.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,7 @@ struct Crate {
270270
}
271271

272272
impl Crate {
273-
fn is_local(&self, build: &Build) -> bool {
274-
self.path.starts_with(&build.config.src)
275-
}
276-
277273
fn local_path(&self, build: &Build) -> PathBuf {
278-
assert!(self.is_local(build));
279274
self.path.strip_prefix(&build.config.src).unwrap().into()
280275
}
281276
}
@@ -1079,17 +1074,29 @@ impl Build {
10791074
}
10801075
}
10811076

1077+
/// Returns a Vec of all the dependencies of the given root crate,
1078+
/// including transitive dependencies and the root itself. Only includes
1079+
/// "local" crates (those in the local source tree, not from a registry).
10821080
fn in_tree_crates(&self, root: &str) -> Vec<&Crate> {
10831081
let mut ret = Vec::new();
10841082
let mut list = vec![INTERNER.intern_str(root)];
10851083
let mut visited = HashSet::new();
10861084
while let Some(krate) = list.pop() {
10871085
let krate = &self.crates[&krate];
1088-
if krate.is_local(self) {
1089-
ret.push(krate);
1090-
}
1086+
ret.push(krate);
10911087
for dep in &krate.deps {
1092-
if visited.insert(dep) && dep != "build_helper" {
1088+
// Don't include optional deps if their features are not
1089+
// enabled. Ideally this would be computed from `cargo
1090+
// metadata --features …`, but that is somewhat slow. Just
1091+
// skip `build_helper` since there aren't any operations we
1092+
// want to perform on it. In the future, we may want to
1093+
// consider just filtering all build and dev dependencies in
1094+
// metadata::build.
1095+
if visited.insert(dep)
1096+
&& dep != "build_helper"
1097+
&& (dep != "profiler_builtins" || self.config.profiler)
1098+
&& (dep != "rustc_codegen_llvm" || self.config.llvm_enabled())
1099+
{
10931100
list.push(*dep);
10941101
}
10951102
}

src/bootstrap/metadata.rs

+13-42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
use std::collections::HashSet;
31
use std::path::PathBuf;
42
use std::process::Command;
53

@@ -12,7 +10,6 @@ use crate::{Build, Crate};
1210
#[derive(Deserialize)]
1311
struct Output {
1412
packages: Vec<Package>,
15-
resolve: Resolve,
1613
}
1714

1815
#[derive(Deserialize)]
@@ -21,65 +18,39 @@ struct Package {
2118
name: String,
2219
source: Option<String>,
2320
manifest_path: String,
21+
dependencies: Vec<Dependency>,
2422
}
2523

2624
#[derive(Deserialize)]
27-
struct Resolve {
28-
nodes: Vec<ResolveNode>,
29-
}
30-
31-
#[derive(Deserialize)]
32-
struct ResolveNode {
33-
id: String,
34-
dependencies: Vec<String>,
25+
struct Dependency {
26+
name: String,
27+
source: Option<String>,
3528
}
3629

3730
pub fn build(build: &mut Build) {
3831
// Run `cargo metadata` to figure out what crates we're testing.
39-
let features: Vec<_> = build
40-
.std_features()
41-
.split_whitespace()
42-
.map(|f| format!("test/{}", f))
43-
.chain(build.rustc_features().split_whitespace().map(|f| format!("rustc-main/{}", f)))
44-
.collect();
4532
let mut cargo = Command::new(&build.initial_cargo);
4633
cargo
4734
.arg("metadata")
4835
.arg("--format-version")
4936
.arg("1")
50-
.arg("--features")
51-
.arg(features.join(","))
52-
.arg("-Zpackage-features")
37+
.arg("--no-deps")
5338
.arg("--manifest-path")
54-
.arg(build.src.join("Cargo.toml"))
55-
.env("RUSTC_BOOTSTRAP", "1");
39+
.arg(build.src.join("Cargo.toml"));
5640
let output = output(&mut cargo);
5741
let output: Output = serde_json::from_str(&output).unwrap();
5842
for package in output.packages {
5943
if package.source.is_none() {
6044
let name = INTERNER.intern_string(package.name);
6145
let mut path = PathBuf::from(package.manifest_path);
6246
path.pop();
63-
build.crates.insert(name, Crate { name, id: package.id, deps: HashSet::new(), path });
64-
}
65-
}
66-
67-
let id2name: HashMap<_, _> =
68-
build.crates.iter().map(|(name, krate)| (krate.id.clone(), name.clone())).collect();
69-
70-
for node in output.resolve.nodes {
71-
let name = match id2name.get(&node.id) {
72-
Some(name) => name,
73-
None => continue,
74-
};
75-
76-
let krate = build.crates.get_mut(name).unwrap();
77-
for dep in node.dependencies.iter() {
78-
let dep = match id2name.get(dep) {
79-
Some(dep) => dep,
80-
None => continue,
81-
};
82-
krate.deps.insert(*dep);
47+
let deps = package
48+
.dependencies
49+
.into_iter()
50+
.filter(|dep| dep.source.is_none())
51+
.map(|dep| INTERNER.intern_string(dep.name))
52+
.collect();
53+
build.crates.insert(name, Crate { name, id: package.id, deps, path });
8354
}
8455
}
8556
}

src/bootstrap/test.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1651,12 +1651,8 @@ impl Step for Crate {
16511651
type Output = ();
16521652
const DEFAULT: bool = true;
16531653

1654-
fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
1655-
let builder = run.builder;
1656-
for krate in run.builder.in_tree_crates("test") {
1657-
run = run.path(krate.local_path(&builder).to_str().unwrap());
1658-
}
1659-
run
1654+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1655+
run.krate("test")
16601656
}
16611657

16621658
fn make_run(run: RunConfig<'_>) {

0 commit comments

Comments
 (0)