Add env-var to suppress rustc caching
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 14 Apr 2018 11:09:23 +0000 (14:09 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 14 Apr 2018 11:09:23 +0000 (14:09 +0300)
src/cargo/util/config.rs
src/doc/src/reference/environment-variables.md
tests/testsuite/rustc_info_cache.rs

index 4596f07c143f770b9233ec69e27f26cb28fcfd6d..1dfefb8c8aef0b30de0cccd5fc45c2ce6bea09c7 100644 (file)
@@ -66,6 +66,9 @@ pub struct Config {
     easy: LazyCell<RefCell<Easy>>,
     /// Cache of the `SourceId` for crates.io
     crates_io_source_id: LazyCell<SourceId>,
+    /// If false, don't cache `rustc --version --verbose` invocations
+    cache_rustc_info: bool,
+    /// Creation time of this config, used to output the total build time
     creation_time: Instant,
 }
 
@@ -82,6 +85,11 @@ impl Config {
             }
         });
 
+        let cache_rustc_info = match env::var("CARGO_CACHE_RUSTC_INFO") {
+            Ok(cache) => cache != "0",
+            _ => true,
+        };
+
         Config {
             home_path: Filesystem::new(homedir),
             shell: RefCell::new(shell),
@@ -103,6 +111,7 @@ impl Config {
             cli_flags: CliUnstable::default(),
             easy: LazyCell::new(),
             crates_io_source_id: LazyCell::new(),
+            cache_rustc_info,
             creation_time: Instant::now(),
         }
     }
@@ -162,7 +171,11 @@ impl Config {
         Rustc::new(
             self.get_tool("rustc")?,
             self.maybe_get_tool("rustc_wrapper")?,
-            cache_location,
+            if self.cache_rustc_info {
+                cache_location
+            } else {
+                None
+            },
         )
     }
 
index b5f81e2d224a34e98b82840e43574b6b710e9959..3b505faa2e394bb288c7cf9069eeefd186299c92 100644 (file)
@@ -9,29 +9,31 @@ with them:
 You can override these environment variables to change Cargo's behavior on your
 system:
 
-* `CARGO_HOME` - Cargo maintains a local cache of the registry index and of git
+* `CARGO_HOME`  Cargo maintains a local cache of the registry index and of git
   checkouts of crates.  By default these are stored under `$HOME/.cargo`, but
   this variable overrides the location of this directory. Once a crate is cached
   it is not removed by the clean command.
-* `CARGO_TARGET_DIR` - Location of where to place all generated artifacts,
+* `CARGO_TARGET_DIR`  Location of where to place all generated artifacts,
   relative to the current working directory.
-* `RUSTC` - Instead of running `rustc`, Cargo will execute this specified
+* `RUSTC`  Instead of running `rustc`, Cargo will execute this specified
   compiler instead.
-* `RUSTC_WRAPPER` - Instead of simply running `rustc`, Cargo will execute this
+* `RUSTC_WRAPPER`  Instead of simply running `rustc`, Cargo will execute this
   specified wrapper instead, passing as its commandline arguments the rustc
   invocation, with the first argument being rustc.
-* `RUSTDOC` - Instead of running `rustdoc`, Cargo will execute this specified
+* `RUSTDOC`  Instead of running `rustdoc`, Cargo will execute this specified
   `rustdoc` instance instead.
-* `RUSTDOCFLAGS` - A space-separated list of custom flags to pass to all `rustdoc`
+* `RUSTDOCFLAGS`  A space-separated list of custom flags to pass to all `rustdoc`
   invocations that Cargo performs. In contrast with `cargo rustdoc`, this is
   useful for passing a flag to *all* `rustdoc` instances.
-* `RUSTFLAGS` - A space-separated list of custom flags to pass to all compiler
+* `RUSTFLAGS`  A space-separated list of custom flags to pass to all compiler
   invocations that Cargo performs. In contrast with `cargo rustc`, this is
   useful for passing a flag to *all* compiler instances.
