diff --git a/src/main.rs b/src/main.rs index 0af618e..65cab99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,6 +153,13 @@ struct Opts { )] command_args: Vec, + #[arg( + long, + help = "Pretend to be a stable compiler (disable features, \ +report a version that looks like a stable version)" + )] + pretend_to_be_stable: bool, + #[arg( long, help = "Left bound for search (*without* regression). You can use \ diff --git a/src/toolchains.rs b/src/toolchains.rs index 2baa591..3586f9e 100644 --- a/src/toolchains.rs +++ b/src/toolchains.rs @@ -257,12 +257,7 @@ impl Toolchain { } (None, None) => { let mut cmd = Command::new("cargo"); - cmd.arg(&format!("+{}", self.rustup_name())); - if cfg.args.command_args.is_empty() { - cmd.arg("build"); - } else { - cmd.args(&cfg.args.command_args); - } + self.set_cargo_args_and_envs(&mut cmd, cfg); cmd } (Some(script), Some(timeout)) => { @@ -277,12 +272,7 @@ impl Toolchain { let mut cmd = Command::new("timeout"); cmd.arg(timeout.to_string()); cmd.arg("cargo"); - cmd.arg(format!("+{}", self.rustup_name())); - if cfg.args.command_args.is_empty() { - cmd.arg("build"); - } else { - cmd.args(&cfg.args.command_args); - } + self.set_cargo_args_and_envs(&mut cmd, cfg); cmd } }; @@ -326,6 +316,32 @@ impl Toolchain { output } + fn set_cargo_args_and_envs(&self, cmd: &mut Command, cfg: &Config) { + let rustup_name = format!("+{}", self.rustup_name()); + cmd.arg(&rustup_name); + if cfg.args.command_args.is_empty() { + cmd.arg("build"); + } else { + cmd.args(&cfg.args.command_args); + } + if cfg.args.pretend_to_be_stable && self.is_current_nightly() { + // Forbid using features + cmd.env( + "RUSTFLAGS", + format!( + "{} -Zallow-features=", + std::env::var("RUSTFLAGS").unwrap_or_default() + ), + ); + // Make rustc report a stable version string derived from the current nightly's version string. + let version = rustc_version::version_meta().unwrap().semver; + cmd.env( + "RUSTC_OVERRIDE_VERSION_STRING", + format!("{}.{}.{}", version.major, version.minor, version.patch), + ); + } + } + pub(crate) fn test(&self, cfg: &Config) -> TestOutcome { eprintln!("testing..."); let outcome = if cfg.args.prompt { diff --git a/tests/cmd/bare-h.stdout b/tests/cmd/bare-h.stdout index c450078..fee81f4 100644 --- a/tests/cmd/bare-h.stdout +++ b/tests/cmd/bare-h.stdout @@ -19,6 +19,8 @@ Options: --install Install the given artifact --preserve Preserve the downloaded artifacts --preserve-target Preserve the target directory used for builds + --pretend-to-be-stable Pretend to be a stable compiler (disable features, report a version + that looks like a stable version) --prompt Manually evaluate for regression with prompts --regress Custom regression definition [default: error] [possible values: error, success, ice, non-ice, non-error] diff --git a/tests/cmd/bare-help.stdout b/tests/cmd/bare-help.stdout index ead0a74..53ef27a 100644 --- a/tests/cmd/bare-help.stdout +++ b/tests/cmd/bare-help.stdout @@ -46,6 +46,10 @@ Options: --preserve-target Preserve the target directory used for builds + --pretend-to-be-stable + Pretend to be a stable compiler (disable features, report a version that looks like a + stable version) + --prompt Manually evaluate for regression with prompts diff --git a/tests/cmd/h.stdout b/tests/cmd/h.stdout index c450078..fee81f4 100644 --- a/tests/cmd/h.stdout +++ b/tests/cmd/h.stdout @@ -19,6 +19,8 @@ Options: --install Install the given artifact --preserve Preserve the downloaded artifacts --preserve-target Preserve the target directory used for builds + --pretend-to-be-stable Pretend to be a stable compiler (disable features, report a version + that looks like a stable version) --prompt Manually evaluate for regression with prompts --regress Custom regression definition [default: error] [possible values: error, success, ice, non-ice, non-error] diff --git a/tests/cmd/help.stdout b/tests/cmd/help.stdout index ead0a74..53ef27a 100644 --- a/tests/cmd/help.stdout +++ b/tests/cmd/help.stdout @@ -46,6 +46,10 @@ Options: --preserve-target Preserve the target directory used for builds + --pretend-to-be-stable + Pretend to be a stable compiler (disable features, report a version that looks like a + stable version) + --prompt Manually evaluate for regression with prompts