Replace triple with struct
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 2 Apr 2018 21:36:30 +0000 (00:36 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 2 Apr 2018 21:39:03 +0000 (00:39 +0300)
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_rustc/context/compilation_files.rs
src/cargo/ops/cargo_rustc/context/mod.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/cargo_rustc/output_depinfo.rs

index 4661052255605b308838964a7b28d374846eedab..30009c7a63bf6390723130e3d206dbb25ecc645c 100644 (file)
@@ -112,9 +112,9 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
             continue;
         }
 
-        for &(ref src, ref link_dst, _) in cx.target_filenames(unit)?.iter() {
-            rm_rf(src, config)?;
-            if let Some(ref dst) = *link_dst {
+        for output in cx.outputs(unit)?.iter() {
+            rm_rf(&output.path, config)?;
+            if let Some(ref dst) = output.hardlink {
                 rm_rf(dst, config)?;
             }
         }
index 81272fe8e6fd93264b53873c3416f134d99bf9c2..d78364a3a8acd0e58a6cd6b18fdf61571d101e58 100644 (file)
@@ -29,13 +29,19 @@ pub struct CompilationFiles<'a, 'cfg: 'a> {
     pub(super) target: Option<Layout>,
     ws: &'a Workspace<'cfg>,
     metas: HashMap<Unit<'a>, Option<Metadata>>,
-    /// For each Unit, a list all files produced as a triple of
-    ///
-    ///  - File name that will be produced by the build process (in `deps`)
-    ///  - If it should be linked into `target`, and what it should be called (e.g. without
-    ///    metadata).
-    ///  - Type of the file (library / debug symbol / else)
-    outputs: HashMap<Unit<'a>, LazyCell<Arc<Vec<(PathBuf, Option<PathBuf>, FileFlavor)>>>>,
+    /// For each Unit, a list all files produced.
+    outputs: HashMap<Unit<'a>, LazyCell<Arc<Vec<OutputFile>>>>,
+}
+
+#[derive(Debug)]
+pub struct OutputFile {
+    /// File name that will be produced by the build process (in `deps`).
+    pub path: PathBuf,
+    /// If it should be linked into `target`, and what it should be called
+    /// (e.g. without metadata).
+    pub hardlink: Option<PathBuf>,
+    /// Type of the file (library / debug symbol / else).
+    pub flavor: FileFlavor,
 }
 
 impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
@@ -153,13 +159,13 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
         }
     }
 
-    pub(super) fn target_filenames(
+    pub(super) fn outputs(
         &self,
         unit: &Unit<'a>,
         cx: &Context<'a, 'cfg>,
-    ) -> CargoResult<Arc<Vec<(PathBuf, Option<PathBuf>, FileFlavor)>>> {
+    ) -> CargoResult<Arc<Vec<OutputFile>>> {
         self.outputs[unit]
-            .try_borrow_with(|| self.calc_target_filenames(unit, cx))
+            .try_borrow_with(|| self.calc_outputs(unit, cx))
             .map(Arc::clone)
     }
 
@@ -211,11 +217,11 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
         }
     }
 
