Skip to content

Commit 6535b01

Browse files
oli-obkRalfJung
authored andcommitted
Also wrap the initial -vV invocation in the rustc_(workspace_)wrapper
1 parent 499a61c commit 6535b01

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,10 @@ fn descriptive_pkg_name(name: &str, target: &Target, mode: &CompileMode) -> Stri
19071907
}
19081908

19091909
/// Applies environment variables from config `[env]` to [`ProcessBuilder`].
1910-
fn apply_env_config(gctx: &crate::GlobalContext, cmd: &mut ProcessBuilder) -> CargoResult<()> {
1910+
pub(crate) fn apply_env_config(
1911+
gctx: &crate::GlobalContext,
1912+
cmd: &mut ProcessBuilder,
1913+
) -> CargoResult<()> {
19111914
for (key, value) in gctx.env_config()?.iter() {
19121915
// never override a value that has already been set by cargo
19131916
if cmd.get_envs().contains_key(key) {

src/cargo/util/rustc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use cargo_util::{paths, ProcessBuilder, ProcessError};
99
use serde::{Deserialize, Serialize};
1010
use tracing::{debug, info, warn};
1111

12+
use crate::core::compiler::apply_env_config;
1213
use crate::util::interning::InternedString;
1314
use crate::util::{CargoResult, GlobalContext, StableHasher};
1415

@@ -57,7 +58,10 @@ impl Rustc {
5758
gctx,
5859
);
5960

60-
let mut cmd = ProcessBuilder::new(&path);
61+
let mut cmd = ProcessBuilder::new(&path)
62+
.wrapped(workspace_wrapper.as_ref())
63+
.wrapped(wrapper.as_deref());
64+
apply_env_config(gctx, &mut cmd)?;
6165
cmd.arg("-vV");
6266
let verbose_version = cache.cached_output(&cmd, 0)?.0;
6367

tests/testsuite/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5210,6 +5210,30 @@ fn rustc_wrapper() {
52105210
.run();
52115211
}
52125212

5213+
#[cargo_test]
5214+
fn rustc_wrapper_queries() {
5215+
// Check that the invocations querying rustc for information are done with the wrapper.
5216+
let p = project().file("src/lib.rs", "").build();
5217+
let wrapper = tools::echo_wrapper();
5218+
p.cargo("build")
5219+
.env("CARGO_LOG", "cargo::util::rustc=debug")
5220+
.env("RUSTC_WRAPPER", &wrapper)
5221+
.with_stderr_contains("[..]running [..]rustc-echo-wrapper rustc -vV[..]")
5222+
.with_stderr_contains(
5223+
"[..]running [..]rustc-echo-wrapper rustc - --crate-name ___ --print[..]",
5224+
)
5225+
.run();
5226+
p.build_dir().rm_rf();
5227+
p.cargo("build")
5228+
.env("CARGO_LOG", "cargo::util::rustc=debug")
5229+
.env("RUSTC_WORKSPACE_WRAPPER", &wrapper)
5230+
.with_stderr_contains("[..]running [..]rustc-echo-wrapper rustc -vV[..]")
5231+
.with_stderr_contains(
5232+
"[..]running [..]rustc-echo-wrapper rustc - --crate-name ___ --print[..]",
5233+
)
5234+
.run();
5235+
}
5236+
52135237
#[cargo_test]
52145238
fn rustc_wrapper_relative() {
52155239
Package::new("bar", "1.0.0").publish();

tests/testsuite/cargo_env_config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,13 @@ fn env_applied_to_target_info_discovery_rustc() {
192192
"src/main.rs",
193193
r#"
194194
fn main() {
195-
let mut args = std::env::args().skip(1);
195+
let mut cmd = std::env::args().skip(1).collect::<Vec<_>>();
196+
// This will be invoked twice (with `-vV` and with all the `--print`),
197+
// make sure the environment variable exists each time.
196198
let env_test = std::env::var("ENV_TEST").unwrap();
197199
eprintln!("WRAPPER ENV_TEST:{env_test}");
198-
let status = std::process::Command::new(&args.next().unwrap())
200+
let (prog, args) = cmd.split_first().unwrap();
201+
let status = std::process::Command::new(prog)
199202
.args(args).status().unwrap();
200203
std::process::exit(status.code().unwrap_or(1));
201204
}

0 commit comments

Comments
 (0)