Stop capturing output of all dependencies

There are some competing concerns when it comes to the output of compiling
dependencies:

* Not capturing anything leads to getting drowned in unrelated output
* Capturing requires coloration be compromised because of the way windows
  terminal colors are implemented.
* Path dependencies are often developed in tandem with the rest of a package,
  and capturing their output is not always desired.

To address these concerns, cargo previously captured output of dependent
compilations and then re-printed it to the screen if an error occurred. This
patch modifies the behavior to as follows:

* No output is captured. This preserves any coloration rustc provides.
* All dependencies are compiled with `-Awarnings`. This should suppress any
  extraneous output from the compiler and it is considered a bug otherwise if
  the compiler prints a warnings when `-Awarnings` is specified.
* All *path* dependencies (`path="..."`, overrides, etc) are *not* compiled with
  `-Awarnings`. The reason for this is that you are always in control of these
  packages and probably want to see warnings anyway.

Closes #490
Closes #496
This commit is contained in:
Alex Crichton 2014-09-21 10:22:46 -07:00
parent 275c97c8b0
commit 541a535f71
4 changed files with 46 additions and 14 deletions

View file

@ -25,6 +25,7 @@ host=static-rust-lang-org.s3.amazonaws.com
# just install the right ones? This should enable cross compilation in the
# future anyway.
if [ -z "${windows}" ]; then
rm -rf rustc *.tar.gz
curl -O https://$host/dist/rust-nightly-i686-$target.tar.gz
curl -O https://$host/dist/rust-nightly-x86_64-$target.tar.gz
tar xfz rust-nightly-i686-$target.tar.gz
@ -49,6 +50,7 @@ if [ -z "${windows}" ]; then
rm -f rust-nightly-i686-$target.tar.gz
rm -f rust-nightly-x86_64-$target.tar.gz
else
rm -rf rustc *.exe
if [ "${BITS}" = "64" ]; then
triple=x86_64-w64-mingw32
else

View file

@ -237,26 +237,19 @@ fn rustc(package: &Package, target: &Target,
log!(5, "root={}; target={}; crate_types={}; verbose={}; req={}",
root.display(), target, crate_types, cx.primary, req);
let primary = cx.primary;
let rustcs = try!(prepare_rustc(package, target, crate_types, cx, req));
Ok(rustcs.into_iter().map(|(rustc, kind)| {
let name = package.get_name().to_string();
let desc = rustc.to_string();
let is_path_source = package.get_package_id().get_source_id().is_path();
let show_warnings = cx.primary || is_path_source;
let rustc = if show_warnings {rustc} else {rustc.arg("-Awarnings")};
(proc() {
if primary {
log!(5, "executing primary");
try!(rustc.exec().chain_error(|| {
human(format!("Could not compile `{}`.", name))
}))
} else {
log!(5, "executing deps");
try!(rustc.exec_with_output().and(Ok(())).map_err(|err| {
caused_human(format!("Could not compile `{}`.\n{}",
name, err.output().unwrap()), err)
}))
}
try!(rustc.exec().chain_error(|| {
human(format!("Could not compile `{}`.", name))
}));
Ok(())
}, kind, desc)
}).collect())

View file

@ -213,7 +213,11 @@ test!(cargo_compile_with_warnings_in_a_dep_package {
{} foo v0.5.0 ({})\n",
COMPILING, p.url(),
COMPILING, p.url()))
.with_stderr(""));
.with_stderr("\
[..]warning: code is never used: `dead`[..]
[..]fn dead() {}
"));
assert_that(&p.bin("foo"), existing_file());

View file

@ -1273,3 +1273,36 @@ test!(fetch_downloads {
assert_that(p.process(cargo_dir().join("cargo")).arg("fetch"),
execs().with_status(0).with_stdout(""));
})
test!(warnings_in_git_dep {
let bar = git_repo("bar", |project| {
project.file("Cargo.toml", r#"
[package]
name = "bar"
version = "0.5.0"
authors = ["wycats@example.com"]
"#)
.file("src/lib.rs", "fn unused() {}")
}).assert();
let p = project("foo")
.file("Cargo.toml", format!(r#"
[project]
name = "foo"
version = "0.5.0"
authors = []
[dependencies.bar]
git = '{}'
"#, bar.url()).as_slice())
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("build"),
execs()
.with_stdout(format!("{} git repository `{}`\n\
{} bar v0.5.0 ({}#[..])\n\
{} foo v0.5.0 ({})\n",
UPDATING, bar.url(),
COMPILING, bar.url(),
COMPILING, p.url()))
.with_stderr(""));
})