Skip to content

Commit e062838

Browse files
authored
Merge pull request #335 from rust-lang/feature_detection
Add a flag for pretending to be a stable compiler when bisecting.
2 parents 4c9d3fd + 700f876 commit e062838

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

src/main.rs

+7
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ struct Opts {
153153
)]
154154
command_args: Vec<OsString>,
155155

156+
#[arg(
157+
long,
158+
help = "Pretend to be a stable compiler (disable features, \
159+
report a version that looks like a stable version)"
160+
)]
161+
pretend_to_be_stable: bool,
162+
156163
#[arg(
157164
long,
158165
help = "Left bound for search (*without* regression). You can use \

src/toolchains.rs

+28-12
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,7 @@ impl Toolchain {
257257
}
258258
(None, None) => {
259259
let mut cmd = Command::new("cargo");
260-
cmd.arg(&format!("+{}", self.rustup_name()));
261-
if cfg.args.command_args.is_empty() {
262-
cmd.arg("build");
263-
} else {
264-
cmd.args(&cfg.args.command_args);
265-
}
260+
self.set_cargo_args_and_envs(&mut cmd, cfg);
266261
cmd
267262
}
268263
(Some(script), Some(timeout)) => {
@@ -277,12 +272,7 @@ impl Toolchain {
277272
let mut cmd = Command::new("timeout");
278273
cmd.arg(timeout.to_string());
279274
cmd.arg("cargo");
280-
cmd.arg(format!("+{}", self.rustup_name()));
281-
if cfg.args.command_args.is_empty() {
282-
cmd.arg("build");
283-
} else {
284-
cmd.args(&cfg.args.command_args);
285-
}
275+
self.set_cargo_args_and_envs(&mut cmd, cfg);
286276
cmd
287277
}
288278
};
@@ -326,6 +316,32 @@ impl Toolchain {
326316
output
327317
}
328318

319+
fn set_cargo_args_and_envs(&self, cmd: &mut Command, cfg: &Config) {
320+
let rustup_name = format!("+{}", self.rustup_name());
321+
cmd.arg(&rustup_name);
322+
if cfg.args.command_args.is_empty() {
323+
cmd.arg("build");
324+
} else {
325+
cmd.args(&cfg.args.command_args);
326+
}
327+
if cfg.args.pretend_to_be_stable && self.is_current_nightly() {
328+
// Forbid using features
329+
cmd.env(
330+
"RUSTFLAGS",
331+
format!(
332+
"{} -Zallow-features=",
333+
std::env::var("RUSTFLAGS").unwrap_or_default()
334+
),
335+
);
336+
// Make rustc report a stable version string derived from the current nightly's version string.
337+
let version = rustc_version::version_meta().unwrap().semver;
338+
cmd.env(
339+
"RUSTC_OVERRIDE_VERSION_STRING",
340+
format!("{}.{}.{}", version.major, version.minor, version.patch),
341+
);
342+
}
343+
}
344+
329345
pub(crate) fn test(&self, cfg: &Config) -> TestOutcome {
330346
eprintln!("testing...");
331347
let outcome = if cfg.args.prompt {

tests/cmd/bare-h.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Options:
1919
--install <INSTALL> Install the given artifact
2020
--preserve Preserve the downloaded artifacts
2121
--preserve-target Preserve the target directory used for builds
22+
--pretend-to-be-stable Pretend to be a stable compiler (disable features, report a version
23+
that looks like a stable version)
2224
--prompt Manually evaluate for regression with prompts
2325
--regress <REGRESS> Custom regression definition [default: error] [possible values:
2426
error, success, ice, non-ice, non-error]

tests/cmd/bare-help.stdout

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Options:
4646
--preserve-target
4747
Preserve the target directory used for builds
4848

49+
--pretend-to-be-stable
50+
Pretend to be a stable compiler (disable features, report a version that looks like a
51+
stable version)
52+
4953
--prompt
5054
Manually evaluate for regression with prompts
5155

tests/cmd/h.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Options:
1919
--install <INSTALL> Install the given artifact
2020
--preserve Preserve the downloaded artifacts
2121
--preserve-target Preserve the target directory used for builds
22+
--pretend-to-be-stable Pretend to be a stable compiler (disable features, report a version
23+
that looks like a stable version)
2224
--prompt Manually evaluate for regression with prompts
2325
--regress <REGRESS> Custom regression definition [default: error] [possible values:
2426
error, success, ice, non-ice, non-error]

tests/cmd/help.stdout

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Options:
4646
--preserve-target
4747
Preserve the target directory used for builds
4848

49+
--pretend-to-be-stable
50+
Pretend to be a stable compiler (disable features, report a version that looks like a
51+
stable version)
52+
4953
--prompt
5054
Manually evaluate for regression with prompts
5155

0 commit comments

Comments
 (0)