From: Aleksey Kladov Date: Tue, 27 Mar 2018 16:03:22 +0000 (+0300) Subject: Supply units to the context at the point of creation X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~2^2~3^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1a5a38713902f2bdc190e2031892f6345253877a;p=cargo.git Supply units to the context at the point of creation --- diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 7f7d96225..bc0bc51f8 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -37,20 +37,6 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { let profiles = ws.profiles(); let host_triple = opts.config.rustc()?.host.clone(); - let mut cx = Context::new( - ws, - &resolve, - &packages, - opts.config, - BuildConfig { - host_triple, - requested_target: opts.target.clone(), - release: opts.release, - jobs: 1, - ..BuildConfig::default() - }, - profiles, - )?; let mut units = Vec::new(); for spec in opts.spec.iter() { @@ -99,8 +85,21 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { } } - cx.probe_target_info()?; - cx.build_unit_dependencies(&units)?; + let mut cx = Context::new( + ws, + &resolve, + &packages, + opts.config, + BuildConfig { + host_triple, + requested_target: opts.target.clone(), + release: opts.release, + jobs: 1, + ..BuildConfig::default() + }, + profiles, + &units, + )?; for unit in units.iter() { rm_rf(&cx.fingerprint_dir(unit), config)?; diff --git a/src/cargo/ops/cargo_rustc/context/mod.rs b/src/cargo/ops/cargo_rustc/context/mod.rs index 9fd597223..7bb9b088f 100644 --- a/src/cargo/ops/cargo_rustc/context/mod.rs +++ b/src/cargo/ops/cargo_rustc/context/mod.rs @@ -104,7 +104,7 @@ pub struct Context<'a, 'cfg: 'a> { profiles: &'a Profiles, incremental_env: Option, - unit_dependencies: Option, Vec>>>, + unit_dependencies: HashMap, Vec>>, /// For each Unit, a list all files produced as a triple of /// /// - File name that will be produced by the build process (in `deps`) @@ -154,6 +154,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { config: &'cfg Config, build_config: BuildConfig, profiles: &'a Profiles, + units: &[Unit<'a>], ) -> CargoResult> { let dest = if build_config.release { "release" @@ -184,8 +185,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { None => Client::new(build_config.jobs as usize - 1) .chain_err(|| "failed to create jobserver")?, }; - - Ok(Context { + let mut cx = Context { ws, host: host_layout, target: target_layout, @@ -208,11 +208,17 @@ impl<'a, 'cfg> Context<'a, 'cfg> { jobserver, build_script_overridden: HashSet::new(), - unit_dependencies: None, + unit_dependencies: HashMap::new(), // TODO: Pre-Calculate these with a topo-sort, rather than lazy-calculating target_filenames: HashMap::new(), target_metadatas: HashMap::new(), - }) + }; + + cx.probe_target_info()?; + let deps = build_unit_dependencies(units, &cx)?; + cx.unit_dependencies = deps; + + Ok(cx) } /// Prepare this context, ensuring that all filesystem directories are in @@ -237,15 +243,9 @@ impl<'a, 'cfg> Context<'a, 'cfg> { Ok(()) } - pub fn build_unit_dependencies(&mut self, units: &[Unit<'a>]) -> CargoResult<()> { - assert!(self.unit_dependencies.is_none()); - self.unit_dependencies = Some(build_unit_dependencies(units, self)?); - Ok(()) - } - /// Ensure that we've collected all target-specific information to compile /// all the units mentioned in `units`. - pub fn probe_target_info(&mut self) -> CargoResult<()> { + fn probe_target_info(&mut self) -> CargoResult<()> { debug!("probe_target_info"); let host_target_same = match self.requested_target() { Some(s) if s != self.config.rustc()?.host => false, @@ -809,7 +809,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { return Vec::new(); } } - self.unit_dependencies.as_ref().unwrap()[unit].clone() + self.unit_dependencies[unit].clone() } fn dep_platform_activated(&self, dep: &Dependency, kind: Kind) -> bool { diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 695b882c3..950a829be 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -164,13 +164,19 @@ pub fn compile_targets<'a, 'cfg: 'a>( }) .collect::>(); - let mut cx = Context::new(ws, resolve, packages, config, build_config, profiles)?; + let mut cx = Context::new( + ws, + resolve, + packages, + config, + build_config, + profiles, + &units, + )?; let mut queue = JobQueue::new(&cx); cx.prepare()?; - cx.probe_target_info()?; - cx.build_unit_dependencies(&units)?; cx.build_used_in_plugin_map(&units)?; custom_build::build_map(&mut cx, &units)?;