From 18d9fcd7ebcc2189c620fc9304cacb4d9ac313b5 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 3 May 2018 10:42:45 +0200 Subject: [PATCH] Pass Workspace directly into Config::rustc() This means we can store the cache file name in one place. --- src/cargo/core/compiler/build_config.rs | 5 +++-- src/cargo/ops/cargo_compile.rs | 5 +---- src/cargo/util/config.rs | 9 +++++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index 61e5cebe4..abd71e0fe 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use util::{CargoResult, CargoResultExt, Config, Rustc}; +use core::Workspace; use super::BuildOutput; /// Configuration information for a rustc build. @@ -35,7 +36,7 @@ impl BuildConfig { config: &Config, jobs: Option, requested_target: &Option, - rustc_info_cache: Option, + ws: Option<&Workspace>, mode: CompileMode, ) -> CargoResult { let requested_target = match requested_target { @@ -88,7 +89,7 @@ impl BuildConfig { None => None, }; let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32); - let rustc = config.rustc(rustc_info_cache)?; + let rustc = config.rustc(ws)?; let host_config = TargetConfig::new(config, &rustc.host)?; let target_config = match target.as_ref() { Some(triple) => TargetConfig::new(config, triple)?, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index ec031b526..c2dad7a78 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -229,10 +229,7 @@ pub fn compile_ws<'a>( ref export_dir, } = *options; - let rustc_info_cache = ws.target_dir() - .join(".rustc_info.json") - .into_path_unlocked(); - let mut build_config = BuildConfig::new(config, jobs, &target, Some(rustc_info_cache), mode)?; + let mut build_config = BuildConfig::new(config, jobs, &target, Some(ws), mode)?; build_config.release = release; build_config.message_format = message_format; let default_arch_kind = if build_config.requested_target.is_some() { diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 91cf39cc7..f3a1d7968 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -20,7 +20,7 @@ use toml; use lazycell::LazyCell; use core::shell::Verbosity; -use core::{CliUnstable, Shell, SourceId}; +use core::{CliUnstable, Shell, SourceId, Workspace}; use ops; use url::Url; use util::ToUrl; @@ -170,7 +170,12 @@ impl Config { } /// Get the path to the `rustc` executable - pub fn rustc(&self, cache_location: Option) -> CargoResult { + pub fn rustc(&self, ws: Option<&Workspace>) -> CargoResult { + let cache_location = ws.map(|ws| { + ws.target_dir() + .join(".rustc_info.json") + .into_path_unlocked() + }); Rustc::new( self.get_tool("rustc")?, self.maybe_get_tool("rustc_wrapper")?, -- 2.39.5