fix: env table config can't trigger rebuild with rerun-if-env-changed.#14756
Conversation
rerun-if-env-changed.rerun-if-env-changed.
0ce1d7d to
ba24555
Compare
| .collect::<HashMap<String, OsString>>() | ||
| }) | ||
| .get(&key.to_uppercase()) | ||
| .and_then(|s| s.to_str().map(|s| s.to_string())) |
There was a problem hiding this comment.
Please use a more specific conversion than to_string as it can mask incidental semantic conversions
There was a problem hiding this comment.
I guessed you intention is explictly to use str::to_string instead ?
There was a problem hiding this comment.
For myself, I tend to prefer to_owned as that signals the intent
| if cfg!(windows) { | ||
| env_config_insensitive |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Sorry, Yes, I meant conditioned on the platform (which is why the typedef would be there)
There was a problem hiding this comment.
Hmm, if we also have a normalization process, I wonder if we should apply that more generally
ba24555 to
0a52c09
Compare
0a52c09 to
ab9438f
Compare
1551bf3 to
697a206
Compare
There was a problem hiding this comment.
refactor: env_config supports resolve case insensitive env.
What was the intention with this last commit?
There was a problem hiding this comment.
Its intention is #14756 (comment). Should I squash it into the previous fixing commit ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Ok, I leave this as a future PR.
18e5a5b to
eeaf9bb
Compare
eeaf9bb to
e035080
Compare
|
I removed the code that makes |
weihanglo
left a comment
There was a problem hiding this comment.
This all makes sense. Thank you.
| /// The `env_config` is used first to check if the env var is set in the config system | ||
| /// as some env needs to be overridden. If not, it will fallback to `std::env::var`. |
There was a problem hiding this comment.
I think the TODO here still holds. I don't see any reason this should be read directly from system but not our env snapshot.
(though it doesn't really make much difference in this case)
| /// The `env_config` is used first to check if the env var is set in the config system | |
| /// as some env needs to be overridden. If not, it will fallback to `std::env::var`. | |
| /// The `env_config` is used first to check if the env var is set in the config system | |
| /// as some env needs to be overridden. If not, it will fallback to `std::env::var`. | |
| // TODO: `std::env::var` is allowed at this moment. Should figure out | |
| // if it makes sense if permitting to read env from the env snapshot. |
…rerun-if-env-changed`.
e035080 to
76ffbe0
Compare
Update cargo 9 commits in d73d2caf9e41a39daf2a8d6ce60ec80bf354d2a7..fd784878cfa843e3e29a6654ecf564c62fae6735 2024-12-31 20:51:21 +0000 to 2025-01-03 20:06:26 +0000 - chore: bump gix-lock to remove thiserror@1 from `cargo` (rust-lang/cargo#15012) - refactor(manifest): Clean up field -> env var handling (rust-lang/cargo#15008) - chore(deps): update rust crate thiserror to v2 (rust-lang/cargo#14998) - test(git): Clean up shallow fetch tests (rust-lang/cargo#15002) - fix(schema): Correct and update the JSON Schema (rust-lang/cargo#15000) - chore(deps): update rust crate itertools to 0.14.0 (rust-lang/cargo#14996) - fix: env table config can't trigger rebuild with `rerun-if-env-changed`. (rust-lang/cargo#14756) - chore(deps): update alpine docker tag to v3.21 (rust-lang/cargo#14995) - fix(package): check dirtiness of symlinks source files (rust-lang/cargo#14981)
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.