Improve rustc cache
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 18 Apr 2018 14:44:23 +0000 (17:44 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 18 Apr 2018 14:44:23 +0000 (17:44 +0300)
Even if we've failed to calculate fingerprint and thus can't persist
cache to disk, it is still valid to cache rustc output within single
process.

src/cargo/util/rustc.rs
tests/testsuite/rustc_info_cache.rs

index 883563d2fd94bc4b5764d70958efa5a7d09a8fdc..c6de81889d9a1e907a0dc9374f0bbfbfdb403fa7 100644 (file)
@@ -154,19 +154,6 @@ impl Cache {
     }
 
     fn cached_output(&mut self, cmd: &ProcessBuilder) -> CargoResult<(String, String)> {
-        let calculate = || {
-            let output = cmd.exec_with_output()?;
-            let stdout = String::from_utf8(output.stdout)
-                .map_err(|_| internal("rustc didn't return utf8 output"))?;
-            let stderr = String::from_utf8(output.stderr)
-                .map_err(|_| internal("rustc didn't return utf8 output"))?;
-            Ok((stdout, stderr))
-        };
-        if self.cache_location.is_none() {
-            info!("rustc info uncached");
-            return calculate();
-        }
-
         let key = process_fingerprint(cmd);
         match self.data.outputs.entry(key) {
             Entry::Occupied(entry) => {
@@ -175,7 +162,12 @@ impl Cache {
             }
             Entry::Vacant(entry) => {
                 info!("rustc info cache miss");
-                let output = calculate()?;
+                let output = cmd.exec_with_output()?;
+                let stdout = String::from_utf8(output.stdout)
+                    .map_err(|_| internal("rustc didn't return utf8 output"))?;
+                let stderr = String::from_utf8(output.stderr)
+                    .map_err(|_| internal("rustc didn't return utf8 output"))?;
+                let output = (stdout, stderr);
                 entry.insert(output.clone());
                 self.dirty = true;
                 Ok(output)
index 28d2c5dc631d4dd59f5eba0575ae5440895dbaa6..b55c84a4de3a135cf9ee7231e96a479e2b991419 100644 (file)
@@ -20,7 +20,6 @@ fn rustc_info_cache() {
 
     let miss = "[..] rustc info cache miss[..]";
     let hit = "[..]rustc info cache hit[..]";
-    let uncached = "[..]rustc info uncached[..]";
     let update = "[..]updated rustc info cache[..]";
 
     assert_that(
@@ -50,7 +49,6 @@ fn rustc_info_cache() {
         execs()
             .with_status(0)
             .with_stderr_contains("[..]rustc info cache disabled[..]")
-            .with_stderr_contains(uncached)
             .with_stderr_does_not_contain(update),
     );