-    fn calc_target_filenames(
+    fn calc_outputs(
         &self,
         unit: &Unit<'a>,
         cx: &Context<'a, 'cfg>,
-    ) -> CargoResult<Arc<Vec<(PathBuf, Option<PathBuf>, FileFlavor)>>> {
+    ) -> CargoResult<Arc<Vec<OutputFile>>> {
         let out_dir = self.out_dir(unit);
         let file_stem = self.file_stem(unit);
         let link_stem = self.link_stem(unit);
@@ -229,11 +235,15 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
         let mut unsupported = Vec::new();
         {
             if unit.profile.check {
-                let filename = out_dir.join(format!("lib{}.rmeta", file_stem));
-                let link_dst = link_stem
+                let path = out_dir.join(format!("lib{}.rmeta", file_stem));
+                let hardlink = link_stem
                     .clone()
                     .map(|(ld, ls)| ld.join(format!("lib{}.rmeta", ls)));
-                ret.push((filename, link_dst, FileFlavor::Linkable));
+                ret.push(OutputFile {
+                    path,
+                    hardlink,
+                    flavor: FileFlavor::Linkable,
+                });
             } else {
                 let mut add = |crate_type: &str, flavor: FileFlavor| -> CargoResult<()> {
                     let crate_type = if crate_type == "lib" {
@@ -250,11 +260,15 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
 
                     match file_types {
                         Some(types) => for file_type in types {
-                            let filename = out_dir.join(file_type.filename(&file_stem));
-                            let link_dst = link_stem
+                            let path = out_dir.join(file_type.filename(&file_stem));
+                            let hardlink = link_stem
                                 .as_ref()
                                 .map(|&(ref ld, ref ls)| ld.join(file_type.filename(ls)));
-                            ret.push((filename, link_dst, file_type.flavor));
+                            ret.push(OutputFile {
+                                path,
+                                hardlink,
+                                flavor: file_type.flavor,
+                            });
                         },
                         // not supported, don't worry about it
                         None => {
index 5993c9225c676a109eaae84546d792a899aa080d..f7456fa31613b92eab33c27aa4f3daa62e7a2b53 100644 (file)
@@ -2,7 +2,7 @@
 
 use std::collections::{HashMap, HashSet};
 use std::env;
-use std::path::{Path, PathBuf};
+use std::path::Path;
 use std::str::{self, FromStr};
 use std::sync::Arc;
 
@@ -24,7 +24,7 @@ mod unit_dependencies;
 use self::unit_dependencies::build_unit_dependencies;
 
 mod compilation_files;
-use self::compilation_files::CompilationFiles;
+use self::compilation_files::{CompilationFiles, OutputFile};
 pub use self::compilation_files::Metadata;
 
 mod target_info;
@@ -274,11 +274,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
     ///  - filename: filename rustc compiles to. (Often has metadata suffix).
     ///  - link_dst: Optional file to link/copy the result to (without metadata suffix)
     ///  - linkable: Whether possible to link against file (eg it's a library)
-    pub fn target_filenames(
-        &mut self,
-        unit: &Unit<'a>,
-    ) -> CargoResult<Arc<Vec<(PathBuf, Option<PathBuf>, FileFlavor)>>> {
-        self.files.as_ref().unwrap().target_filenames(unit, self)
+    pub fn outputs(&mut self, unit: &Unit<'a>) -> CargoResult<Arc<Vec<OutputFile>>> {
+        self.files.as_ref().unwrap().outputs(unit, self)
     }
 
     /// For a package, return all targets which are registered as dependencies
index 0c55df23f2e726b783898eb662dd1a7698bed401..ab4731612486ef9cd14140a3b3340bef5399a6dc 100644 (file)
@@ -91,12 +91,12 @@ pub fn prepare_target<'a, 'cfg>(
             .join("index.html")
             .exists();
     } else {
-        for &(ref src, ref link_dst, file_type) in cx.target_filenames(unit)?.iter() {
-            if file_type == FileFlavor::DebugInfo {
+        for output in cx.outputs(unit)?.iter() {
+            if output.flavor == FileFlavor::DebugInfo {
                 continue;
             }
-            missing_outputs |= !src.exists();
-            if let Some(ref link_dst) = *link_dst {
+            missing_outputs |= !output.path.exists();
+            if let Some(ref link_dst) = output.hardlink {
                 missing_outputs |= !link_dst.exists();
             }
         }
index 76b9d9afd243fa044e0cdcd9d9603097551d81e7..0e08078799a3ba473e88c6416bf5b03864a36dbb 100644 (file)
@@ -193,14 +193,14 @@ pub fn compile_targets<'a, 'cfg: 'a>(
     queue.execute(&mut cx)?;
 
     for unit in units.iter() {
-        for &(ref dst, ref link_dst, file_type) in cx.target_filenames(unit)?.iter() {
-            if file_type == FileFlavor::DebugInfo {
+        for output in cx.outputs(unit)?.iter() {
+            if output.flavor == FileFlavor::DebugInfo {
                 continue;
             }
 
-            let bindst = match *link_dst {
+            let bindst = match output.hardlink {
                 Some(ref link_dst) => link_dst,
-                None => dst,
+                None => &output.path,
             };
 
             if unit.profile.test {
@@ -208,7 +208,7 @@ pub fn compile_targets<'a, 'cfg: 'a>(
                     unit.pkg.clone(),
                     unit.target.kind().clone(),
                     unit.target.name().to_string(),
-                    dst.clone(),
+                    output.path.clone(),
                 ));
             } else if unit.target.is_bin() || unit.target.is_example() {
                 cx.compilation.binaries.push(bindst.clone());
@@ -218,7 +218,7 @@ pub fn compile_targets<'a, 'cfg: 'a>(
                     .libraries
                     .entry(pkgid)
                     .or_insert_with(HashSet::new)
-                    .insert((unit.target.clone(), dst.clone()));
+                    .insert((unit.target.clone(), output.path.clone()));
             }
         }
 
@@ -243,14 +243,15 @@ pub fn compile_targets<'a, 'cfg: 'a>(
                 continue;
             }
 
-            let v = cx.target_filenames(dep)?;
+            let outputs = cx.outputs(dep)?;
             cx.compilation
                 .libraries
                 .entry(unit.pkg.package_id().clone())
                 .or_insert_with(HashSet::new)
                 .extend(
-                    v.iter()
-                        .map(|&(ref f, _, _)| (dep.target.clone(), f.clone())),
+                    outputs
+                        .iter()
+                        .map(|output| (dep.target.clone(), output.path.clone())),
                 );
         }
 
@@ -367,7 +368,7 @@ fn rustc<'a, 'cfg>(
         rustc.arg("--cap-lints").arg("warn");
     }
 
-    let filenames = cx.target_filenames(unit)?;
+    let outputs = cx.outputs(unit)?;
     let root = cx.files().out_dir(unit);
     let kind = unit.kind;
 
@@ -427,12 +428,12 @@ fn rustc<'a, 'cfg>(
             add_custom_env(&mut rustc, &build_state, &current_id, kind)?;
         }
 
-        for &(ref filename, ref _link_dst, _linkable) in filenames.iter() {
+        for output in outputs.iter() {
             // If there is both an rmeta and rlib, rustc will prefer to use the
             // rlib, even if it is older. Therefore, we must delete the rlib to
             // force using the new rmeta.
-            if filename.extension() == Some(OsStr::new("rmeta")) {
-                let dst = root.join(filename).with_extension("rlib");
+            if output.path.extension() == Some(OsStr::new("rmeta")) {
+                let dst = root.join(&output.path).with_extension("rlib");
                 if dst.exists() {
                     paths::remove_file(&dst)?;
                 }
@@ -482,7 +483,7 @@ fn rustc<'a, 'cfg>(
         }
 
         if do_rename && real_name != crate_name {
-            let dst = &filenames[0].0;
+            let dst = &outputs[0].path;
             let src = dst.with_file_name(
                 dst.file_name()
                     .unwrap()
@@ -567,7 +568,7 @@ fn link_targets<'a, 'cfg>(
     unit: &Unit<'a>,
     fresh: bool,
 ) -> CargoResult<Work> {
-    let filenames = cx.target_filenames(unit)?;
+    let outputs = cx.outputs(unit)?;
     let package_id = unit.pkg.package_id().clone();
     let target = unit.target.clone();
     let profile = unit.profile.clone();
@@ -584,13 +585,14 @@ fn link_targets<'a, 'cfg>(
         // above. This means that `cargo build` will produce binaries in
         // `target/debug` which one probably expects.
         let mut destinations = vec![];
-        for &(ref src, ref link_dst, _file_type) in filenames.iter() {
+        for output in outputs.iter() {
+            let src = &output.path;
             // This may have been a `cargo rustc` command which changes the
             // output, so the source may not actually exist.
             if !src.exists() {
                 continue;
             }
-            let dst = match link_dst.as_ref() {
+            let dst = match output.hardlink.as_ref() {
                 Some(dst) => dst,
                 None => {
                     destinations.push(src.display().to_string());
@@ -1071,8 +1073,8 @@ fn build_deps_args<'a, 'cfg>(
         current: &Unit<'a>,
         dep: &Unit<'a>,
     ) -> CargoResult<()> {
-        for &(ref dst, _, file_type) in cx.target_filenames(dep)?.iter() {
-            if file_type != FileFlavor::Linkable {
+        for output in cx.outputs(dep)?.iter() {
+            if output.flavor != FileFlavor::Linkable {
                 continue;
             }
             let mut v = OsString::new();
@@ -1097,7 +1099,7 @@ fn build_deps_args<'a, 'cfg>(
             v.push("=");
             v.push(cx.files().out_dir(dep));
             v.push(&path::MAIN_SEPARATOR.to_string());
-            v.push(&dst.file_name().unwrap());
+            v.push(&output.path.file_name().unwrap());
             cmd.arg("--extern").arg(&v);
         }
         Ok(())
index a8a83425ef8511626764bcf8a12c7aef5898ec10..8edcd185f17187986708904c3bab6fd045af0fa3 100644 (file)
@@ -91,8 +91,8 @@ pub fn output_depinfo<'a, 'b>(context: &mut Context<'a, 'b>, unit: &Unit<'a>) ->
         .map(|f| render_filename(f, basedir))
         .collect::<CargoResult<Vec<_>>>()?;
 
-    for &(_, ref link_dst, _) in context.target_filenames(unit)?.iter() {
-        if let Some(ref link_dst) = *link_dst {
+    for output in context.outputs(unit)?.iter() {
+        if let Some(ref link_dst) = output.hardlink {
             let output_path = link_dst.with_extension("d");
             if success {
                 let target_fn = render_filename(link_dst, basedir)?;