Skip to content

Commit

Permalink
Auto merge of #11754 - kylematsuda:more-config-env, r=ehuss
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Feb 22, 2023
2 parents 7ddcf0f + 5035cb2 commit 239ff78
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ use crate::util;
use crate::util::errors::CargoResult;
use crate::util::interning::InternedString;
use crate::util::{internal, path_args, profile, StableHasher};
use crate::CARGO_ENV;
use crate::{Config, CARGO_ENV};

use super::custom_build::BuildDeps;
use super::job::{Job, Work};
Expand Down Expand Up @@ -782,6 +782,7 @@ impl LocalFingerprint {
pkg_root: &Path,
target_root: &Path,
cargo_exe: &Path,
config: &Config,
) -> CargoResult<Option<StaleItem>> {
match self {
// We need to parse `dep_info`, learn about the crate's dependencies.
Expand Down Expand Up @@ -810,7 +811,7 @@ impl LocalFingerprint {
.to_string(),
)
} else {
env::var(key).ok()
config.get_env(key).ok()
};
if current == *previous {
continue;
Expand Down Expand Up @@ -1059,6 +1060,7 @@ impl Fingerprint {
pkg_root: &Path,
target_root: &Path,
cargo_exe: &Path,
config: &Config,
) -> CargoResult<()> {
assert!(!self.fs_status.up_to_date());

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

let fingerprint = Arc::new(fingerprint);
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ impl Config {
} else {
None
},
self,
)
}

Expand Down
12 changes: 8 additions & 4 deletions src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use log::{debug, info, warn};
use serde::{Deserialize, Serialize};

use crate::util::interning::InternedString;
use crate::util::{profile, CargoResult, StableHasher};
use crate::util::{profile, CargoResult, Config, StableHasher};

/// Information on the `rustc` executable
#[derive(Debug)]
Expand Down Expand Up @@ -43,6 +43,7 @@ impl Rustc {
workspace_wrapper: Option<PathBuf>,
rustup_rustc: &Path,
cache_location: Option<PathBuf>,
config: &Config,
) -> CargoResult<Rustc> {
let _p = profile::start("Rustc::new");

Expand All @@ -52,6 +53,7 @@ impl Rustc {
&path,
rustup_rustc,
cache_location,
config,
);

let mut cmd = ProcessBuilder::new(&path);
Expand Down Expand Up @@ -173,10 +175,11 @@ impl Cache {
rustc: &Path,
rustup_rustc: &Path,
cache_location: Option<PathBuf>,
config: &Config,
) -> Cache {
match (
cache_location,
rustc_fingerprint(wrapper, workspace_wrapper, rustc, rustup_rustc),
rustc_fingerprint(wrapper, workspace_wrapper, rustc, rustup_rustc, config),
) {
(Some(cache_location), Ok(rustc_fingerprint)) => {
let empty = CacheData {
Expand Down Expand Up @@ -296,6 +299,7 @@ fn rustc_fingerprint(
workspace_wrapper: Option<&Path>,
rustc: &Path,
rustup_rustc: &Path,
config: &Config,
) -> CargoResult<u64> {
let mut hasher = StableHasher::new();

Expand Down Expand Up @@ -329,8 +333,8 @@ fn rustc_fingerprint(
let maybe_rustup = rustup_rustc == rustc;
match (
maybe_rustup,
env::var("RUSTUP_HOME"),
env::var("RUSTUP_TOOLCHAIN"),
config.get_env("RUSTUP_HOME"),
config.get_env("RUSTUP_TOOLCHAIN"),
) {
(_, Ok(rustup_home), Ok(rustup_toolchain)) => {
debug!("adding rustup info to rustc fingerprint");
Expand Down

0 comments on commit 239ff78

Please sign in to comment.