mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Add track_env_var to the proc macro server
This commit is contained in:
parent
e5f252ade7
commit
3d169bd3f4
6 changed files with 40 additions and 1 deletions
|
@ -924,3 +924,25 @@ impl fmt::Debug for Literal {
|
|||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod tracked_env {
|
||||
use std::env::{self, VarError};
|
||||
use std::ffi::OsStr;
|
||||
|
||||
/// Retrieve an environment variable and add it to build dependency info.
|
||||
/// Build system executing the compiler will know that the variable was accessed during
|
||||
/// compilation, and will be able to rerun the build when the value of that variable changes.
|
||||
/// Besides the dependency tracking this function should be equivalent to `env::var` from the
|
||||
/// standard library, except that the argument must be UTF-8.
|
||||
pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
|
||||
use std::ops::Deref;
|
||||
|
||||
let key: &str = key.as_ref();
|
||||
let value = env::var(key);
|
||||
super::bridge::client::FreeFunctions::track_env_var(
|
||||
key,
|
||||
value.as_ref().map(|t| t.deref()).ok(),
|
||||
);
|
||||
value
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue