From 20920c01315003e5bc34ff0ca41d55a44e6ec07e Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Tue, 9 Oct 2018 16:30:13 -0400 Subject: [PATCH] Prefix build script output with crate name when running in extra verbose mode. Fixes #6158. cargo's extra verbose mode is useful for getting detailed information out of builds in CI where it can be difficult to examine the build environment after-the-fact. However, when multiple build scripts are running as part of a build it's not always clear what output is from which build script. This patch makes cargo prefix each line of build script output with the crate name and version this case. --- src/cargo/core/compiler/custom_build.rs | 3 ++- src/cargo/core/compiler/job_queue.rs | 6 +++-- src/cargo/core/compiler/mod.rs | 4 ++-- tests/testsuite/build_script.rs | 4 ++-- tests/testsuite/metabuild.rs | 30 ++++++++++++------------- tests/testsuite/profile_targets.rs | 25 ++++++++++----------- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 58bdd7c76a4d..cb4a4537ce61 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -326,7 +326,8 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes } else { state.running(&cmd); let output = if extra_verbose { - state.capture_output(&cmd, true) + let prefix = format!("[{} {}] ", id.name(), id.version()); + state.capture_output(&cmd, Some(prefix), true) } else { cmd.exec_with_output() }; diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index 94aa2a58f157..1bb654d1f2d7 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -112,15 +112,17 @@ impl<'a> JobState<'a> { pub fn capture_output( &self, cmd: &ProcessBuilder, + prefix: Option, print_output: bool, ) -> CargoResult { + let prefix = prefix.unwrap_or_else(|| String::new()); cmd.exec_with_streaming( &mut |out| { - let _ = self.tx.send(Message::Stdout(out.to_string())); + let _ = self.tx.send(Message::Stdout(format!("{}{}", prefix, out))); Ok(()) }, &mut |err| { - let _ = self.tx.send(Message::Stderr(err.to_string())); + let _ = self.tx.send(Message::Stderr(format!("{}{}", prefix, err))); Ok(()) }, print_output, diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 474094468ddf..59834c409150 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -118,7 +118,7 @@ impl Executor for DefaultExecutor { _mode: CompileMode, state: &job_queue::JobState<'_>, ) -> CargoResult<()> { - state.capture_output(&cmd, false).map(drop) + state.capture_output(&cmd, None, false).map(drop) } } @@ -645,7 +645,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult false, ).map(drop) } else { - state.capture_output(&rustdoc, false).map(drop) + state.capture_output(&rustdoc, None, false).map(drop) }; exec_result.chain_err(|| format!("Could not document `{}`.", name))?; Ok(()) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 22052d3c26d6..0f41f355ad81 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -2803,13 +2803,13 @@ fn output_shows_on_vv() { ).build(); p.cargo("build -vv") - .with_stdout("stdout") + .with_stdout("[foo 0.5.0] stdout") .with_stderr( "\ [COMPILING] foo v0.5.0 ([..]) [RUNNING] `rustc [..]` [RUNNING] `[..]` -stderr +[foo 0.5.0] stderr [RUNNING] `rustc [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", diff --git a/tests/testsuite/metabuild.rs b/tests/testsuite/metabuild.rs index 53b8836a0c07..6420edac6577 100644 --- a/tests/testsuite/metabuild.rs +++ b/tests/testsuite/metabuild.rs @@ -72,8 +72,8 @@ fn metabuild_basic() { let p = basic_project(); p.cargo("build -vv") .masquerade_as_nightly_cargo() - .with_stdout_contains("Hello mb") - .with_stdout_contains("Hello mb-other") + .with_stdout_contains("[foo 0.0.1] Hello mb") + .with_stdout_contains("[foo 0.0.1] Hello mb-other") .run(); } @@ -164,12 +164,12 @@ fn metabuild_optional_dep() { p.cargo("build -vv") .masquerade_as_nightly_cargo() - .with_stdout_does_not_contain("Hello mb") + .with_stdout_does_not_contain("[foo 0.0.1] Hello mb") .run(); p.cargo("build -vv --features mb") .masquerade_as_nightly_cargo() - .with_stdout_contains("Hello mb") + .with_stdout_contains("[foo 0.0.1] Hello mb") .run(); } @@ -206,7 +206,7 @@ fn metabuild_lib_name() { p.cargo("build -vv") .masquerade_as_nightly_cargo() - .with_stdout_contains("Hello mb") + .with_stdout_contains("[foo 0.0.1] Hello mb") .run(); } @@ -235,12 +235,12 @@ fn metabuild_fresh() { p.cargo("build -vv") .masquerade_as_nightly_cargo() - .with_stdout_contains("Hello mb") + .with_stdout_contains("[foo 0.0.1] Hello mb") .run(); p.cargo("build -vv") .masquerade_as_nightly_cargo() - .with_stdout_does_not_contain("Hello mb") + .with_stdout_does_not_contain("[foo 0.0.1] Hello mb") .with_stderr( "\ [FRESH] mb [..] @@ -279,7 +279,7 @@ fn metabuild_links() { p.cargo("build -vv") .masquerade_as_nightly_cargo() - .with_stdout_contains("Hello mb") + .with_stdout_contains("[foo 0.0.1] Hello mb") .run(); } @@ -376,10 +376,10 @@ fn metabuild_workspace() { p.cargo("build -vv --all") .masquerade_as_nightly_cargo() - .with_stdout_contains("Hello mb1 [..]member1") - .with_stdout_contains("Hello mb2 [..]member1") - .with_stdout_contains("Hello mb1 [..]member2") - .with_stdout_does_not_contain("Hello mb2 [..]member2") + .with_stdout_contains("[member1 0.0.1] Hello mb1 [..]member1") + .with_stdout_contains("[member1 0.0.1] Hello mb2 [..]member1") + .with_stdout_contains("[member2 0.0.1] Hello mb1 [..]member2") + .with_stdout_does_not_contain("[member2 0.0.1] Hello mb2 [..]member2") .run(); } @@ -572,8 +572,8 @@ fn metabuild_two_versions() { p.cargo("build -vv --all") .masquerade_as_nightly_cargo() - .with_stdout_contains("Hello mb1 [..]member1") - .with_stdout_contains("Hello mb2 [..]member2") + .with_stdout_contains("[member1 0.0.1] Hello mb1 [..]member1") + .with_stdout_contains("[member2 0.0.1] Hello mb2 [..]member2") .run(); assert_eq!( @@ -628,7 +628,7 @@ fn metabuild_external_dependency() { p.cargo("build -vv") .masquerade_as_nightly_cargo() - .with_stdout_contains("Hello mb") + .with_stdout_contains("[dep 1.0.0] Hello mb") .run(); assert_eq!( diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index a62a2da87866..225d4efe9da7 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -83,7 +83,7 @@ fn profile_selection_build() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` -foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 +[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=dep-info,link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] [FINISHED] dev [unoptimized + debuginfo] [..] @@ -113,7 +113,7 @@ fn profile_selection_build_release() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..]/target/release/build/foo-[..]/build-script-build` -foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 +[foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [FINISHED] release [optimized] [..] @@ -174,8 +174,8 @@ fn profile_selection_build_all_targets() { [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` -foo custom build PROFILE=debug DEBUG=false OPT_LEVEL=3 -foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 +[foo 0.0.1] foo custom build PROFILE=debug DEBUG=false OPT_LEVEL=3 +[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..]` [RUNNING] `rustc --crate-name foo src/lib.rs [..]--emit=dep-info,link -C codegen-units=3 -C debuginfo=2 --test [..]` [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..]` @@ -241,7 +241,7 @@ fn profile_selection_build_all_targets_release() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..]/target/release/build/foo-[..]/build-script-build` -foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 +[foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C opt-level=3 -C panic=abort -C codegen-units=2 [..]` [RUNNING] `rustc --crate-name foo src/lib.rs [..]--emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..]` [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..]` @@ -296,7 +296,7 @@ fn profile_selection_test() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` -foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 +[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--emit=dep-info,link -C codegen-units=3 -C debuginfo=2 --test [..] @@ -360,7 +360,7 @@ fn profile_selection_test_release() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..]/target/release/build/foo-[..]/build-script-build` -foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 +[foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..] @@ -424,7 +424,7 @@ fn profile_selection_bench() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..]target/release/build/foo-[..]/build-script-build` -foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 +[foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..] @@ -493,7 +493,7 @@ fn profile_selection_check_all_targets() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..]target/debug/build/foo-[..]/build-script-build` -foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 +[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,metadata -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,metadata -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--emit=dep-info,metadata -C codegen-units=1 -C debuginfo=2 --test [..] @@ -543,7 +543,7 @@ fn profile_selection_check_all_targets_release() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..]target/release/build/foo-[..]/build-script-build` -foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 +[foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,metadata -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,metadata -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--emit=dep-info,metadata -C opt-level=3 -C codegen-units=2 --test [..] @@ -607,14 +607,13 @@ fn profile_selection_check_all_targets_test() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..]target/debug/build/foo-[..]/build-script-build` -foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 +[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=dep-info,metadata -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `rustc --crate-name foo src/lib.rs [..]--emit=dep-info,metadata -C codegen-units=1 -C debuginfo=2 --test [..] [RUNNING] `rustc --crate-name test1 tests/test1.rs [..]--emit=dep-info,metadata -C codegen-units=1 -C debuginfo=2 --test [..] [RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=dep-info,metadata -C codegen-units=1 -C debuginfo=2 --test [..] [RUNNING] `rustc --crate-name bench1 benches/bench1.rs [..]--emit=dep-info,metadata -C codegen-units=1 -C debuginfo=2 --test [..] [RUNNING] `rustc --crate-name ex1 examples/ex1.rs [..]--emit=dep-info,metadata -C codegen-units=1 -C debuginfo=2 --test [..] -[FINISHED] dev [unoptimized + debuginfo] [..] ").run(); p.cargo("check --all-targets --profile=test -vv") @@ -653,7 +652,7 @@ fn profile_selection_doc() { [COMPILING] foo [..] [RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..]target/debug/build/foo-[..]/build-script-build` -foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 +[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [DOCUMENTING] foo [..] [RUNNING] `rustdoc --crate-name foo src/lib.rs [..] [FINISHED] dev [unoptimized + debuginfo] [..]