]> git.lizzy.rs Git - rust.git/commitdiff
Add track_env_var to the proc macro server
authorLaurențiu Nicola <lnicola@dend.ro>
Mon, 3 Aug 2020 10:57:04 +0000 (13:57 +0300)
committerLaurențiu Nicola <lnicola@dend.ro>
Thu, 8 Oct 2020 14:06:20 +0000 (17:06 +0300)
crates/proc_macro_srv/src/proc_macro/bridge/client.rs
crates/proc_macro_srv/src/proc_macro/bridge/mod.rs
crates/proc_macro_srv/src/proc_macro/bridge/server.rs
crates/proc_macro_srv/src/proc_macro/mod.rs
crates/proc_macro_srv/src/rustc_server.rs
xtask/src/install.rs

index cb4b3bdb0d3eb8f99f2118cde2eb177fd3697e3c..55d6330cc3186a162711eacbf71c055f3c5590aa 100644 (file)
@@ -160,6 +160,7 @@ fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
 }
 define_handles! {
     'owned:
+    FreeFunctions,
     TokenStream,
     TokenStreamBuilder,
     TokenStreamIter,
index aeb05aad44810aed89ef19d1a64a31c3b2340d5b..b97886eb9483bf0f89365e72194d50e0de144a92 100644 (file)
 macro_rules! with_api {
     ($S:ident, $self:ident, $m:ident) => {
         $m! {
+            FreeFunctions {
+                fn drop($self: $S::FreeFunctions);
+                fn track_env_var(var: &str, value: Option<&str>);
+            },
             TokenStream {
                 fn drop($self: $S::TokenStream);
                 fn clone($self: &$S::TokenStream) -> $S::TokenStream;
index 45d41ac02b805ac346cc0fff39b8c43572cfb66d..3acb239af6c8045ac572096223b2a88dc86d7808 100644 (file)
@@ -11,6 +11,8 @@
 /// Declare an associated item of one of the traits below, optionally
 /// adjusting it (i.e., adding bounds to types and default bodies to methods).
 macro_rules! associated_item {
+    (type FreeFunctions) =>
+        (type FreeFunctions: 'static;);
     (type TokenStream) =>
         (type TokenStream: 'static + Clone;);
     (type TokenStreamBuilder) =>
index ee0dc97223c0302bb169c3131c5ae48d3aa755f9..fc6e7344f74a8138c111300168e5865cae8be964 100644 (file)
@@ -924,3 +924,25 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         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
+    }
+}
index 7d1695c86a8f33037f701eb08e6062e04e0db405..c5fe3591e508bb21a8d411502e1c1c714c7ba36d 100644 (file)
@@ -242,6 +242,8 @@ fn build(self) -> TokenStream {
     }
 }
 
+pub struct FreeFunctions;
+
 #[derive(Clone)]
 pub struct TokenStreamIter {
     trees: IntoIter<TokenTree>,
@@ -254,6 +256,7 @@ pub struct Rustc {
 }
 
 impl server::Types for Rustc {
+    type FreeFunctions = FreeFunctions;
     type TokenStream = TokenStream;
     type TokenStreamBuilder = TokenStreamBuilder;
     type TokenStreamIter = TokenStreamIter;
@@ -267,6 +270,13 @@ impl server::Types for Rustc {
     type MultiSpan = Vec<Span>;
 }
 
+impl server::FreeFunctions for Rustc {
+    fn track_env_var(&mut self, _var: &str, _value: Option<&str>) {
+        // FIXME: track env var accesses
+        // https://github.com/rust-lang/rust/pull/71858
+    }
+}
+
 impl server::TokenStream for Rustc {
     fn new(&mut self) -> Self::TokenStream {
         Self::TokenStream::new()
index d829790d7883dcd584bd0ed2bd88e77f0292f57e..fcc4f05e4ca4b562d680b33629c1bfd2d6a89c46 100644 (file)
@@ -7,7 +7,7 @@
 use crate::not_bash::{pushd, run};
 
 // Latest stable, feel free to send a PR if this lags behind.
-const REQUIRED_RUST_VERSION: u32 = 46;
+const REQUIRED_RUST_VERSION: u32 = 47;
 
 pub struct InstallCmd {
     pub client: Option<ClientOpt>,