Skip to content

Commit 316667d

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

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
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

+20-37
Original file line numberDiff line numberDiff line change
@@ -190,29 +190,27 @@ fn compile<'gctx>(
190190
} else {
191191
let force = exec.force_rebuild(unit) || force_rebuild;
192192
let mut job = fingerprint::prepare_target(build_runner, unit, force)?;
193-
job.before(
194-
if job.freshness().is_dirty() || env_config_modified(bcx.gctx)? {
195-
let work = if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
196-
rustdoc(build_runner, unit)?
197-
} else {
198-
rustc(build_runner, unit, exec)?
199-
};
200-
work.then(link_targets(build_runner, unit, false)?)
193+
job.before(if job.freshness().is_dirty() {
194+
let work = if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
195+
rustdoc(build_runner, unit)?
201196
} else {
202-
// We always replay the output cache,
203-
// since it might contain future-incompat-report messages
204-
let work = replay_output_cache(
205-
unit.pkg.package_id(),
206-
PathBuf::from(unit.pkg.manifest_path()),
207-
&unit.target,
208-
build_runner.files().message_cache_path(unit),
209-
build_runner.bcx.build_config.message_format,
210-
unit.show_warnings(bcx.gctx),
211-
);
212-
// Need to link targets on both the dirty and fresh.
213-
work.then(link_targets(build_runner, unit, true)?)
214-
},
215-
);
197+
rustc(build_runner, unit, exec)?
198+
};
199+
work.then(link_targets(build_runner, unit, false)?)
200+
} else {
201+
// We always replay the output cache,
202+
// since it might contain future-incompat-report messages
203+
let work = replay_output_cache(
204+
unit.pkg.package_id(),
205+
PathBuf::from(unit.pkg.manifest_path()),
206+
&unit.target,
207+
build_runner.files().message_cache_path(unit),
208+
build_runner.bcx.build_config.message_format,
209+
unit.show_warnings(bcx.gctx),
210+
);
211+
// Need to link targets on both the dirty and fresh.
212+
work.then(link_targets(build_runner, unit, true)?)
213+
});
216214

217215
job
218216
};
@@ -1928,21 +1926,6 @@ fn should_include_scrape_units(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool
19281926
unit.mode.is_doc() && bcx.scrape_units.len() > 0 && bcx.ws.unit_needs_doc_scrape(unit)
19291927
}
19301928

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

0 commit comments

Comments
 (0)