Skip to content

Commit

Permalink
Move detection to be in the fingerprint code
Browse files Browse the repository at this point in the history
  • Loading branch information
LuuuXXX committed Mar 16, 2024
1 parent 02a0e09 commit 58e8535
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/cargo/core/compiler/fingerprint/dirty_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub enum DirtyReason {
MetadataChanged,
ConfigSettingsChanged,
CompileKindChanged,
EnvConfigChanged,
LocalLengthsChanged,
PrecalculatedComponentsChanged {
old: String,
Expand Down Expand Up @@ -172,6 +173,9 @@ impl DirtyReason {
DirtyReason::CompileKindChanged => {
s.dirty_because(unit, "the rustc compile kind changed")
}
DirtyReason::EnvConfigChanged => {
s.dirty_because(unit, "the environment variable changed")
},
DirtyReason::LocalLengthsChanged => {
s.dirty_because(unit, "the local lengths changed")?;
s.note(
Expand Down
24 changes: 22 additions & 2 deletions src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,14 @@ pub fn prepare_target(
let mtime_on_use = build_runner.bcx.gctx.cli_unstable().mtime_on_use;
let dirty_reason = compare_old_fingerprint(unit, &loc, &*fingerprint, mtime_on_use, force);

let Some(dirty_reason) = dirty_reason else {
return Ok(Job::new_fresh());
let dirty_reason = match dirty_reason {
Some(dr) => dr,
None => {
let Some(dr) = env_config_modified(bcx.gctx) else {
return Ok(Job::new_fresh());
};
dr
},
};

// We're going to rebuild, so ensure the source of the crate passes all
Expand Down Expand Up @@ -2231,3 +2237,17 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
Ok(ret)
}
}

/// Detects if environment variables from config `[env]` is newly modified.
fn env_config_modified(gctx: &crate::GlobalContext) -> Option<DirtyReason> {
for (key, value) in gctx.env_config().unwrap().iter() {
if !gctx.env().any(|(k, _)| k == key) {
continue;
}

if !value.is_force() && gctx.env().find(|(k, _)| k == key).is_some() {
return Some(DirtyReason::EnvConfigChanged);
}
}
None
}
17 changes: 1 addition & 16 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn compile<'gctx>(
let force = exec.force_rebuild(unit) || force_rebuild;
let mut job = fingerprint::prepare_target(build_runner, unit, force)?;
job.before(
if job.freshness().is_dirty() || env_config_modified(bcx.gctx)? {
if job.freshness().is_dirty() {
let work = if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
rustdoc(build_runner, unit)?
} else {
Expand Down Expand Up @@ -1928,21 +1928,6 @@ fn should_include_scrape_units(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool
unit.mode.is_doc() && bcx.scrape_units.len() > 0 && bcx.ws.unit_needs_doc_scrape(unit)
}

/// Detects if environment variables from config `[env]` is newly modified.
fn env_config_modified(gctx: &crate::GlobalContext) -> CargoResult<bool> {
for (key, value) in gctx.env_config()?.iter() {
if !gctx.env().any(|(k, _)| k == key) {
continue;
}

if !value.is_force() && gctx.env().find(|(k, _)| k == key).is_some() {
return Ok(true);
}
}

Ok(false)
}

/// Gets the file path of function call information output from `rustdoc`.
fn scrape_output_path(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<PathBuf> {
assert!(unit.mode.is_doc() || unit.mode.is_doc_scrape());
Expand Down

0 comments on commit 58e8535

Please sign in to comment.