-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: improve handling of the env! macro
#20554
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
Conversation
cargo.extraEnv to be resolved by the env! macroenv! macro
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.
Just one nit.
Thanks!
crates/project-model/src/env.rs
Outdated
| extra_env: &FxHashMap<String, Option<String>>, | ||
| ) -> Env { | ||
| let mut env = Env::default(); | ||
| for (key, value) in extra_env { |
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.
Env implements Extend, please use that.
| )| { | ||
| let env = env.clone().into_iter().collect(); | ||
| let mut env = env.clone().into_iter().collect::<Env>(); | ||
| for (key, value) in extra_env.iter() { |
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.
Here again use Extend.
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.
Thanks!
env! macroenv! macro
First issue:
Currently
cargo_config_envassumes thatcargo configalways serializes each entry in theenvtable to an object, but it is valid to use just a string for the value in theenvtable and this is converted to a string in the JSON:The fix for this is to handle JSON strings as well as objects.
Second issue:
Currently the only values available to the
env!macro are those set in theenvtable of the Cargo configuration file (plus a few other hard coded values). This makes it difficult to simulate having environment variables set (e.g., to match a CI system) without either modifying the current project's configuration (which is usually checked-in) or the user's configuration (which is shared between projects).This change makes the values set in the
cargo.extraEnvconfiguration option available via theenv!macro when loading a project via Cargo manifests. This provides a straightforward way for users to set custom values forenv!and for those values to be consistent between language services andcargo check.Note that this feature respects the
forceoption in theenvtable, so it will only overwrite the values fromextraEnvifforceis set to true.Fixes #13004
Partial fix for #17593 (changes
env!but notinclude!)