Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix build script output with crate name when running in extra verbose mode. Fixes #6158. #6164

Merged
merged 2 commits into from
Oct 19, 2018

Conversation

luser
Copy link
Contributor

@luser luser commented Oct 11, 2018

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
in this case.

I put together a simple test crate for this. Building that crate on my machine with stable cargo produces:

luser@eye7:/build/snippet$ cargo build -vv
   Compiling one v0.1.0 (file:///build/snippet/one)
   Compiling two v0.1.0 (file:///build/snippet/two)
       Fresh itoa v0.3.4
     Running `rustc --crate-name build_script_build one/build.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8e5ff38061b98562 -C extra-filename=-8e5ff38061b98562 --out-dir /build/snippet/target/debug/build/one-8e5ff38061b98562 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name build_script_build two/build.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fcd8c089040e6ff4 -C extra-filename=-fcd8c089040e6ff4 --out-dir /build/snippet/target/debug/build/two-fcd8c089040e6ff4 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `/build/snippet/target/debug/build/two-fcd8c089040e6ff4/build-script-build`
     Running `/build/snippet/target/debug/build/one-8e5ff38061b98562/build-script-build`
Error 0
Output 0
Output 0
Error 0
Output 1
Error 1
Error 1
Output 1
Error 2
Output 2
Error 2
Output 2
Error 3
Output 3
Error 3
Output 3
Error 4
Error 4
Output 4
Output 4
Error 5
Error 5
Output 5
Output 5
Error 6
Output 6
Error 6
Output 6
Error 7
Output 7
Error 7
Output 7
Error 8
Error 8
Output 8
Output 8
Error 9
Output 9
Error 9
Output 9
     Running `rustc --crate-name two two/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=904ea56f5613ae62 -C extra-filename=-904ea56f5613ae62 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name one one/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c2b76a52468c9a0b -C extra-filename=-c2b76a52468c9a0b --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
   Compiling snippet v0.1.4-alpha.0 (file:///build/snippet)
     Running `rustc --crate-name snippet src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=a5c6abeab1e38e11 -C extra-filename=-a5c6abeab1e38e11 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
     Running `rustc --crate-name snippet src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8b5a0b44264aa67c -C extra-filename=-8b5a0b44264aa67c --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern snippet=/build/snippet/target/debug/deps/libsnippet-a5c6abeab1e38e11.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 0.76s

Building that crate with my local cargo including this change produces:

luser@eye7:/build/snippet$ /build/cargo/target/debug/cargo build -vv
   Compiling one v0.1.0 (/build/snippet/one)                                                         
   Compiling two v0.1.0 (/build/snippet/two)                                                         
   Compiling itoa v0.3.4                                                                             
     Running `rustc --crate-name build_script_build one/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8e5ff38061b98562 -C extra-filename=-8e5ff38061b98562 --out-dir /build/snippet/target/debug/build/one-8e5ff38061b98562 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name build_script_build two/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fcd8c089040e6ff4 -C extra-filename=-fcd8c089040e6ff4 --out-dir /build/snippet/target/debug/build/two-fcd8c089040e6ff4 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name itoa /home/luser/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-0.3.4/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=327a92d5ddd56b4a -C extra-filename=-327a92d5ddd56b4a --out-dir /build/snippet/target/debug/deps -L dependency=/build/snippet/target/debug/deps --cap-lints warn`
     Running `/build/snippet/target/debug/build/one-8e5ff38061b98562/build-script-build`             
     Running `/build/snippet/target/debug/build/two-fcd8c089040e6ff4/build-script-build`             
[one-e779b28932bbd20b] Error 0                                                                       
[one-e779b28932bbd20b] Output 0                                                                      
[one-e779b28932bbd20b] Output 1                                                                      
[one-e779b28932bbd20b] Error 1                                                                       
[two-adc2191c38bf9afc] Error 0                                                                       
[two-adc2191c38bf9afc] Output 0                                                                      
[one-e779b28932bbd20b] Error 2                                                                       
[one-e779b28932bbd20b] Output 2                                                                      
[two-adc2191c38bf9afc] Error 1                                                                       
[two-adc2191c38bf9afc] Output 1                                                                      
[one-e779b28932bbd20b] Output 3                                                                      
[one-e779b28932bbd20b] Error 3                                                                       
[two-adc2191c38bf9afc] Error 2                                                                       
[two-adc2191c38bf9afc] Output 2                                                                      
[one-e779b28932bbd20b] Error 4                                                                       
[one-e779b28932bbd20b] Output 4                                                                      
[two-adc2191c38bf9afc] Error 3                                                                       
[two-adc2191c38bf9afc] Output 3                                                                      
[one-e779b28932bbd20b] Error 5                                                                       
[one-e779b28932bbd20b] Output 5                                                                      
[two-adc2191c38bf9afc] Error 4                                                                       
[two-adc2191c38bf9afc] Output 4                                                                      
[one-e779b28932bbd20b] Error 6                                                                       
[one-e779b28932bbd20b] Output 6                                                                      
[two-adc2191c38bf9afc] Error 5                                                                       
[two-adc2191c38bf9afc] Output 5                                                                      
[one-e779b28932bbd20b] Error 7                                                                       
[one-e779b28932bbd20b] Output 7                                                                      
[two-adc2191c38bf9afc] Error 6                                                                       
[two-adc2191c38bf9afc] Output 6                                                                      
[one-e779b28932bbd20b] Error 8                                                                       
[one-e779b28932bbd20b] Output 8                                                                      
[two-adc2191c38bf9afc] Error 7                                                                       
[two-adc2191c38bf9afc] Output 7                                                                      
[one-e779b28932bbd20b] Error 9                                                                       
[one-e779b28932bbd20b] Output 9                                                                      
[two-adc2191c38bf9afc] Output 8                                                                      
[two-adc2191c38bf9afc] Error 8                                                                       
     Running `rustc --crate-name one one/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c2b76a52468c9a0b -C extra-filename=-c2b76a52468c9a0b --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
[two-adc2191c38bf9afc] Error 9                                                                       
[two-adc2191c38bf9afc] Output 9                                                                      
     Running `rustc --crate-name two two/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=904ea56f5613ae62 -C extra-filename=-904ea56f5613ae62 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
   Compiling snippet v0.1.4-alpha.0 (/build/snippet)                                                 
     Running `rustc --crate-name snippet src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=a5c6abeab1e38e11 -C extra-filename=-a5c6abeab1e38e11 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
     Running `rustc --crate-name snippet src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8b5a0b44264aa67c -C extra-filename=-8b5a0b44264aa67c --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern snippet=/build/snippet/target/debug/deps/libsnippet-a5c6abeab1e38e11.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 0.90s                                        

I used invocation_name here for no particular reason other than it was being used by the build plan code immediately above, but since that includes the fingerprint it might be nicer to use just pkg_name?

@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

This seems reasonable to me! I might say we should just go ahead and probably switch the name output here to [$name $version] to be a bit more human readable, but otherwise seems like a good improvement to be!

@rust-lang/cargo, any knee-jerk reactions or objections?

@joshtriplett
Copy link
Member

This seems reasonable to me! (And yes, please use the version, in addition to the git hash.)

@bors
Copy link
Contributor

bors commented Oct 15, 2018

☔ The latest upstream changes (presumably #6170) made this pull request unmergeable. Please resolve the merge conflicts.

@luser
Copy link
Contributor Author

luser commented Oct 15, 2018

This seems reasonable to me! (And yes, please use the version, in addition to the git hash.)

Sorry, what do you mean by "git hash" here? AFAICT the hashes in the output above are just cargo's calculated fingerprint for each crate.

@joshtriplett
Copy link
Member

@luser We need enough information to uniquely identify a crate version. A version number helps; I'd also like to see a git hash for any crate being built from sources in git, or a source hash (the way cargo computes one) otherwise. Something easily tracked down after seeing it in a log.

@luser
Copy link
Contributor Author

luser commented Oct 16, 2018

I changed things to use [crate version] instead, and tack on the git ref if present. That starts to get awfully long and I'm not sure doing more than that is useful, honestly. Presumably the crate+version should be unique enough to distinguish a specific dependency within a single build, right?

Here's what my local output looks like for my test project, having added a third build script from a git ref:

luser@eye7:/build/snippet$ cargo clean; /build/cargo/target/debug/cargo build -vv
    Updating git repository `file:///build/three`
   Compiling three v0.1.0 (file:///build/three?rev=297eafaa76d42b318ae11435ab910e725a92fce0#297eafaa)
   Compiling one v0.1.0 (/build/snippet/one)                                                         
   Compiling two v0.1.0 (/build/snippet/two)                                                         
   Compiling itoa v0.3.4                                                                             
     Running `rustc --crate-name build_script_build /home/luser/.cargo/git/checkouts/three-3d24c9ab318cc61a/297eafa/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=ca55695f0011d061 -C extra-filename=-ca55695f0011d061 --out-dir /build/snippet/target/debug/build/three-ca55695f0011d061 -L dependency=/build/snippet/target/debug/deps --cap-lints warn`
     Running `rustc --crate-name build_script_build one/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=60f88b2fff908353 -C extra-filename=-60f88b2fff908353 --out-dir /build/snippet/target/debug/build/one-60f88b2fff908353 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name build_script_build two/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=31c1514210cfdce5 -C extra-filename=-31c1514210cfdce5 --out-dir /build/snippet/target/debug/build/two-31c1514210cfdce5 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name itoa /home/luser/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-0.3.4/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=cc1629e92f2b68c9 -C extra-filename=-cc1629e92f2b68c9 --out-dir /build/snippet/target/debug/deps -L dependency=/build/snippet/target/debug/deps --cap-lints warn`
     Running `/build/snippet/target/debug/build/two-31c1514210cfdce5/build-script-build`             
     Running `/build/snippet/target/debug/build/one-60f88b2fff908353/build-script-build`             
[two 0.1.0] Output 0                                                                                 
[two 0.1.0] Error 0                                                                                  
[two 0.1.0] Error 1                                                                                  
[two 0.1.0] Output 1                                                                                 
     Running `/build/snippet/target/debug/build/three-ca55695f0011d061/build-script-build`           
[one 0.1.0] Output 0                                                                                 
[one 0.1.0] Error 0                                                                                  
[two 0.1.0] Error 2                                                                                  
[two 0.1.0] Output 2                                                                                 
[one 0.1.0] Error 1                                                                                  
[one 0.1.0] Output 1                                                                                 
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 0                                  
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 0                                   
[two 0.1.0] Output 3                                                                                 
[two 0.1.0] Error 3                                                                                  
[one 0.1.0] Error 2                                                                                  
[one 0.1.0] Output 2                                                                                 
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 1                                  
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 1                                   
[two 0.1.0] Error 4                                                                                  
[two 0.1.0] Output 4                                                                                 
[one 0.1.0] Error 3                                                                                  
[one 0.1.0] Output 3                                                                                 
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 2                                  
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 2                                   
[two 0.1.0] Output 5                                                                                 
[two 0.1.0] Error 5                                                                                  
[one 0.1.0] Error 4                                                                                  
[one 0.1.0] Output 4                                                                                 
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 3                                  
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 3                                   
[two 0.1.0] Error 6                                                                                  
[two 0.1.0] Output 6                                                                                 
[one 0.1.0] Error 5                                                                                  
[one 0.1.0] Output 5                                                                                 
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 4                                  
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 4                                   
[two 0.1.0] Error 7                                                                                  
[two 0.1.0] Output 7                                                                                 
[one 0.1.0] Error 6                                                                                  
[one 0.1.0] Output 6                                                                                 
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 5                                   
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 5                                  
[two 0.1.0] Error 8                                                                                  
[two 0.1.0] Output 8                                                                                 
[one 0.1.0] Error 7                                                                                  
[one 0.1.0] Output 7                                                                                 
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 6                                   
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 6                                  
[two 0.1.0] Error 9                                                                                  
[two 0.1.0] Output 9                                                                                 
[one 0.1.0] Error 8                                                                                  
[one 0.1.0] Output 8                                                                                 
     Running `rustc --crate-name two two/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=83fa099ece41eb54 -C extra-filename=-83fa099ece41eb54 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 7                                   
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 7                                  
[one 0.1.0] Error 9                                                                                  
[one 0.1.0] Output 9                                                                                 
     Running `rustc --crate-name one one/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=f16d4da1f6472df4 -C extra-filename=-f16d4da1f6472df4 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 8                                   
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 8                                  
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Error 9                                   
[three 0.1.0 rev=297eafaa76d42b318ae11435ab910e725a92fce0] Output 9                                  
     Running `rustc --crate-name three /home/luser/.cargo/git/checkouts/three-3d24c9ab318cc61a/297eafa/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=fce6960295c9a34c -C extra-filename=-fce6960295c9a34c --out-dir /build/snippet/target/debug/deps -L dependency=/build/snippet/target/debug/deps --cap-lints warn`
   Compiling snippet v0.1.4-alpha.0 (/build/snippet)                                                 
     Running `rustc --crate-name snippet src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=11d95a3d4303ae0e -C extra-filename=-11d95a3d4303ae0e --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-cc1629e92f2b68c9.rlib --extern one=/build/snippet/target/debug/deps/libone-f16d4da1f6472df4.rlib --extern three=/build/snippet/target/debug/deps/libthree-fce6960295c9a34c.rlib --extern two=/build/snippet/target/debug/deps/libtwo-83fa099ece41eb54.rlib`
     Running `rustc --crate-name snippet src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=08e6ed213d4f61d0 -C extra-filename=-08e6ed213d4f61d0 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-cc1629e92f2b68c9.rlib --extern one=/build/snippet/target/debug/deps/libone-f16d4da1f6472df4.rlib --extern snippet=/build/snippet/target/debug/deps/libsnippet-11d95a3d4303ae0e.rlib --extern three=/build/snippet/target/debug/deps/libthree-fce6960295c9a34c.rlib --extern two=/build/snippet/target/debug/deps/libtwo-83fa099ece41eb54.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 0.94s                                        

@alexcrichton
Copy link
Member

Looks reasonable to me! Although I agree that name+version is almost always enough to make the output unique, and if it's not then it's no worse than today! I'd personally lean towards just name/version and omitting git/path information

…ose mode. Fixes rust-lang#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.
@luser
Copy link
Contributor Author

luser commented Oct 18, 2018

OK I went with [name version] for the prefix, so the output for my sample project looks something like:

     Running `/build/snippet/target/debug/build/three-ca55695f0011d061/build-script-build`           
[three 0.1.0] Output 0                                                                               
[three 0.1.0] Error 0                                                                                
[three 0.1.0] Error 1                                                                                
[three 0.1.0] Output 1                                                                               
[three 0.1.0] Error 2                                                                                
[three 0.1.0] Output 2                                                                               
     Running `/build/snippet/target/debug/build/two-31c1514210cfdce5/build-script-build`             
[three 0.1.0] Error 3                                                                                
[three 0.1.0] Output 3                                                                               
[two 0.1.0] Error 0                                                                                  
[two 0.1.0] Output 0                                                                                 
     Running `/build/snippet/target/debug/build/one-60f88b2fff908353/build-script-build`             
[three 0.1.0] Error 4                                                                                
[three 0.1.0] Output 4                                                                               
[two 0.1.0] Error 1                                                                                  
[two 0.1.0] Output 1                                                                                 
[three 0.1.0] Error 5                                                                                
[one 0.1.0] Error 0                                                                                  
[one 0.1.0] Output 0                                                                                 

I also rebased the patch over another change that conflicted.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Oct 18, 2018

📌 Commit 20920c0 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Oct 18, 2018

⌛ Testing commit 20920c0 with merge 4076b8d...

bors added a commit that referenced this pull request Oct 18, 2018
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
in this case.

I put together [a simple test crate](https://github.com/luser/snippet/tree/build-script-output) for this. Building that crate on my machine with stable cargo produces:
```
luser@eye7:/build/snippet$ cargo build -vv
   Compiling one v0.1.0 (file:///build/snippet/one)
   Compiling two v0.1.0 (file:///build/snippet/two)
       Fresh itoa v0.3.4
     Running `rustc --crate-name build_script_build one/build.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8e5ff38061b98562 -C extra-filename=-8e5ff38061b98562 --out-dir /build/snippet/target/debug/build/one-8e5ff38061b98562 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name build_script_build two/build.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fcd8c089040e6ff4 -C extra-filename=-fcd8c089040e6ff4 --out-dir /build/snippet/target/debug/build/two-fcd8c089040e6ff4 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `/build/snippet/target/debug/build/two-fcd8c089040e6ff4/build-script-build`
     Running `/build/snippet/target/debug/build/one-8e5ff38061b98562/build-script-build`
Error 0
Output 0
Output 0
Error 0
Output 1
Error 1
Error 1
Output 1
Error 2
Output 2
Error 2
Output 2
Error 3
Output 3
Error 3
Output 3
Error 4
Error 4
Output 4
Output 4
Error 5
Error 5
Output 5
Output 5
Error 6
Output 6
Error 6
Output 6
Error 7
Output 7
Error 7
Output 7
Error 8
Error 8
Output 8
Output 8
Error 9
Output 9
Error 9
Output 9
     Running `rustc --crate-name two two/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=904ea56f5613ae62 -C extra-filename=-904ea56f5613ae62 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name one one/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c2b76a52468c9a0b -C extra-filename=-c2b76a52468c9a0b --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
   Compiling snippet v0.1.4-alpha.0 (file:///build/snippet)
     Running `rustc --crate-name snippet src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=a5c6abeab1e38e11 -C extra-filename=-a5c6abeab1e38e11 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
     Running `rustc --crate-name snippet src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8b5a0b44264aa67c -C extra-filename=-8b5a0b44264aa67c --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern snippet=/build/snippet/target/debug/deps/libsnippet-a5c6abeab1e38e11.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 0.76s
```

Building that crate with my local cargo including this change produces:
```
luser@eye7:/build/snippet$ /build/cargo/target/debug/cargo build -vv
   Compiling one v0.1.0 (/build/snippet/one)
   Compiling two v0.1.0 (/build/snippet/two)
   Compiling itoa v0.3.4
     Running `rustc --crate-name build_script_build one/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8e5ff38061b98562 -C extra-filename=-8e5ff38061b98562 --out-dir /build/snippet/target/debug/build/one-8e5ff38061b98562 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name build_script_build two/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fcd8c089040e6ff4 -C extra-filename=-fcd8c089040e6ff4 --out-dir /build/snippet/target/debug/build/two-fcd8c089040e6ff4 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name itoa /home/luser/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-0.3.4/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=327a92d5ddd56b4a -C extra-filename=-327a92d5ddd56b4a --out-dir /build/snippet/target/debug/deps -L dependency=/build/snippet/target/debug/deps --cap-lints warn`
     Running `/build/snippet/target/debug/build/one-8e5ff38061b98562/build-script-build`
     Running `/build/snippet/target/debug/build/two-fcd8c089040e6ff4/build-script-build`
[one-e779b28932bbd20b] Error 0
[one-e779b28932bbd20b] Output 0
[one-e779b28932bbd20b] Output 1
[one-e779b28932bbd20b] Error 1
[two-adc2191c38bf9afc] Error 0
[two-adc2191c38bf9afc] Output 0
[one-e779b28932bbd20b] Error 2
[one-e779b28932bbd20b] Output 2
[two-adc2191c38bf9afc] Error 1
[two-adc2191c38bf9afc] Output 1
[one-e779b28932bbd20b] Output 3
[one-e779b28932bbd20b] Error 3
[two-adc2191c38bf9afc] Error 2
[two-adc2191c38bf9afc] Output 2
[one-e779b28932bbd20b] Error 4
[one-e779b28932bbd20b] Output 4
[two-adc2191c38bf9afc] Error 3
[two-adc2191c38bf9afc] Output 3
[one-e779b28932bbd20b] Error 5
[one-e779b28932bbd20b] Output 5
[two-adc2191c38bf9afc] Error 4
[two-adc2191c38bf9afc] Output 4
[one-e779b28932bbd20b] Error 6
[one-e779b28932bbd20b] Output 6
[two-adc2191c38bf9afc] Error 5
[two-adc2191c38bf9afc] Output 5
[one-e779b28932bbd20b] Error 7
[one-e779b28932bbd20b] Output 7
[two-adc2191c38bf9afc] Error 6
[two-adc2191c38bf9afc] Output 6
[one-e779b28932bbd20b] Error 8
[one-e779b28932bbd20b] Output 8
[two-adc2191c38bf9afc] Error 7
[two-adc2191c38bf9afc] Output 7
[one-e779b28932bbd20b] Error 9
[one-e779b28932bbd20b] Output 9
[two-adc2191c38bf9afc] Output 8
[two-adc2191c38bf9afc] Error 8
     Running `rustc --crate-name one one/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c2b76a52468c9a0b -C extra-filename=-c2b76a52468c9a0b --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
[two-adc2191c38bf9afc] Error 9
[two-adc2191c38bf9afc] Output 9
     Running `rustc --crate-name two two/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=904ea56f5613ae62 -C extra-filename=-904ea56f5613ae62 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
   Compiling snippet v0.1.4-alpha.0 (/build/snippet)
     Running `rustc --crate-name snippet src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=a5c6abeab1e38e11 -C extra-filename=-a5c6abeab1e38e11 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
     Running `rustc --crate-name snippet src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8b5a0b44264aa67c -C extra-filename=-8b5a0b44264aa67c --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern snippet=/build/snippet/target/debug/deps/libsnippet-a5c6abeab1e38e11.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 0.90s
```
I used `invocation_name` here for no particular reason other than it was being used by the build plan code immediately above, but since that includes the fingerprint it might be nicer to use just `pkg_name`?
@bors
Copy link
Contributor

bors commented Oct 18, 2018

💔 Test failed - status-appveyor

[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] [..]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this line should have been removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that was a rebase mistake! I swear I ran tests locally, I'm not sure why it didn't fail here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this test only runs on nightly and I was using stable cargo to run cargo test locally:
20920c0#diff-2cbe411b955101d5ff2d27d7a2b63503R571

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Oct 19, 2018

📌 Commit 989ebee has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Oct 19, 2018

⌛ Testing commit 989ebee with merge 4ed9373...

bors added a commit that referenced this pull request Oct 19, 2018
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
in this case.

I put together [a simple test crate](https://github.com/luser/snippet/tree/build-script-output) for this. Building that crate on my machine with stable cargo produces:
```
luser@eye7:/build/snippet$ cargo build -vv
   Compiling one v0.1.0 (file:///build/snippet/one)
   Compiling two v0.1.0 (file:///build/snippet/two)
       Fresh itoa v0.3.4
     Running `rustc --crate-name build_script_build one/build.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8e5ff38061b98562 -C extra-filename=-8e5ff38061b98562 --out-dir /build/snippet/target/debug/build/one-8e5ff38061b98562 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name build_script_build two/build.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fcd8c089040e6ff4 -C extra-filename=-fcd8c089040e6ff4 --out-dir /build/snippet/target/debug/build/two-fcd8c089040e6ff4 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `/build/snippet/target/debug/build/two-fcd8c089040e6ff4/build-script-build`
     Running `/build/snippet/target/debug/build/one-8e5ff38061b98562/build-script-build`
Error 0
Output 0
Output 0
Error 0
Output 1
Error 1
Error 1
Output 1
Error 2
Output 2
Error 2
Output 2
Error 3
Output 3
Error 3
Output 3
Error 4
Error 4
Output 4
Output 4
Error 5
Error 5
Output 5
Output 5
Error 6
Output 6
Error 6
Output 6
Error 7
Output 7
Error 7
Output 7
Error 8
Error 8
Output 8
Output 8
Error 9
Output 9
Error 9
Output 9
     Running `rustc --crate-name two two/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=904ea56f5613ae62 -C extra-filename=-904ea56f5613ae62 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name one one/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c2b76a52468c9a0b -C extra-filename=-c2b76a52468c9a0b --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
   Compiling snippet v0.1.4-alpha.0 (file:///build/snippet)
     Running `rustc --crate-name snippet src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=a5c6abeab1e38e11 -C extra-filename=-a5c6abeab1e38e11 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
     Running `rustc --crate-name snippet src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8b5a0b44264aa67c -C extra-filename=-8b5a0b44264aa67c --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern snippet=/build/snippet/target/debug/deps/libsnippet-a5c6abeab1e38e11.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 0.76s
```

Building that crate with my local cargo including this change produces:
```
luser@eye7:/build/snippet$ /build/cargo/target/debug/cargo build -vv
   Compiling one v0.1.0 (/build/snippet/one)
   Compiling two v0.1.0 (/build/snippet/two)
   Compiling itoa v0.3.4
     Running `rustc --crate-name build_script_build one/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8e5ff38061b98562 -C extra-filename=-8e5ff38061b98562 --out-dir /build/snippet/target/debug/build/one-8e5ff38061b98562 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name build_script_build two/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fcd8c089040e6ff4 -C extra-filename=-fcd8c089040e6ff4 --out-dir /build/snippet/target/debug/build/two-fcd8c089040e6ff4 -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
     Running `rustc --crate-name itoa /home/luser/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-0.3.4/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=327a92d5ddd56b4a -C extra-filename=-327a92d5ddd56b4a --out-dir /build/snippet/target/debug/deps -L dependency=/build/snippet/target/debug/deps --cap-lints warn`
     Running `/build/snippet/target/debug/build/one-8e5ff38061b98562/build-script-build`
     Running `/build/snippet/target/debug/build/two-fcd8c089040e6ff4/build-script-build`
[one-e779b28932bbd20b] Error 0
[one-e779b28932bbd20b] Output 0
[one-e779b28932bbd20b] Output 1
[one-e779b28932bbd20b] Error 1
[two-adc2191c38bf9afc] Error 0
[two-adc2191c38bf9afc] Output 0
[one-e779b28932bbd20b] Error 2
[one-e779b28932bbd20b] Output 2
[two-adc2191c38bf9afc] Error 1
[two-adc2191c38bf9afc] Output 1
[one-e779b28932bbd20b] Output 3
[one-e779b28932bbd20b] Error 3
[two-adc2191c38bf9afc] Error 2
[two-adc2191c38bf9afc] Output 2
[one-e779b28932bbd20b] Error 4
[one-e779b28932bbd20b] Output 4
[two-adc2191c38bf9afc] Error 3
[two-adc2191c38bf9afc] Output 3
[one-e779b28932bbd20b] Error 5
[one-e779b28932bbd20b] Output 5
[two-adc2191c38bf9afc] Error 4
[two-adc2191c38bf9afc] Output 4
[one-e779b28932bbd20b] Error 6
[one-e779b28932bbd20b] Output 6
[two-adc2191c38bf9afc] Error 5
[two-adc2191c38bf9afc] Output 5
[one-e779b28932bbd20b] Error 7
[one-e779b28932bbd20b] Output 7
[two-adc2191c38bf9afc] Error 6
[two-adc2191c38bf9afc] Output 6
[one-e779b28932bbd20b] Error 8
[one-e779b28932bbd20b] Output 8
[two-adc2191c38bf9afc] Error 7
[two-adc2191c38bf9afc] Output 7
[one-e779b28932bbd20b] Error 9
[one-e779b28932bbd20b] Output 9
[two-adc2191c38bf9afc] Output 8
[two-adc2191c38bf9afc] Error 8
     Running `rustc --crate-name one one/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c2b76a52468c9a0b -C extra-filename=-c2b76a52468c9a0b --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
[two-adc2191c38bf9afc] Error 9
[two-adc2191c38bf9afc] Output 9
     Running `rustc --crate-name two two/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=904ea56f5613ae62 -C extra-filename=-904ea56f5613ae62 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps`
   Compiling snippet v0.1.4-alpha.0 (/build/snippet)
     Running `rustc --crate-name snippet src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=a5c6abeab1e38e11 -C extra-filename=-a5c6abeab1e38e11 --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
     Running `rustc --crate-name snippet src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8b5a0b44264aa67c -C extra-filename=-8b5a0b44264aa67c --out-dir /build/snippet/target/debug/deps -C incremental=/build/snippet/target/debug/incremental -L dependency=/build/snippet/target/debug/deps --extern itoa=/build/snippet/target/debug/deps/libitoa-327a92d5ddd56b4a.rlib --extern one=/build/snippet/target/debug/deps/libone-c2b76a52468c9a0b.rlib --extern snippet=/build/snippet/target/debug/deps/libsnippet-a5c6abeab1e38e11.rlib --extern two=/build/snippet/target/debug/deps/libtwo-904ea56f5613ae62.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 0.90s
```
I used `invocation_name` here for no particular reason other than it was being used by the build plan code immediately above, but since that includes the fingerprint it might be nicer to use just `pkg_name`?
@bors
Copy link
Contributor

bors commented Oct 19, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 4ed9373 to master...

@bors bors merged commit 989ebee into rust-lang:master Oct 19, 2018
@ehuss ehuss added this to the 1.31.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants