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)?;
}
}
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> {
}
}
- 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)
}
}
}
- 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);
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" {
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 => {
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;
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;
/// - 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
.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();
}
}
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 {
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());
.libraries
.entry(pkgid)
.or_insert_with(HashSet::new)
- .insert((unit.target.clone(), dst.clone()));
+ .insert((unit.target.clone(), output.path.clone()));
}
}
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())),
);
}
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;
add_custom_env(&mut rustc, &build_state, ¤t_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)?;
}
}
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()
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();
// 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());
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();
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(())
.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)?;