Skip to content

Commit

Permalink
apply the environment to the version query
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 7, 2024
1 parent f372dee commit d67f485
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@ fn descriptive_pkg_name(name: &str, target: &Target, mode: &CompileMode) -> Stri
}

/// Applies environment variables from config `[env]` to [`ProcessBuilder`].
fn apply_env_config(gctx: &crate::GlobalContext, cmd: &mut ProcessBuilder) -> CargoResult<()> {
pub(crate) fn apply_env_config(gctx: &crate::GlobalContext, cmd: &mut ProcessBuilder) -> CargoResult<()> {
for (key, value) in gctx.env_config()?.iter() {
// never override a value that has already been set by cargo
if cmd.get_envs().contains_key(key) {
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cargo_util::{paths, ProcessBuilder, ProcessError};
use serde::{Deserialize, Serialize};
use tracing::{debug, info, warn};

use crate::core::compiler::apply_env_config;
use crate::util::interning::InternedString;
use crate::util::{CargoResult, GlobalContext, StableHasher};

Expand Down Expand Up @@ -60,6 +61,7 @@ impl Rustc {
let mut cmd = ProcessBuilder::new(&path)
.wrapped(workspace_wrapper.as_ref())
.wrapped(wrapper.as_deref());
apply_env_config(gctx, &mut cmd)?;
cmd.arg("-vV");
let verbose_version = cache.cached_output(&cmd, 0)?.0;

Expand Down
10 changes: 4 additions & 6 deletions tests/testsuite/cargo_env_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,10 @@ fn env_applied_to_target_info_discovery_rustc() {
r#"
fn main() {
let mut cmd = std::env::args().skip(1).collect::<Vec<_>>();
if cmd.get(1).map(|s| &**s) == Some("-vV") {
// This is the version query, not the target info query, so skip this.
} else {
let env_test = std::env::var("ENV_TEST").unwrap();
eprintln!("WRAPPER ENV_TEST:{env_test}");
}
// This will be invoked twice (with `-vV` and with all the `--print`),
// make sure the environment variable exists each time.
let env_test = std::env::var("ENV_TEST").unwrap();
eprintln!("WRAPPER ENV_TEST:{env_test}");
let (prog, args) = cmd.split_first().unwrap();
let status = std::process::Command::new(prog)
.args(args).status().unwrap();
Expand Down

0 comments on commit d67f485

Please sign in to comment.