Add -Z configurable-env to gate [env] usage

Added the `-Z configurable-env` option which controls whether the data from the [env] section is used. Updated the tests to pass the flag and to masquerade as the nightly cargo.
This commit is contained in:
Martin Donlon 2021-02-15 20:21:22 -08:00
parent 3aa99422ca
commit 7990ab53f5
3 changed files with 17 additions and 8 deletions

View File

@ -340,10 +340,12 @@ impl<'cfg> Compilation<'cfg> {
.env("CARGO_PKG_AUTHORS", &pkg.authors().join(":"))
.cwd(pkg.root());
// Apply any environment variables from the config
for (key, value) in self.config.env_config()?.iter() {
if value.is_force() || cmd.get_env(&key).is_none() {
cmd.env(&key, value.resolve(&self.config));
if self.config.cli_unstable().configurable_env {
// Apply any environment variables from the config
for (key, value) in self.config.env_config()?.iter() {
if value.is_force() || cmd.get_env(&key).is_none() {
cmd.env(&key, value.resolve(&self.config));
}
}
}

View File

@ -444,6 +444,7 @@ pub struct CliUnstable {
pub weak_dep_features: bool,
pub extra_link_arg: bool,
pub credential_process: bool,
pub configurable_env: bool,
}
const STABILIZED_COMPILE_PROGRESS: &str = "The progress bar is now always \
@ -598,6 +599,7 @@ impl CliUnstable {
"doctest-xcompile" => self.doctest_xcompile = parse_empty(k, v)?,
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
"jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?,
"configurable-env" => self.configurable_env = parse_empty(k, v)?,
"features" => {
// For now this is still allowed (there are still some
// unstable options like "compare"). This should be removed at

View File

@ -25,7 +25,8 @@ fn env_basic() {
)
.build();
p.cargo("run")
p.cargo("run -Zconfigurable-env")
.masquerade_as_nightly_cargo()
.with_stdout_contains("compile-time:Hello")
.with_stdout_contains("run-time:Hello")
.run();
@ -51,7 +52,8 @@ fn env_invalid() {
)
.build();
p.cargo("build")
p.cargo("build -Zconfigurable-env")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr_contains("[..]`env.ENV_TEST_BOOL` expected a string, but found a boolean")
.run();
@ -81,7 +83,8 @@ fn env_force() {
)
.build();
p.cargo("run")
p.cargo("run -Zconfigurable-env")
.masquerade_as_nightly_cargo()
.env("ENV_TEST_FORCED", "from-env")
.env("ENV_TEST_UNFORCED", "from-env")
.with_stdout_contains("ENV_TEST_FORCED:from-config")
@ -117,5 +120,7 @@ fn env_relative() {
)
.build();
p.cargo("run").run();
p.cargo("run -Zconfigurable-env")
.masquerade_as_nightly_cargo()
.run();
}