Skip to content

Commit

Permalink
Add detect while using environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
LuuuXXX committed Mar 16, 2024
1 parent e7ca1af commit 02a0e09
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,29 @@ fn compile<'gctx>(
} else {
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() {
let work = if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
rustdoc(build_runner, unit)?
job.before(
if job.freshness().is_dirty() || env_config_modified(bcx.gctx)? {
let work = if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
rustdoc(build_runner, unit)?
} else {
rustc(build_runner, unit, exec)?
};
work.then(link_targets(build_runner, unit, false)?)
} else {
rustc(build_runner, unit, exec)?
};
work.then(link_targets(build_runner, unit, false)?)
} else {
// We always replay the output cache,
// since it might contain future-incompat-report messages
let work = replay_output_cache(
unit.pkg.package_id(),
PathBuf::from(unit.pkg.manifest_path()),
&unit.target,
build_runner.files().message_cache_path(unit),
build_runner.bcx.build_config.message_format,
unit.show_warnings(bcx.gctx),
);
// Need to link targets on both the dirty and fresh.
work.then(link_targets(build_runner, unit, true)?)
});
// We always replay the output cache,
// since it might contain future-incompat-report messages
let work = replay_output_cache(
unit.pkg.package_id(),
PathBuf::from(unit.pkg.manifest_path()),
&unit.target,
build_runner.files().message_cache_path(unit),
build_runner.bcx.build_config.message_format,
unit.show_warnings(bcx.gctx),
);
// Need to link targets on both the dirty and fresh.
work.then(link_targets(build_runner, unit, true)?)
},
);

job
};
Expand Down Expand Up @@ -1926,6 +1928,21 @@ 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 02a0e09

Please sign in to comment.