diff options
author | Laurențiu Nicola <[email protected]> | 2020-08-03 11:57:04 +0100 |
---|---|---|
committer | Laurențiu Nicola <[email protected]> | 2020-10-08 15:06:20 +0100 |
commit | 3d169bd3f4cdc2dc3dd09eadbbc17c19214d69f3 (patch) | |
tree | 8e8d829f5926401ac8303001fb435b504311c203 /crates/proc_macro_srv/src/proc_macro/mod.rs | |
parent | e5f252ade72fee4776396122dc91a17ddc185a66 (diff) |
Add track_env_var to the proc macro server
Diffstat (limited to 'crates/proc_macro_srv/src/proc_macro/mod.rs')
-rw-r--r-- | crates/proc_macro_srv/src/proc_macro/mod.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/proc_macro_srv/src/proc_macro/mod.rs b/crates/proc_macro_srv/src/proc_macro/mod.rs index ee0dc9722..fc6e7344f 100644 --- a/crates/proc_macro_srv/src/proc_macro/mod.rs +++ b/crates/proc_macro_srv/src/proc_macro/mod.rs | |||
@@ -924,3 +924,25 @@ impl fmt::Debug for Literal { | |||
924 | self.0.fmt(f) | 924 | self.0.fmt(f) |
925 | } | 925 | } |
926 | } | 926 | } |
927 | |||
928 | pub mod tracked_env { | ||
929 | use std::env::{self, VarError}; | ||
930 | use std::ffi::OsStr; | ||
931 | |||
932 | /// Retrieve an environment variable and add it to build dependency info. | ||
933 | /// Build system executing the compiler will know that the variable was accessed during | ||
934 | /// compilation, and will be able to rerun the build when the value of that variable changes. | ||
935 | /// Besides the dependency tracking this function should be equivalent to `env::var` from the | ||
936 | /// standard library, except that the argument must be UTF-8. | ||
937 | pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> { | ||
938 | use std::ops::Deref; | ||
939 | |||
940 | let key: &str = key.as_ref(); | ||
941 | let value = env::var(key); | ||
942 | super::bridge::client::FreeFunctions::track_env_var( | ||
943 | key, | ||
944 | value.as_ref().map(|t| t.deref()).ok(), | ||
945 | ); | ||
946 | value | ||
947 | } | ||
948 | } | ||