From: Aleksey Kladov Date: Wed, 18 Apr 2018 14:44:23 +0000 (+0300) Subject: Improve rustc cache X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~59^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1be35793963d0c38210c3ce0d5be1d71a2f46695;p=cargo.git Improve rustc cache 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. --- diff --git a/src/cargo/util/rustc.rs b/src/cargo/util/rustc.rs index 883563d2f..c6de81889 100644 --- a/src/cargo/util/rustc.rs +++ b/src/cargo/util/rustc.rs @@ -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) diff --git a/tests/testsuite/rustc_info_cache.rs b/tests/testsuite/rustc_info_cache.rs index 28d2c5dc6..b55c84a4d 100644 --- a/tests/testsuite/rustc_info_cache.rs +++ b/tests/testsuite/rustc_info_cache.rs @@ -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), );