Skip to content

Commit 239ff78

Browse files
committed
Auto merge of #11754 - kylematsuda:more-config-env, r=ehuss
Make more reads of environment variables go through the `Config` As discussed in #11588, it's better to make reads of environment variables go through the `Config` instead of calling `std::env::var` or `env::var_os` everywhere. Most of the "easy" places to change this in `src/` were handled in #11727. This PR fixes a few remaining call sites that were missed in #11727, namely: - `LocalFingerprint::find_stale_item` - `util::profile::start` and `Profiler` - `util::rustc::rustc_fingerprint` After doing this, there are a few remaining calls to `env::var` in `src/` but those probably require more discussion to fix.
2 parents 7ddcf0f + 5035cb2 commit 239ff78

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ use crate::util;
371371
use crate::util::errors::CargoResult;
372372
use crate::util::interning::InternedString;
373373
use crate::util::{internal, path_args, profile, StableHasher};
374-
use crate::CARGO_ENV;
374+
use crate::{Config, CARGO_ENV};
375375

376376
use super::custom_build::BuildDeps;
377377
use super::job::{Job, Work};
@@ -782,6 +782,7 @@ impl LocalFingerprint {
782782
pkg_root: &Path,
783783
target_root: &Path,
784784
cargo_exe: &Path,
785+
config: &Config,
785786
) -> CargoResult<Option<StaleItem>> {
786787
match self {
787788
// We need to parse `dep_info`, learn about the crate's dependencies.
@@ -810,7 +811,7 @@ impl LocalFingerprint {
810811
.to_string(),
811812
)
812813
} else {
813-
env::var(key).ok()
814+
config.get_env(key).ok()
814815
};
815816
if current == *previous {
816817
continue;
@@ -1059,6 +1060,7 @@ impl Fingerprint {
10591060
pkg_root: &Path,
10601061
target_root: &Path,
10611062
cargo_exe: &Path,
1063+
config: &Config,
10621064
) -> CargoResult<()> {
10631065
assert!(!self.fs_status.up_to_date());
10641066

@@ -1166,7 +1168,7 @@ impl Fingerprint {
11661168
// message and bail out so we stay stale.
11671169
for local in self.local.get_mut().unwrap().iter() {
11681170
if let Some(item) =
1169-
local.find_stale_item(mtime_cache, pkg_root, target_root, cargo_exe)?
1171+
local.find_stale_item(mtime_cache, pkg_root, target_root, cargo_exe, config)?
11701172
{
11711173
item.log();
11721174
self.fs_status = FsStatus::StaleItem(item);
@@ -1328,6 +1330,7 @@ fn calculate(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Arc<Fingerpri
13281330
unit.pkg.root(),
13291331
&target_root,
13301332
cargo_exe,
1333+
cx.bcx.config,
13311334
)?;
13321335

13331336
let fingerprint = Arc::new(fingerprint);

src/cargo/util/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ impl Config {
426426
} else {
427427
None
428428
},
429+
self,
429430
)
430431
}
431432

src/cargo/util/rustc.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use log::{debug, info, warn};
1010
use serde::{Deserialize, Serialize};
1111

1212
use crate::util::interning::InternedString;
13-
use crate::util::{profile, CargoResult, StableHasher};
13+
use crate::util::{profile, CargoResult, Config, StableHasher};
1414

1515
/// Information on the `rustc` executable
1616
#[derive(Debug)]
@@ -43,6 +43,7 @@ impl Rustc {
4343
workspace_wrapper: Option<PathBuf>,
4444
rustup_rustc: &Path,
4545
cache_location: Option<PathBuf>,
46+
config: &Config,
4647
) -> CargoResult<Rustc> {
4748
let _p = profile::start("Rustc::new");
4849

@@ -52,6 +53,7 @@ impl Rustc {
5253
&path,
5354
rustup_rustc,
5455
cache_location,
56+
config,
5557
);
5658

5759
let mut cmd = ProcessBuilder::new(&path);
@@ -173,10 +175,11 @@ impl Cache {
173175
rustc: &Path,
174176
rustup_rustc: &Path,
175177
cache_location: Option<PathBuf>,
178+
config: &Config,
176179
) -> Cache {
177180
match (
178181
cache_location,
179-
rustc_fingerprint(wrapper, workspace_wrapper, rustc, rustup_rustc),
182+
rustc_fingerprint(wrapper, workspace_wrapper, rustc, rustup_rustc, config),
180183
) {
181184
(Some(cache_location), Ok(rustc_fingerprint)) => {
182185
let empty = CacheData {
@@ -296,6 +299,7 @@ fn rustc_fingerprint(
296299
workspace_wrapper: Option<&Path>,
297300
rustc: &Path,
298301
rustup_rustc: &Path,
302+
config: &Config,
299303
) -> CargoResult<u64> {
300304
let mut hasher = StableHasher::new();
301305

@@ -329,8 +333,8 @@ fn rustc_fingerprint(
329333
let maybe_rustup = rustup_rustc == rustc;
330334
match (
331335
maybe_rustup,
332-
env::var("RUSTUP_HOME"),
333-
env::var("RUSTUP_TOOLCHAIN"),
336+
config.get_env("RUSTUP_HOME"),
337+
config.get_env("RUSTUP_TOOLCHAIN"),
334338
) {
335339
(_, Ok(rustup_home), Ok(rustup_toolchain)) => {
336340
debug!("adding rustup info to rustc fingerprint");

0 commit comments

Comments
 (0)