From: Nipunn Koorapati Date: Tue, 15 Nov 2016 19:53:24 +0000 (-0800) Subject: Merge branch 'master' into attempt X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~13^2^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d7977f881f6017ff96b9db889d830d12b788a129;p=cargo.git Merge branch 'master' into attempt - Fix instances of try! converting to ? syntax --- d7977f881f6017ff96b9db889d830d12b788a129 diff --cc src/cargo/ops/cargo_clean.rs index 738417a4b,4f6e6cf03..99b45f7c2 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@@ -74,14 -74,12 +74,14 @@@ pub fn clean(ws: &Workspace, opts: &Cle for unit in units.iter() { let layout = cx.layout(unit); - try!(rm_rf(&layout.proxy().fingerprint(&unit.pkg))); - try!(rm_rf(&layout.build(&unit.pkg))); + rm_rf(&layout.proxy().fingerprint(&unit.pkg))?; + rm_rf(&layout.build(&unit.pkg))?; - for (src, link_dst, _) in try!(cx.target_filenames(&unit)) { - try!(rm_rf(&src)); - let root = cx.out_dir(&unit); - for (filename, _) in cx.target_filenames(&unit)? { - rm_rf(&root.join(&filename))?; ++ for (src, link_dst, _) in cx.target_filenames(&unit)? { ++ rm_rf(&src)?; + if let Some(dst) = link_dst { - try!(rm_rf(&dst)); ++ rm_rf(&dst)?; + } } } diff --cc src/cargo/ops/cargo_rustc/fingerprint.rs index 1f785609f,ae0497e71..6cc8f88c1 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@@ -82,11 -82,8 +82,11 @@@ pub fn prepare_target<'a, 'cfg>(cx: &mu missing_outputs = !root.join(unit.target.crate_name()) .join("index.html").exists(); } else { - for (src, link_dst, _) in try!(cx.target_filenames(unit)) { - for (filename, _) in cx.target_filenames(unit)? { - missing_outputs |= fs::metadata(root.join(filename)).is_err(); ++ for (src, link_dst, _) in cx.target_filenames(unit)? { + missing_outputs |= !src.exists(); + if let Some(link_dst) = link_dst { + missing_outputs |= !link_dst.exists(); + } } } diff --cc src/cargo/ops/cargo_rustc/mod.rs index 435f28f5c,a7aedbe6b..02e108830 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@@ -110,12 -110,8 +110,12 @@@ pub fn compile_targets<'a, 'cfg: 'a>(ws .or_insert(Vec::new()) .push(("OUT_DIR".to_string(), out_dir)); - for (dst, link_dst, _linkable) in try!(cx.target_filenames(unit)) { - for (filename, _linkable) in cx.target_filenames(unit)? { - let dst = cx.out_dir(unit).join(filename); ++ for (dst, link_dst, _linkable) in cx.target_filenames(unit)? { + let bindst = match link_dst { + Some(link_dst) => link_dst, + None => dst.clone(), + }; + if unit.profile.test { cx.compilation.tests.push((unit.pkg.clone(), unit.target.name().to_string(), @@@ -138,9 -134,9 +138,9 @@@ continue } - let v = try!(cx.target_filenames(unit)); + let v = cx.target_filenames(unit)?; - let v = v.into_iter().map(|(f, _)| { - (unit.target.clone(), cx.out_dir(unit).join(f)) + let v = v.into_iter().map(|(f, _, _)| { + (unit.target.clone(), f) }).collect::>(); cx.compilation.libraries.insert(pkgid.clone(), v); } @@@ -177,27 -173,23 +177,27 @@@ fn compile<'a, 'cfg: 'a>(cx: &mut Conte // we've got everything constructed. let p = profile::start(format!("preparing: {}/{}", unit.pkg, unit.target.name())); - try!(fingerprint::prepare_init(cx, unit)); - try!(cx.links.validate(unit)); + fingerprint::prepare_init(cx, unit)?; + cx.links.validate(unit)?; let (dirty, fresh, freshness) = if unit.profile.run_custom_build { - try!(custom_build::prepare(cx, unit)) + custom_build::prepare(cx, unit)? } else { - let (freshness, dirty, fresh) = try!(fingerprint::prepare_target(cx, - unit)); + let (freshness, dirty, fresh) = fingerprint::prepare_target(cx, + unit)?; let work = if unit.profile.doc { - try!(rustdoc(cx, unit)) + rustdoc(cx, unit)? } else { - try!(rustc(cx, unit)) + rustc(cx, unit)? }; - let link_work1 = try!(link_targets(cx, unit)); - let link_work2 = try!(link_targets(cx, unit)); - let dirty = work.then(dirty); ++ let link_work1 = link_targets(cx, unit)?; ++ let link_work2 = link_targets(cx, unit)?; + // Need to link targets on both the dirty and fresh + let dirty = work.then(link_work1).then(dirty); + let fresh = link_work2.then(fresh); (dirty, fresh, freshness) }; - try!(jobs.enqueue(cx, unit, Job::new(dirty, fresh), freshness)); + jobs.enqueue(cx, unit, Job::new(dirty, fresh), freshness)?; drop(p); // Be sure to compile all dependencies of this target as well. @@@ -265,11 -257,12 +265,11 @@@ fn rustc(cx: &mut Context, unit: &Unit // FIXME(rust-lang/rust#18913): we probably shouldn't have to do // this manually - for &(ref filename, _linkable) in filenames.iter() { - let dst = root.join(filename); + for &(ref dst, ref _link_dst, _linkable) in filenames.iter() { if fs::metadata(&dst).is_ok() { - try!(fs::remove_file(&dst).chain_error(|| { + fs::remove_file(&dst).chain_error(|| { human(format!("Could not remove file: {}.", dst.display())) - })); + })?; } } @@@ -299,10 -292,10 +299,10 @@@ rustc.exec() }.chain_error(|| { human(format!("Could not compile `{}`.", name)) - })); + })?; if do_rename && real_name != crate_name { - let dst = root.join(&filenames[0].0); + let dst = &filenames[0].0; let src = dst.with_file_name(dst.file_name().unwrap() .to_str().unwrap() .replace(&real_name, &crate_name)); @@@ -314,14 -307,49 +314,14 @@@ } if !has_custom_args || fs::metadata(&rustc_dep_info_loc).is_ok() { + info!("Renaming dep_info {:?} to {:?}", rustc_dep_info_loc, dep_info_loc); - try!(fs::rename(&rustc_dep_info_loc, &dep_info_loc).chain_error(|| { + fs::rename(&rustc_dep_info_loc, &dep_info_loc).chain_error(|| { internal(format!("could not rename dep info: {:?}", rustc_dep_info_loc)) - })); - try!(fingerprint::append_current_dir(&dep_info_loc, &cwd)); + })?; + fingerprint::append_current_dir(&dep_info_loc, &cwd)?; } - // If we're a "root crate", e.g. the target of this compilation, then we - // hard link our outputs out of the `deps` directory into the directory - // above. This means that `cargo build` will produce binaries in - // `target/debug` which one probably expects. - if move_outputs_up { - for &(ref filename, _linkable) in filenames.iter() { - let src = root.join(filename); - // This may have been a `cargo rustc` command which changes the - // output, so the source may not actually exist. - if !src.exists() { - continue - } - - // We currently only lift files up from the `deps` directory. If - // it was compiled into something like `example/` or `doc/` then - // we don't want to link it up. - let src_dir = src.parent().unwrap(); - if !src_dir.ends_with("deps") { - continue - } - let dst = src_dir.parent().unwrap() - .join(src.file_name().unwrap()); - if dst.exists() { - fs::remove_file(&dst).chain_error(|| { - human(format!("failed to remove: {}", dst.display())) - })?; - } - fs::hard_link(&src, &dst) - .or_else(|_| fs::copy(&src, &dst).map(|_| ())) - .chain_error(|| { - human(format!("failed to link or copy `{}` to `{}`", - src.display(), dst.display())) - })?; - } - } - Ok(()) })); @@@ -355,44 -383,6 +355,44 @@@ } } +/// Link the compiled target (often of form foo-{metadata_hash}) to the +/// final target. This must happen during both "Fresh" and "Compile" +fn link_targets(cx: &mut Context, unit: &Unit) -> CargoResult { - let filenames = try!(cx.target_filenames(unit)); ++ let filenames = cx.target_filenames(unit)?; + Ok(Work::new(move |_| { + // If we're a "root crate", e.g. the target of this compilation, then we + // hard link our outputs out of the `deps` directory into the directory + // above. This means that `cargo build` will produce binaries in + // `target/debug` which one probably expects. + for (src, link_dst, _linkable) in filenames { + // This may have been a `cargo rustc` command which changes the + // output, so the source may not actually exist. + debug!("Thinking about linking {} to {:?}", src.display(), link_dst); + if !src.exists() || link_dst.is_none() { + continue + } + let dst = link_dst.unwrap(); + + debug!("linking {} to {}", src.display(), dst.display()); + if dst.exists() { - try!(fs::remove_file(&dst).chain_error(|| { ++ fs::remove_file(&dst).chain_error(|| { + human(format!("failed to remove: {}", dst.display())) - })); ++ })?; + } - try!(fs::hard_link(&src, &dst) ++ fs::hard_link(&src, &dst) + .or_else(|err| { + debug!("hard link failed {}. falling back to fs::copy", err); + fs::copy(&src, &dst).map(|_| ()) + }) + .chain_error(|| { + human(format!("failed to link or copy `{}` to `{}`", + src.display(), dst.display())) - })); ++ })?; + } + Ok(()) + })) +} + fn load_build_deps(cx: &Context, unit: &Unit) -> Option> { cx.build_scripts.get(unit).cloned() } @@@ -668,7 -658,7 +668,7 @@@ fn build_deps_args(cmd: &mut ProcessBui fn link_to(cmd: &mut ProcessBuilder, cx: &Context, unit: &Unit) -> CargoResult<()> { - for (dst, _link_dst, linkable) in try!(cx.target_filenames(unit)) { - for (filename, linkable) in cx.target_filenames(unit)? { ++ for (dst, _link_dst, linkable) in cx.target_filenames(unit)? { if !linkable { continue }