Skip to content

Commit 7990ab5

Browse files
committed
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.
1 parent 3aa9942 commit 7990ab5

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,12 @@ impl<'cfg> Compilation<'cfg> {
340340
.env("CARGO_PKG_AUTHORS", &pkg.authors().join(":"))
341341
.cwd(pkg.root());
342342

343-
// Apply any environment variables from the config
344-
for (key, value) in self.config.env_config()?.iter() {
345-
if value.is_force() || cmd.get_env(&key).is_none() {
346-
cmd.env(&key, value.resolve(&self.config));
343+
if self.config.cli_unstable().configurable_env {
344+
// Apply any environment variables from the config
345+
for (key, value) in self.config.env_config()?.iter() {
346+
if value.is_force() || cmd.get_env(&key).is_none() {
347+
cmd.env(&key, value.resolve(&self.config));
348+
}
347349
}
348350
}
349351

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ pub struct CliUnstable {
444444
pub weak_dep_features: bool,
445445
pub extra_link_arg: bool,
446446
pub credential_process: bool,
447+
pub configurable_env: bool,
447448
}
448449

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

tests/testsuite/cargo_env_config.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fn env_basic() {
2525
)
2626
.build();
2727

28-
p.cargo("run")
28+
p.cargo("run -Zconfigurable-env")
29+
.masquerade_as_nightly_cargo()
2930
.with_stdout_contains("compile-time:Hello")
3031
.with_stdout_contains("run-time:Hello")
3132
.run();
@@ -51,7 +52,8 @@ fn env_invalid() {
5152
)
5253
.build();
5354

54-
p.cargo("build")
55+
p.cargo("build -Zconfigurable-env")
56+
.masquerade_as_nightly_cargo()
5557
.with_status(101)
5658
.with_stderr_contains("[..]`env.ENV_TEST_BOOL` expected a string, but found a boolean")
5759
.run();
@@ -81,7 +83,8 @@ fn env_force() {
8183
)
8284
.build();
8385

84-
p.cargo("run")
86+
p.cargo("run -Zconfigurable-env")
87+
.masquerade_as_nightly_cargo()
8588
.env("ENV_TEST_FORCED", "from-env")
8689
.env("ENV_TEST_UNFORCED", "from-env")
8790
.with_stdout_contains("ENV_TEST_FORCED:from-config")
@@ -117,5 +120,7 @@ fn env_relative() {
117120
)
118121
.build();
119122

120-
p.cargo("run").run();
123+
p.cargo("run -Zconfigurable-env")
124+
.masquerade_as_nightly_cargo()
125+
.run();
121126
}

0 commit comments

Comments
 (0)