@@ -9,19 +9,19 @@ use std::fmt::{self, Display};
9
9
use std:: hash:: Hash ;
10
10
use std:: io:: IsTerminal ;
11
11
use std:: path:: { Path , PathBuf , absolute} ;
12
- use std:: process:: Command ;
13
12
use std:: str:: FromStr ;
14
13
use std:: sync:: { Arc , Mutex , OnceLock } ;
15
14
use std:: { cmp, env, fs} ;
16
15
17
16
use build_helper:: ci:: CiEnv ;
18
17
use build_helper:: exit;
19
- use build_helper:: git:: { GitConfig , PathFreshness , check_path_modifications, output_result } ;
18
+ use build_helper:: git:: { GitConfig , PathFreshness , check_path_modifications} ;
20
19
use serde:: { Deserialize , Deserializer } ;
21
20
use serde_derive:: Deserialize ;
22
21
#[ cfg( feature = "tracing" ) ]
23
22
use tracing:: { instrument, span} ;
24
23
24
+ use crate :: command;
25
25
use crate :: core:: build_steps:: compile:: CODEGEN_BACKEND_PREFIX ;
26
26
use crate :: core:: build_steps:: llvm;
27
27
use crate :: core:: build_steps:: llvm:: LLVM_INVALIDATION_PATHS ;
@@ -1530,14 +1530,10 @@ impl Config {
1530
1530
// has already been (kinda-cross-)compiled to Windows land, we require a normal Windows path.
1531
1531
cmd. arg ( "rev-parse" ) . arg ( "--show-cdup" ) ;
1532
1532
// Discard stderr because we expect this to fail when building from a tarball.
1533
- let output = cmd
1534
- . as_command_mut ( )
1535
- . stderr ( std:: process:: Stdio :: null ( ) )
1536
- . output ( )
1537
- . ok ( )
1538
- . and_then ( |output| if output. status . success ( ) { Some ( output) } else { None } ) ;
1539
- if let Some ( output) = output {
1540
- let git_root_relative = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
1533
+ let output = cmd. run_capture_stdout ( & config. context ( ) ) ;
1534
+
1535
+ if output. is_success ( ) {
1536
+ let git_root_relative = output. stdout ( ) ;
1541
1537
// We need to canonicalize this path to make sure it uses backslashes instead of forward slashes,
1542
1538
// and to resolve any relative components.
1543
1539
let git_root = env:: current_dir ( )
@@ -1632,7 +1628,9 @@ impl Config {
1632
1628
build. cargo = build. cargo . take ( ) . or ( std:: env:: var_os ( "CARGO" ) . map ( |p| p. into ( ) ) ) ;
1633
1629
}
1634
1630
1635
- if GitInfo :: new ( false , & config. src ) . is_from_tarball ( ) && toml. profile . is_none ( ) {
1631
+ if GitInfo :: new ( false , & config. src , config. context ( ) ) . is_from_tarball ( )
1632
+ && toml. profile . is_none ( )
1633
+ {
1636
1634
toml. profile = Some ( "dist" . into ( ) ) ;
1637
1635
}
1638
1636
@@ -1839,7 +1837,11 @@ impl Config {
1839
1837
} ;
1840
1838
1841
1839
config. initial_sysroot = t ! ( PathBuf :: from_str(
1842
- output( Command :: new( & config. initial_rustc) . args( [ "--print" , "sysroot" ] ) ) . trim( )
1840
+ command( & config. initial_rustc)
1841
+ . args( [ "--print" , "sysroot" ] )
1842
+ . run_capture_stdout( & config. context( ) )
1843
+ . stdout( )
1844
+ . trim( )
1843
1845
) ) ;
1844
1846
1845
1847
config. initial_cargo_clippy = cargo_clippy;
@@ -1966,19 +1968,41 @@ impl Config {
1966
1968
let default = config. channel == "dev" ;
1967
1969
config. omit_git_hash = toml. rust . as_ref ( ) . and_then ( |r| r. omit_git_hash ) . unwrap_or ( default) ;
1968
1970
1969
- config. rust_info = GitInfo :: new ( config. omit_git_hash , & config. src ) ;
1970
- config. cargo_info = GitInfo :: new ( config. omit_git_hash , & config. src . join ( "src/tools/cargo" ) ) ;
1971
- config. rust_analyzer_info =
1972
- GitInfo :: new ( config. omit_git_hash , & config. src . join ( "src/tools/rust-analyzer" ) ) ;
1973
- config. clippy_info =
1974
- GitInfo :: new ( config. omit_git_hash , & config. src . join ( "src/tools/clippy" ) ) ;
1975
- config. miri_info = GitInfo :: new ( config. omit_git_hash , & config. src . join ( "src/tools/miri" ) ) ;
1976
- config. rustfmt_info =
1977
- GitInfo :: new ( config. omit_git_hash , & config. src . join ( "src/tools/rustfmt" ) ) ;
1978
- config. enzyme_info =
1979
- GitInfo :: new ( config. omit_git_hash , & config. src . join ( "src/tools/enzyme" ) ) ;
1980
- config. in_tree_llvm_info = GitInfo :: new ( false , & config. src . join ( "src/llvm-project" ) ) ;
1981
- config. in_tree_gcc_info = GitInfo :: new ( false , & config. src . join ( "src/gcc" ) ) ;
1971
+ config. rust_info = GitInfo :: new ( config. omit_git_hash , & config. src , & config. context ( ) ) ;
1972
+ config. cargo_info = GitInfo :: new (
1973
+ config. omit_git_hash ,
1974
+ & config. src . join ( "src/tools/cargo" ) ,
1975
+ config. context ( ) ,
1976
+ ) ;
1977
+ config. rust_analyzer_info = GitInfo :: new (
1978
+ config. omit_git_hash ,
1979
+ & config. src . join ( "src/tools/rust-analyzer" ) ,
1980
+ config. context ( ) ,
1981
+ ) ;
1982
+ config. clippy_info = GitInfo :: new (
1983
+ config. omit_git_hash ,
1984
+ & config. src . join ( "src/tools/clippy" ) ,
1985
+ config. context ( ) ,
1986
+ ) ;
1987
+ config. miri_info = GitInfo :: new (
1988
+ config. omit_git_hash ,
1989
+ & config. src . join ( "src/tools/miri" ) ,
1990
+ config. context ( ) ,
1991
+ ) ;
1992
+ config. rustfmt_info = GitInfo :: new (
1993
+ config. omit_git_hash ,
1994
+ & config. src . join ( "src/tools/rustfmt" ) ,
1995
+ config. context ( ) ,
1996
+ ) ;
1997
+ config. enzyme_info = GitInfo :: new (
1998
+ config. omit_git_hash ,
1999
+ & config. src . join ( "src/tools/enzyme" ) ,
2000
+ config. context ( ) ,
2001
+ ) ;
2002
+ config. in_tree_llvm_info =
2003
+ GitInfo :: new ( false , & config. src . join ( "src/llvm-project" ) , config. context ( ) ) ;
2004
+ config. in_tree_gcc_info =
2005
+ GitInfo :: new ( false , & config. src . join ( "src/gcc" ) , config. context ( ) ) ;
1982
2006
1983
2007
config. vendor = vendor. unwrap_or (
1984
2008
config. rust_info . is_from_tarball ( )
@@ -2610,18 +2634,6 @@ impl Config {
2610
2634
self . explicit_stage_from_cli || self . explicit_stage_from_config
2611
2635
}
2612
2636
2613
- /// Runs a command, printing out nice contextual information if it fails.
2614
- /// Exits if the command failed to execute at all, otherwise returns its
2615
- /// `status.success()`.
2616
- #[ deprecated = "use `Builder::try_run` instead where possible" ]
2617
- pub ( crate ) fn try_run ( & self , cmd : & mut Command ) -> Result < ( ) , ( ) > {
2618
- if self . dry_run ( ) {
2619
- return Ok ( ( ) ) ;
2620
- }
2621
- self . verbose ( || println ! ( "running: {cmd:?}" ) ) ;
2622
- build_helper:: util:: try_run ( cmd, self . is_verbose ( ) )
2623
- }
2624
-
2625
2637
pub ( crate ) fn test_args ( & self ) -> Vec < & str > {
2626
2638
let mut test_args = match self . cmd {
2627
2639
Subcommand :: Test { ref test_args, .. }
@@ -2655,7 +2667,7 @@ impl Config {
2655
2667
2656
2668
let mut git = helpers:: git ( Some ( & self . src ) ) ;
2657
2669
git. arg ( "show" ) . arg ( format ! ( "{commit}:{}" , file. to_str( ) . unwrap( ) ) ) ;
2658
- output ( git. as_command_mut ( ) )
2670
+ git. run_capture_stdout ( self . context ( ) ) . stdout ( )
2659
2671
}
2660
2672
2661
2673
/// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@@ -2980,7 +2992,7 @@ impl Config {
2980
2992
2981
2993
// NOTE: The check for the empty directory is here because when running x.py the first time,
2982
2994
// the submodule won't be checked out. Check it out now so we can build it.
2983
- if !GitInfo :: new ( false , & absolute_path) . is_managed_git_subrepository ( )
2995
+ if !GitInfo :: new ( false , & absolute_path, & self . context ( ) ) . is_managed_git_subrepository ( )
2984
2996
&& !helpers:: dir_is_empty ( & absolute_path)
2985
2997
{
2986
2998
return ;
@@ -2999,16 +3011,20 @@ impl Config {
2999
3011
} ;
3000
3012
3001
3013
// Determine commit checked out in submodule.
3002
- let checked_out_hash = output ( submodule_git ( ) . args ( [ "rev-parse" , "HEAD" ] ) . as_command_mut ( ) ) ;
3014
+ // let checked_out_hash = output(submodule_git().args(["rev-parse", "HEAD"]).as_command_mut());
3015
+ let checked_out_hash = submodule_git ( )
3016
+ . args ( [ "rev-parse" , "HEAD" ] )
3017
+ . run_capture_stdout ( & self . context ( ) )
3018
+ . stdout ( ) ;
3003
3019
let checked_out_hash = checked_out_hash. trim_end ( ) ;
3004
3020
// Determine commit that the submodule *should* have.
3005
- let recorded = output (
3006
- helpers:: git ( Some ( & self . src ) )
3007
- . run_always ( )
3008
- . args ( [ "ls-tree" , "HEAD" ] )
3009
- . arg ( relative_path)
3010
- . as_command_mut ( ) ,
3011
- ) ;
3021
+
3022
+ let recorded = helpers:: git ( Some ( & self . src ) )
3023
+ . run_always ( )
3024
+ . args ( [ "ls-tree" , "HEAD" ] )
3025
+ . arg ( relative_path)
3026
+ . run_capture_stdout ( & self . context ( ) )
3027
+ . stdout ( ) ;
3012
3028
3013
3029
let actual_hash = recorded
3014
3030
. split_whitespace ( )
@@ -3032,20 +3048,17 @@ impl Config {
3032
3048
let update = |progress : bool | {
3033
3049
// Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
3034
3050
// even though that has no relation to the upstream for the submodule.
3035
- let current_branch = output_result (
3036
- helpers:: git ( Some ( & self . src ) )
3037
- . allow_failure ( )
3038
- . run_always ( )
3039
- . args ( [ "symbolic-ref" , "--short" , "HEAD" ] )
3040
- . as_command_mut ( ) ,
3041
- )
3042
- . map ( |b| b. trim ( ) . to_owned ( ) ) ;
3043
-
3051
+ let current_branch = helpers:: git ( Some ( & self . src ) )
3052
+ . allow_failure ( )
3053
+ . run_always ( )
3054
+ . args ( [ "symbolic-ref" , "--short" , "HEAD" ] )
3055
+ . run_capture_stdout ( & self . context ( ) ) ;
3044
3056
let mut git = helpers:: git ( Some ( & self . src ) ) . allow_failure ( ) ;
3045
3057
git. run_always ( ) ;
3046
- if let Ok ( branch ) = current_branch {
3058
+ if current_branch . is_success ( ) {
3047
3059
// If there is a tag named after the current branch, git will try to disambiguate by prepending `heads/` to the branch name.
3048
3060
// This syntax isn't accepted by `branch.{branch}`. Strip it.
3061
+ let branch = current_branch. stdout ( ) ;
3049
3062
let branch = branch. strip_prefix ( "heads/" ) . unwrap_or ( & branch) ;
3050
3063
git. arg ( "-c" ) . arg ( format ! ( "branch.{branch}.remote=origin" ) ) ;
3051
3064
}
@@ -3091,7 +3104,8 @@ impl Config {
3091
3104
return ;
3092
3105
}
3093
3106
3094
- let stage0_output = output ( Command :: new ( program_path) . arg ( "--version" ) ) ;
3107
+ let stage0_output =
3108
+ command ( program_path) . arg ( "--version" ) . run_capture_stdout ( self . context ( ) ) . stdout ( ) ;
3095
3109
let mut stage0_output = stage0_output. lines ( ) . next ( ) . unwrap ( ) . split ( ' ' ) ;
3096
3110
3097
3111
let stage0_name = stage0_output. next ( ) . unwrap ( ) ;
0 commit comments