Skip to content

Commit a0de44f

Browse files
committed
Make it possible to run cargo test for bootstrap
Note that this only runs bootstrap's self-tests, not compiler or library tests.
1 parent 5f4e067 commit a0de44f

File tree

3 files changed

+3
-10
lines changed

3 files changed

+3
-10
lines changed

src/bootstrap/builder/tests.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
88
config.save_toolstates = None;
99
config.dry_run = true;
1010
config.ninja_in_file = false;
11-
config.out = PathBuf::from(env::var_os("BOOTSTRAP_OUTPUT_DIRECTORY").unwrap());
12-
config.initial_rustc = PathBuf::from(env::var_os("RUSTC").unwrap());
13-
config.initial_cargo = PathBuf::from(env::var_os("BOOTSTRAP_INITIAL_CARGO").unwrap());
1411
// try to avoid spurious failures in dist where we create/delete each others file
15-
let dir = config
16-
.out
12+
// HACK: rather than pull in `tempdir`, use the one that cargo has conveniently created for us
13+
let dir = Path::new(env!("OUT_DIR"))
1714
.join("tmp-rustbuild-tests")
1815
.join(&thread::current().name().unwrap_or("unknown").replace(":", "-"));
1916
t!(fs::create_dir_all(&dir));

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl Build {
442442
.map(PathBuf::from)
443443
.unwrap_or_else(|_| src.join("target"));
444444
let bootstrap_out = workspace_target_dir.join("debug");
445-
if !bootstrap_out.join("rustc").exists() {
445+
if !bootstrap_out.join("rustc").exists() && !cfg!(test) {
446446
// this restriction can be lifted whenever https://github.com/rust-lang/rfcs/pull/3028 is implemented
447447
panic!("run `cargo build --bins` before `cargo run`")
448448
}

src/bootstrap/test.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2346,10 +2346,6 @@ impl Step for Bootstrap {
23462346
.current_dir(builder.src.join("src/bootstrap"))
23472347
.env("RUSTFLAGS", "-Cdebuginfo=2")
23482348
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2349-
// HACK: bootstrap's tests want to know the output directory, but there's no way to set
2350-
// it except through config.toml. Set it through an env variable instead.
2351-
.env("BOOTSTRAP_OUTPUT_DIRECTORY", &builder.config.out)
2352-
.env("BOOTSTRAP_INITIAL_CARGO", &builder.config.initial_cargo)
23532349
.env("RUSTC_BOOTSTRAP", "1")
23542350
.env("RUSTC", &builder.initial_rustc);
23552351
if let Some(flags) = option_env!("RUSTFLAGS") {

0 commit comments

Comments
 (0)