Skip to content

Commit 58e8535

Browse files
committed
Move detection to be in the fingerprint code
1 parent 02a0e09 commit 58e8535

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub enum DirtyReason {
2929
MetadataChanged,
3030
ConfigSettingsChanged,
3131
CompileKindChanged,
32+
EnvConfigChanged,
3233
LocalLengthsChanged,
3334
PrecalculatedComponentsChanged {
3435
old: String,
@@ -172,6 +173,9 @@ impl DirtyReason {
172173
DirtyReason::CompileKindChanged => {
173174
s.dirty_because(unit, "the rustc compile kind changed")
174175
}
176+
DirtyReason::EnvConfigChanged => {
177+
s.dirty_because(unit, "the environment variable changed")
178+
},
175179
DirtyReason::LocalLengthsChanged => {
176180
s.dirty_because(unit, "the local lengths changed")?;
177181
s.note(

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,14 @@ pub fn prepare_target(
420420
let mtime_on_use = build_runner.bcx.gctx.cli_unstable().mtime_on_use;
421421
let dirty_reason = compare_old_fingerprint(unit, &loc, &*fingerprint, mtime_on_use, force);
422422

423-
let Some(dirty_reason) = dirty_reason else {
424-
return Ok(Job::new_fresh());
423+
let dirty_reason = match dirty_reason {
424+
Some(dr) => dr,
425+
None => {
426+
let Some(dr) = env_config_modified(bcx.gctx) else {
427+
return Ok(Job::new_fresh());
428+
};
429+
dr
430+
},
425431
};
426432

427433
// We're going to rebuild, so ensure the source of the crate passes all
@@ -2231,3 +2237,17 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
22312237
Ok(ret)
22322238
}
22332239
}
2240+
2241+
/// Detects if environment variables from config `[env]` is newly modified.
2242+
fn env_config_modified(gctx: &crate::GlobalContext) -> Option<DirtyReason> {
2243+
for (key, value) in gctx.env_config().unwrap().iter() {
2244+
if !gctx.env().any(|(k, _)| k == key) {
2245+
continue;
2246+
}
2247+
2248+
if !value.is_force() && gctx.env().find(|(k, _)| k == key).is_some() {
2249+
return Some(DirtyReason::EnvConfigChanged);
2250+
}
2251+
}
2252+
None
2253+
}

src/cargo/core/compiler/mod.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn compile<'gctx>(
191191
let force = exec.force_rebuild(unit) || force_rebuild;
192192
let mut job = fingerprint::prepare_target(build_runner, unit, force)?;
193193
job.before(
194-
if job.freshness().is_dirty() || env_config_modified(bcx.gctx)? {
194+
if job.freshness().is_dirty() {
195195
let work = if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
196196
rustdoc(build_runner, unit)?
197197
} else {
@@ -1928,21 +1928,6 @@ fn should_include_scrape_units(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool
19281928
unit.mode.is_doc() && bcx.scrape_units.len() > 0 && bcx.ws.unit_needs_doc_scrape(unit)
19291929
}
19301930

1931-
/// Detects if environment variables from config `[env]` is newly modified.
1932-
fn env_config_modified(gctx: &crate::GlobalContext) -> CargoResult<bool> {
1933-
for (key, value) in gctx.env_config()?.iter() {
1934-
if !gctx.env().any(|(k, _)| k == key) {
1935-
continue;
1936-
}
1937-
1938-
if !value.is_force() && gctx.env().find(|(k, _)| k == key).is_some() {
1939-
return Ok(true);
1940-
}
1941-
}
1942-
1943-
Ok(false)
1944-
}
1945-
19461931
/// Gets the file path of function call information output from `rustdoc`.
19471932
fn scrape_output_path(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<PathBuf> {
19481933
assert!(unit.mode.is_doc() || unit.mode.is_doc_scrape());

0 commit comments

Comments
 (0)