-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Fix: Cargo fails to detect environment variable #13596
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this does fix the case described in #13280, the actual problem is not addressed: Dep-info from Cargo doesn't track It's simple to reproduce delete the
Only |
||
return Ok(Job::new_fresh()); | ||
}; | ||
dr | ||
} | ||
}; | ||
|
||
// 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> | |
Ok(ret) | ||
} | ||
} | ||
|
||
/// Detects if environment variables from config `[env]` is newly seted. | ||
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder some alternatives may be like:
cargo::rustc-env
build script directive into account, and I feel it will be pretty error-prone as we might miss something when adding more envs.--env-set
rustc flag from the env sandboxing RFC. However, it is still unstable so Cargo can't use it.