Skip to content
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

fix: env table config can't trigger rebuild with rerun-if-env-changed. #14756

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

linyihai
Copy link
Contributor

What does this PR try to resolve?

As #10358 said, When a build.rs script emits cargo:rerun-if-env-changed, it is not re-run when the value of the specified variable is changed via the env configuration.

Fixes #10358

How should we test and review this PR?

Add test bofore fixing to reflect the issue, the next commit fixed it.

Additional information

The PR is a sucessor of #14058, so the previous dicussion can be refer to it.

@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2024

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-rebuild-detection Area: rebuild detection and fingerprinting S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 31, 2024
@linyihai linyihai changed the title fix: env table config can trigger rebuild with rerun-if-env-changed. fix: env table config can't trigger rebuild with rerun-if-env-changed. Oct 31, 2024
@linyihai linyihai force-pushed the rerun-env-changed-issue-10358 branch from 0ce1d7d to ba24555 Compare October 31, 2024 08:34
@linyihai linyihai marked this pull request as ready for review October 31, 2024 09:30
@@ -376,6 +377,7 @@ use anyhow::format_err;
use anyhow::Context as _;
use cargo_util::paths;
use filetime::FileTime;
use lazycell::LazyCell;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo we should not be adding any new uses of lazycell but should instead be trying to remove it in favor of OnceCell

Comment on lines +809 to +812
let val = if let Some(val) = env::var(key).ok() {
Some(val)
} else {
match env_config.get(key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which is supposed to have higher precedence?

@@ -1701,6 +1725,7 @@ fn build_script_local_fingerprints(
// obvious.
let pkg_root = unit.pkg.root().to_path_buf();
let target_dir = target_root(build_runner);
let env_config = Arc::clone(build_runner.bcx.gctx.env_config().unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the assumption we are operating under that its safe to unwrap?

.collect::<HashMap<String, OsString>>()
})
.get(&key.to_uppercase())
.and_then(|s| s.to_str().map(|s| s.to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a more specific conversion than to_string as it can mask incidental semantic conversions

Comment on lines +815 to +816
if cfg!(windows) {
env_config_insensitive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having to do all of this extra work, I wonder if we should make the env map itself case insensitive. Looking at how env_config() is used, I think we have several places where we don't handle case sensitivity and maybe we should?

What we could do is define a type def for EnvMap where the key is unicase::Ascii<String> and have the global context return that.

@weihanglo thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be conditioned on platform, maybe only on Windows?

Cargo does that upfront for environment variables from configuration enviornment: https://github.com/rust-lang/cargo/blob/master/src/cargo/util/context/environment.rs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, Yes, I meant conditioned on the platform (which is why the typedef would be there)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if we also have a normalization process, I wonder if we should apply that more generally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rebuild-detection Area: rebuild detection and fingerprinting S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo:rerun-if-env-changed doesn't work with env configuration
4 participants