Skip to content

Commit 81a7cea

Browse files
authored
Unrolled build for #144782
Rollup merge of #144782 - jieyouxu:compiletest-selftests, r=Kobzol Properly pass path to staged `rustc` to `compiletest` self-tests Otherwise, this can do weird things like use a global rustc, or try to use stage 0 rustc. This must be properly configured, because `compiletest` is intended to only support one compiler target spec JSON format (of the in-tree compiler). Historically, this was probably done so before `bootstrap` was really its own thing, and `compiletest` had to be runnable as a much more "self-standing" tool. Follow-up to #144675, as I didn't realize this until Zalathar pointed it out in [#t-infra/bootstrap > Building vs testing `compiletest` @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Building.20vs.20testing.20.60compiletest.60/near/532040838). r? ````@Kobzol````
2 parents a65b04d + bd7b8b3 commit 81a7cea

File tree

2 files changed

+8
-16
lines changed
  • src
    • bootstrap/src/core/build_steps
    • tools/compiletest/src/directives

2 files changed

+8
-16
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,12 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
749749
SourceType::InTree,
750750
&[],
751751
);
752+
753+
// Used for `compiletest` self-tests to have the path to the *staged* compiler. Getting this
754+
// right is important, as `compiletest` is intended to only support one target spec JSON
755+
// format, namely that of the staged compiler.
756+
cargo.env("TEST_RUSTC", builder.rustc(compiler));
757+
752758
cargo.allow_features(COMPILETEST_ALLOW_FEATURES);
753759
run_cargo_test(cargo, &[], &[], "compiletest self test", host, builder);
754760
}

src/tools/compiletest/src/directives/tests.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,22 +203,8 @@ impl ConfigBuilder {
203203
}
204204

205205
args.push("--rustc-path".to_string());
206-
// This is a subtle/fragile thing. On rust-lang CI, there is no global
207-
// `rustc`, and Cargo doesn't offer a convenient way to get the path to
208-
// `rustc`. Fortunately bootstrap sets `RUSTC` for us, which is pointing
209-
// to the stage0 compiler.
210-
//
211-
// Otherwise, if you are running compiletests's tests manually, you
212-
// probably don't have `RUSTC` set, in which case this falls back to the
213-
// global rustc. If your global rustc is too far out of sync with stage0,
214-
// then this may cause confusing errors. Or if for some reason you don't
215-
// have rustc in PATH, that would also fail.
216-
args.push(std::env::var("RUSTC").unwrap_or_else(|_| {
217-
eprintln!(
218-
"warning: RUSTC not set, using global rustc (are you not running via bootstrap?)"
219-
);
220-
"rustc".to_string()
221-
}));
206+
args.push(std::env::var("TEST_RUSTC").expect("must be configured by bootstrap"));
207+
222208
crate::parse_config(args)
223209
}
224210
}

0 commit comments

Comments
 (0)