-* `CARGO_INCREMENTAL` - If this is set to 1 then Cargo will force incremental
+* `CARGO_INCREMENTAL`  If this is set to 1 then Cargo will force incremental
   compilation to be enabled for the current compilation, and when set to 0 it
   will force disabling it. If this env var isn't present then cargo's defaults
   will otherwise be used.
+* `CARGO_CACHE_RUSTC_INFO` — If this is set to 0 then Cargo will not try to cache 
+  compiler version information.
 
 Note that Cargo will also read environment variables for `.cargo/config`
 configuration values, as described in [that documentation][config-env]
index 7d3bcb5e17df37c2515d6d22b5ce9b877af82437..28d2c5dc631d4dd59f5eba0575ae5440895dbaa6 100644 (file)
@@ -19,7 +19,9 @@ fn rustc_info_cache() {
         .build();
 
     let miss = "[..] rustc info cache miss[..]";
-    let hit = "[..] rustc info cache hit[..]";
+    let hit = "[..]rustc info cache hit[..]";
+    let uncached = "[..]rustc info uncached[..]";
+    let update = "[..]updated rustc info cache[..]";
 
     assert_that(
         p.cargo("build").env("RUST_LOG", "cargo::util::rustc=info"),
@@ -27,7 +29,8 @@ fn rustc_info_cache() {
             .with_status(0)
             .with_stderr_contains("[..]failed to read rustc info cache[..]")
             .with_stderr_contains(miss)
-            .with_stderr_does_not_contain(hit),
+            .with_stderr_does_not_contain(hit)
+            .with_stderr_contains(update),
     );
 
     assert_that(
@@ -36,7 +39,19 @@ fn rustc_info_cache() {
             .with_status(0)
             .with_stderr_contains("[..]reusing existing rustc info cache[..]")
             .with_stderr_contains(hit)
-            .with_stderr_does_not_contain(miss),
+            .with_stderr_does_not_contain(miss)
+            .with_stderr_does_not_contain(update),
+    );
+
+    assert_that(
+        p.cargo("build")
+            .env("RUST_LOG", "cargo::util::rustc=info")
+            .env("CARGO_CACHE_RUSTC_INFO", "0"),
+        execs()
+            .with_status(0)
+            .with_stderr_contains("[..]rustc info cache disabled[..]")
+            .with_stderr_contains(uncached)
+            .with_stderr_does_not_contain(update),
     );
 
     let other_rustc = {
@@ -80,7 +95,8 @@ fn rustc_info_cache() {
             .with_status(0)
             .with_stderr_contains("[..]different compiler, creating new rustc info cache[..]")
             .with_stderr_contains(miss)
-            .with_stderr_does_not_contain(hit),
+            .with_stderr_does_not_contain(hit)
+            .with_stderr_contains(update),
     );
 
     assert_that(
@@ -91,7 +107,8 @@ fn rustc_info_cache() {
             .with_status(0)
             .with_stderr_contains("[..]reusing existing rustc info cache[..]")
             .with_stderr_contains(hit)
-            .with_stderr_does_not_contain(miss),
+            .with_stderr_does_not_contain(miss)
+            .with_stderr_does_not_contain(update),
     );
 
     other_rustc.move_into_the_future();
@@ -104,7 +121,8 @@ fn rustc_info_cache() {
             .with_status(0)
             .with_stderr_contains("[..]different compiler, creating new rustc info cache[..]")
             .with_stderr_contains(miss)
-            .with_stderr_does_not_contain(hit),
+            .with_stderr_does_not_contain(hit)
+            .with_stderr_contains(update),
     );
 
     assert_that(
@@ -115,6 +133,7 @@ fn rustc_info_cache() {
             .with_status(0)
             .with_stderr_contains("[..]reusing existing rustc info cache[..]")
             .with_stderr_contains(hit)
-            .with_stderr_does_not_contain(miss),
+            .with_stderr_does_not_contain(miss)
+            .with_stderr_does_not_contain(update),
     );
 }