mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
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:
parent
3aa99422ca
commit
7990ab53f5
@ -340,10 +340,12 @@ impl<'cfg> Compilation<'cfg> {
|
|||||||
.env("CARGO_PKG_AUTHORS", &pkg.authors().join(":"))
|
.env("CARGO_PKG_AUTHORS", &pkg.authors().join(":"))
|
||||||
.cwd(pkg.root());
|
.cwd(pkg.root());
|
||||||
|
|
||||||
// Apply any environment variables from the config
|
if self.config.cli_unstable().configurable_env {
|
||||||
for (key, value) in self.config.env_config()?.iter() {
|
// Apply any environment variables from the config
|
||||||
if value.is_force() || cmd.get_env(&key).is_none() {
|
for (key, value) in self.config.env_config()?.iter() {
|
||||||
cmd.env(&key, value.resolve(&self.config));
|
if value.is_force() || cmd.get_env(&key).is_none() {
|
||||||
|
cmd.env(&key, value.resolve(&self.config));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,6 +444,7 @@ pub struct CliUnstable {
|
|||||||
pub weak_dep_features: bool,
|
pub weak_dep_features: bool,
|
||||||
pub extra_link_arg: bool,
|
pub extra_link_arg: bool,
|
||||||
pub credential_process: bool,
|
pub credential_process: bool,
|
||||||
|
pub configurable_env: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const STABILIZED_COMPILE_PROGRESS: &str = "The progress bar is now always \
|
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)?,
|
"doctest-xcompile" => self.doctest_xcompile = parse_empty(k, v)?,
|
||||||
"panic-abort-tests" => self.panic_abort_tests = 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)?,
|
"jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?,
|
||||||
|
"configurable-env" => self.configurable_env = parse_empty(k, v)?,
|
||||||
"features" => {
|
"features" => {
|
||||||
// For now this is still allowed (there are still some
|
// For now this is still allowed (there are still some
|
||||||
// unstable options like "compare"). This should be removed at
|
// unstable options like "compare"). This should be removed at
|
||||||
|
@ -25,7 +25,8 @@ fn env_basic() {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("run")
|
p.cargo("run -Zconfigurable-env")
|
||||||
|
.masquerade_as_nightly_cargo()
|
||||||
.with_stdout_contains("compile-time:Hello")
|
.with_stdout_contains("compile-time:Hello")
|
||||||
.with_stdout_contains("run-time:Hello")
|
.with_stdout_contains("run-time:Hello")
|
||||||
.run();
|
.run();
|
||||||
@ -51,7 +52,8 @@ fn env_invalid() {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("build")
|
p.cargo("build -Zconfigurable-env")
|
||||||
|
.masquerade_as_nightly_cargo()
|
||||||
.with_status(101)
|
.with_status(101)
|
||||||
.with_stderr_contains("[..]`env.ENV_TEST_BOOL` expected a string, but found a boolean")
|
.with_stderr_contains("[..]`env.ENV_TEST_BOOL` expected a string, but found a boolean")
|
||||||
.run();
|
.run();
|
||||||
@ -81,7 +83,8 @@ fn env_force() {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("run")
|
p.cargo("run -Zconfigurable-env")
|
||||||
|
.masquerade_as_nightly_cargo()
|
||||||
.env("ENV_TEST_FORCED", "from-env")
|
.env("ENV_TEST_FORCED", "from-env")
|
||||||
.env("ENV_TEST_UNFORCED", "from-env")
|
.env("ENV_TEST_UNFORCED", "from-env")
|
||||||
.with_stdout_contains("ENV_TEST_FORCED:from-config")
|
.with_stdout_contains("ENV_TEST_FORCED:from-config")
|
||||||
@ -117,5 +120,7 @@ fn env_relative() {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("run").run();
|
p.cargo("run -Zconfigurable-env")
|
||||||
|
.masquerade_as_nightly_cargo()
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user