Skip to content

Commit 0687b78

Browse files
committed
Speed up bootstrap a little.
1 parent f4fbb93 commit 0687b78

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

src/bootstrap/flags.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ use std::process;
1010
use getopts::Options;
1111

1212
use crate::builder::Builder;
13+
use crate::cache::{Interned, INTERNER};
1314
use crate::config::Config;
14-
use crate::metadata;
1515
use crate::{Build, DocTests};
1616

17-
use crate::cache::{Interned, INTERNER};
18-
1917
/// Deserialized version of all flags for this compile.
2018
pub struct Flags {
2119
pub verbose: usize, // number of -v args; each extra -v after the first is passed to Cargo
@@ -444,8 +442,7 @@ Arguments:
444442
// All subcommands except `clean` can have an optional "Available paths" section
445443
if matches.opt_present("verbose") {
446444
let config = Config::parse(&["build".to_string()]);
447-
let mut build = Build::new(config);
448-
metadata::build(&mut build);
445+
let build = Build::new(config);
449446

450447
let maybe_rules_help = Builder::get_help(&build, subcommand.as_str());
451448
extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str());

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ struct Crate {
271271

272272
impl Crate {
273273
fn is_local(&self, build: &Build) -> bool {
274-
self.path.starts_with(&build.config.src) && !self.path.to_string_lossy().ends_with("_shim")
274+
self.path.starts_with(&build.config.src)
275275
}
276276

277277
fn local_path(&self, build: &Build) -> PathBuf {

src/bootstrap/metadata.rs

+29-36
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,24 @@ struct ResolveNode {
3535
}
3636

3737
pub fn build(build: &mut Build) {
38-
let mut resolves = Vec::new();
39-
build_krate(&build.std_features(), build, &mut resolves, "src/libstd");
40-
build_krate("", build, &mut resolves, "src/libtest");
41-
build_krate(&build.rustc_features(), build, &mut resolves, "src/rustc");
42-
43-
let mut id2name = HashMap::with_capacity(build.crates.len());
44-
for (name, krate) in build.crates.iter() {
45-
id2name.insert(krate.id.clone(), name.clone());
46-
}
47-
48-
for node in resolves {
49-
let name = match id2name.get(&node.id) {
50-
Some(name) => name,
51-
None => continue,
52-
};
53-
54-
let krate = build.crates.get_mut(name).unwrap();
55-
for dep in node.dependencies.iter() {
56-
let dep = match id2name.get(dep) {
57-
Some(dep) => dep,
58-
None => continue,
59-
};
60-
krate.deps.insert(*dep);
61-
}
62-
}
63-
}
64-
65-
fn build_krate(features: &str, build: &mut Build, resolves: &mut Vec<ResolveNode>, krate: &str) {
6638
// Run `cargo metadata` to figure out what crates we're testing.
67-
//
68-
// Down below we're going to call `cargo test`, but to test the right set
69-
// of packages we're going to have to know what `-p` arguments to pass it
70-
// to know what crates to test. Here we run `cargo metadata` to learn about
71-
// the dependency graph and what `-p` arguments there are.
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();
7245
let mut cargo = Command::new(&build.initial_cargo);
7346
cargo
7447
.arg("metadata")
7548
.arg("--format-version")
7649
.arg("1")
7750
.arg("--features")
78-
.arg(features)
51+
.arg(features.join(","))
52+
.arg("-Zpackage-features")
7953
.arg("--manifest-path")
80-
.arg(build.src.join(krate).join("Cargo.toml"));
54+
.arg(build.src.join("Cargo.toml"))
55+
.env("RUSTC_BOOTSTRAP", "1");
8156
let output = output(&mut cargo);
8257
let output: Output = serde_json::from_str(&output).unwrap();
8358
for package in output.packages {
@@ -88,5 +63,23 @@ fn build_krate(features: &str, build: &mut Build, resolves: &mut Vec<ResolveNode
8863
build.crates.insert(name, Crate { name, id: package.id, deps: HashSet::new(), path });
8964
}
9065
}
91-
resolves.extend(output.resolve.nodes);
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);
83+
}
84+
}
9285
}

src/bootstrap/test.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1654,9 +1654,7 @@ impl Step for Crate {
16541654
fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
16551655
let builder = run.builder;
16561656
for krate in run.builder.in_tree_crates("test") {
1657-
if !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) {
1658-
run = run.path(krate.local_path(&builder).to_str().unwrap());
1659-
}
1657+
run = run.path(krate.local_path(&builder).to_str().unwrap());
16601658
}
16611659
run
16621660
}

0 commit comments

Comments
 (0)