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
.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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guessed you intention is explictly to use str::to_string instead ?

Copy link
Contributor

Choose a reason for hiding this comment

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

For myself, I tend to prefer to_owned as that signals the intent

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

@linyihai linyihai force-pushed the rerun-env-changed-issue-10358 branch from ba24555 to 0a52c09 Compare November 1, 2024 09:29
@linyihai linyihai force-pushed the rerun-env-changed-issue-10358 branch from 0a52c09 to ab9438f Compare November 4, 2024 08:40
@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-configuration Area: cargo config files and env vars labels Nov 4, 2024
@linyihai linyihai force-pushed the rerun-env-changed-issue-10358 branch from 1551bf3 to 697a206 Compare November 4, 2024 10:30
Copy link
Contributor

Choose a reason for hiding this comment

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

refactor: env_config supports resolve case insensitive env.

What was the intention with this last commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its intention is #14756 (comment). Should I squash it into the previous fixing commit ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The intention behind that is to abstract away the platform-specific logic and make it easier to do the right thing across cargo. I don't feel the current implementation meets that need. Granted, this might be a bigger change, so depending on the direction we should take with it, maybe its better to defer out of this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I leave this as a future PR.

@linyihai linyihai force-pushed the rerun-env-changed-issue-10358 branch 2 times, most recently from 18e5a5b to eeaf9bb Compare November 6, 2024 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-configuration Area: cargo config files and env vars 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