-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Avoid directly reading environment variables #11588
Comments
Hi! Can I help out with this? I played around a bit in If it'd be helpful, I'll open a PR with what I have so far as a start. |
Oops sorry, could you reopen this? I shouldn't have said "Fixes" in my PR, as there are still several places that weren't handled by #11727. |
I just opened another PR with a few call sites that I missed in #11727 but are hopefully straightforward. After that, there are still a handful of calls to
Thoughts on these? (I'm also fine just leaving them, since there's not too many remaining now after #11727.) |
Sure, sorry, I didn't realize there were more updates. |
Thanks! |
Make more reads of environment variables go through the `Config` As discussed in #11588, it's better to make reads of environment variables go through the `Config` instead of calling `std::env::var` or `env::var_os` everywhere. Most of the "easy" places to change this in `src/` were handled in #11727. This PR fixes a few remaining call sites that were missed in #11727, namely: - `LocalFingerprint::find_stale_item` - `util::profile::start` and `Profiler` - `util::rustc::rustc_fingerprint` After doing this, there are a few remaining calls to `env::var` in `src/` but those probably require more discussion to fix.
expand to see the original commentSome variables read from snapshot starting from #11727 may need a double check:
Not really relevant anymore. See the discussion. |
Cargo has a snapshot of the environment in Config.env. This environment snapshot is primarily used for loading config environment variables.
However, other environment variables (like RUSTFLAGS) do not go through the snapshot. In an effort to try to have a unified location where environment variables are accessed, we would like to consider updating the codebase so that all environment variables are read through the config snapshot.
One would need to scour the codebase for calls to the
std::env
functions (var
,var_os
,vars
, etc.). The scope of this is uncertain, since there may be some places where it is difficult to access theConfig
object. This may require some exploration to evaluate the impact.As for the API, I would consider renaming the existing
get_env
to something else (likeget_config_env
), and then adding some public methods likeget_env
orget_env_os
.The text was updated successfully, but these errors were encountered: