Skip to content

Commit 1297f40

Browse files
committed
fix: trace env vars from [env] table
1 parent 7d81fc5 commit 1297f40

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/cargo/core/compiler/fingerprint/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
mod dirty_reason;
363363

364364
use std::collections::hash_map::{Entry, HashMap};
365-
365+
use std::collections::HashSet;
366366
use std::env;
367367
use std::fmt::{self, Display};
368368
use std::fs::{self, File};
@@ -2124,6 +2124,9 @@ enum DepInfoPathType {
21242124
///
21252125
/// The serialized Cargo format will contain a list of files, all of which are
21262126
/// relative if they're under `root`. or absolute if they're elsewhere.
2127+
///
2128+
/// The `config_envs` argument is a set of environment variables that are
2129+
/// defined in `[env]` table of the `config.toml`.
21272130
pub fn translate_dep_info(
21282131
rustc_dep_info: &Path,
21292132
cargo_dep_info: &Path,
@@ -2132,6 +2135,7 @@ pub fn translate_dep_info(
21322135
target_root: &Path,
21332136
rustc_cmd: &ProcessBuilder,
21342137
allow_package: bool,
2138+
config_envs: &HashSet<String>,
21352139
) -> CargoResult<()> {
21362140
let depinfo = parse_rustc_dep_info(rustc_dep_info)?;
21372141

@@ -2168,9 +2172,11 @@ pub fn translate_dep_info(
21682172
// This also includes `CARGO` since if the code is explicitly wanting to
21692173
// know that path, it should be rebuilt if it changes. The CARGO path is
21702174
// not tracked elsewhere in the fingerprint.
2171-
on_disk_info
2172-
.env
2173-
.retain(|(key, _)| !rustc_cmd.get_envs().contains_key(key) || key == CARGO_ENV);
2175+
//
2176+
// For issue#13280, We trace env vars that are defined in the `config.toml`.
2177+
on_disk_info.env.retain(|(key, _)| {
2178+
!rustc_cmd.get_envs().contains_key(key) || key == CARGO_ENV || config_envs.contains(key)
2179+
});
21742180

21752181
let serialize_path = |file| {
21762182
// The path may be absolute or relative, canonical or not. Make sure

src/cargo/core/compiler/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,13 @@ fn rustc(
330330
if hide_diagnostics_for_scrape_unit {
331331
output_options.show_diagnostics = false;
332332
}
333-
333+
let config_envs: HashSet<String> = build_runner
334+
.bcx
335+
.gctx
336+
.env_config()?
337+
.keys()
338+
.cloned()
339+
.collect();
334340
return Ok(Work::new(move |state| {
335341
// Artifacts are in a different location than typical units,
336342
// hence we must assure the crate- and target-dependent
@@ -459,6 +465,7 @@ fn rustc(
459465
&rustc,
460466
// Do not track source files in the fingerprint for registry dependencies.
461467
is_local,
468+
&config_envs,
462469
)
463470
.with_context(|| {
464471
internal(format!(

tests/testsuite/cargo_env_config.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,11 @@ from-config
315315
p.cargo("run")
316316
.env("ENV_TEST", "from-env")
317317
.with_stdout_data(str![[r#"
318-
from-config
318+
from-env
319319
320320
"#]])
321321
.with_stderr_data(str![[r#"
322+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
322323
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
323324
[RUNNING] `target/debug/foo[EXE]`
324325
@@ -355,10 +356,11 @@ one
355356

356357
p.cargo(r#"run --config 'env.ENV_TEST="two"'"#)
357358
.with_stdout_data(str![[r#"
358-
one
359+
two
359360
360361
"#]])
361362
.with_stderr_data(str![[r#"
363+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
362364
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
363365
[RUNNING] `target/debug/foo[EXE]`
364366

0 commit comments

Comments
 (0)