Skip to content

Commit 400f23e

Browse files
committed
Simplify make_run for test::Crate by introducing crate_paths instead of calculating them after the fact
1 parent 11909e3 commit 400f23e

File tree

3 files changed

+14
-31
lines changed

3 files changed

+14
-31
lines changed

src/bootstrap/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ pub struct Build {
301301
ar: HashMap<TargetSelection, PathBuf>,
302302
ranlib: HashMap<TargetSelection, PathBuf>,
303303
// Miscellaneous
304+
// allow bidirectional lookups: both name -> path and path -> name
304305
crates: HashMap<Interned<String>, Crate>,
306+
crate_paths: HashMap<PathBuf, Interned<String>>,
305307
is_sudo: bool,
306308
ci_env: CiEnv,
307309
delayed_failures: RefCell<Vec<String>>,
@@ -491,6 +493,7 @@ impl Build {
491493
ar: HashMap::new(),
492494
ranlib: HashMap::new(),
493495
crates: HashMap::new(),
496+
crate_paths: HashMap::new(),
494497
is_sudo,
495498
ci_env: CiEnv::current(),
496499
delayed_failures: RefCell::new(Vec::new()),

src/bootstrap/metadata.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ pub fn build(build: &mut Build) {
4949
.filter(|dep| dep.source.is_none())
5050
.map(|dep| INTERNER.intern_string(dep.name))
5151
.collect();
52-
build.crates.insert(name, Crate { name, deps, path });
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");
5357
}
5458
}
5559
}

src/bootstrap/test.rs

+6-30
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::native;
2121
use crate::tool::{self, SourceType, Tool};
2222
use crate::toolstate::ToolState;
2323
use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
24-
use crate::Crate as CargoCrate;
2524
use crate::{envify, CLang, DocTests, GitRepo, Mode};
2625

2726
const ADB_TEST_DIR: &str = "/data/tmp/work";
@@ -1901,19 +1900,10 @@ impl Step for CrateLibrustc {
19011900
fn make_run(run: RunConfig<'_>) {
19021901
let builder = run.builder;
19031902
let compiler = builder.compiler(builder.top_stage, run.build_triple());
1903+
let krate = builder.crate_paths[&run.path];
1904+
let test_kind = builder.kind.into();
19041905

1905-
for krate in builder.in_tree_crates("rustc-main", Some(run.target)) {
1906-
if krate.path.ends_with(&run.path) {
1907-
let test_kind = builder.kind.into();
1908-
1909-
builder.ensure(CrateLibrustc {
1910-
compiler,
1911-
target: run.target,
1912-
test_kind,
1913-
krate: krate.name,
1914-
});
1915-
}
1916-
}
1906+
builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, krate });
19171907
}
19181908

19191909
fn run(self, builder: &Builder<'_>) {
@@ -1947,24 +1937,10 @@ impl Step for Crate {
19471937
fn make_run(run: RunConfig<'_>) {
19481938
let builder = run.builder;
19491939
let compiler = builder.compiler(builder.top_stage, run.build_triple());
1940+
let test_kind = builder.kind.into();
1941+
let krate = builder.crate_paths[&run.path];
19501942

1951-
let make = |mode: Mode, krate: &CargoCrate| {
1952-
let test_kind = builder.kind.into();
1953-
1954-
builder.ensure(Crate {
1955-
compiler,
1956-
target: run.target,
1957-
mode,
1958-
test_kind,
1959-
krate: krate.name,
1960-
});
1961-
};
1962-
1963-
for krate in builder.in_tree_crates("test", Some(run.target)) {
1964-
if krate.path.ends_with(&run.path) {
1965-
make(Mode::Std, krate);
1966-
}
1967-
}
1943+
builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, krate });
19681944
}
19691945

19701946
/// Runs all unit tests plus documentation tests for a given crate defined

0 commit comments

Comments
 (0)