@@ -13,7 +13,6 @@ use std::time::{Duration, Instant};
1313
1414use crate :: cache:: { Cache , Interned , INTERNER } ;
1515use crate :: config:: { SplitDebuginfo , TargetSelection } ;
16- use crate :: dist;
1716use crate :: doc;
1817use crate :: flags:: { Color , Subcommand } ;
1918use crate :: install;
@@ -25,6 +24,7 @@ use crate::tool::{self, SourceType};
2524use crate :: util:: { self , add_dylib_path, add_link_lib_path, exe, libdir, output, t} ;
2625use crate :: EXTRA_CHECK_CFGS ;
2726use crate :: { check, compile, Crate } ;
27+ use crate :: { clean, dist} ;
2828use crate :: { Build , CLang , DocTests , GitRepo , Mode } ;
2929
3030pub use crate :: Compiler ;
@@ -96,6 +96,17 @@ impl RunConfig<'_> {
9696 pub fn build_triple ( & self ) -> TargetSelection {
9797 self . builder . build . build
9898 }
99+
100+ /// Return a `-p=x -p=y` string suitable for passing to a cargo invocation.
101+ pub fn cargo_crates_in_set ( & self ) -> Interned < Vec < String > > {
102+ let mut crates = Vec :: new ( ) ;
103+ for krate in & self . paths {
104+ let path = krate. assert_single_path ( ) ;
105+ let crate_name = self . builder . crate_paths [ & path. path ] ;
106+ crates. push ( format ! ( "-p={crate_name}" ) ) ;
107+ }
108+ INTERNER . intern_list ( crates)
109+ }
99110}
100111
101112struct StepDescription {
@@ -764,8 +775,9 @@ impl<'a> Builder<'a> {
764775 run:: GenerateCopyright ,
765776 ) ,
766777 Kind :: Setup => describe ! ( setup:: Profile ) ,
767- // These commands either don't use paths, or they're special-cased in Build::build()
768- Kind :: Clean | Kind :: Format => vec ! [ ] ,
778+ Kind :: Clean => describe ! ( clean:: CleanAll , clean:: Rustc , clean:: Std ) ,
779+ // special-cased in Build::build()
780+ Kind :: Format => vec ! [ ] ,
769781 }
770782 }
771783
@@ -827,14 +839,12 @@ impl<'a> Builder<'a> {
827839 Subcommand :: Dist { ref paths } => ( Kind :: Dist , & paths[ ..] ) ,
828840 Subcommand :: Install { ref paths } => ( Kind :: Install , & paths[ ..] ) ,
829841 Subcommand :: Run { ref paths, .. } => ( Kind :: Run , & paths[ ..] ) ,
842+ Subcommand :: Clean { ref paths, .. } => ( Kind :: Clean , & paths[ ..] ) ,
830843 Subcommand :: Format { .. } => ( Kind :: Format , & [ ] [ ..] ) ,
831844 Subcommand :: Setup { profile : ref path } => (
832845 Kind :: Setup ,
833846 path. as_ref ( ) . map_or ( [ ] . as_slice ( ) , |path| std:: slice:: from_ref ( path) ) ,
834847 ) ,
835- Subcommand :: Clean { .. } => {
836- panic ! ( )
837- }
838848 } ;
839849
840850 Self :: new_internal ( build, kind, paths. to_owned ( ) )
@@ -1077,6 +1087,62 @@ impl<'a> Builder<'a> {
10771087 None
10781088 }
10791089
1090+ /// Like `cargo`, but only passes flags that are valid for all commands.
1091+ pub fn bare_cargo (
1092+ & self ,
1093+ compiler : Compiler ,
1094+ mode : Mode ,
1095+ target : TargetSelection ,
1096+ cmd : & str ,
1097+ ) -> Command {
1098+ let mut cargo = Command :: new ( & self . initial_cargo ) ;
1099+ // Run cargo from the source root so it can find .cargo/config.
1100+ // This matters when using vendoring and the working directory is outside the repository.
1101+ cargo. current_dir ( & self . src ) ;
1102+
1103+ let out_dir = self . stage_out ( compiler, mode) ;
1104+ cargo. env ( "CARGO_TARGET_DIR" , & out_dir) . arg ( cmd) ;
1105+
1106+ // Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger`
1107+ // from out of tree it shouldn't matter, since x.py is only used for
1108+ // building in-tree.
1109+ let color_logs = [ "RUSTDOC_LOG_COLOR" , "RUSTC_LOG_COLOR" , "RUST_LOG_COLOR" ] ;
1110+ match self . build . config . color {
1111+ Color :: Always => {
1112+ cargo. arg ( "--color=always" ) ;
1113+ for log in & color_logs {
1114+ cargo. env ( log, "always" ) ;
1115+ }
1116+ }
1117+ Color :: Never => {
1118+ cargo. arg ( "--color=never" ) ;
1119+ for log in & color_logs {
1120+ cargo. env ( log, "never" ) ;
1121+ }
1122+ }
1123+ Color :: Auto => { } // nothing to do
1124+ }
1125+
1126+ if cmd != "install" {
1127+ cargo. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
1128+ } else {
1129+ assert_eq ! ( target, compiler. host) ;
1130+ }
1131+
1132+ if self . config . rust_optimize {
1133+ // FIXME: cargo bench/install do not accept `--release`
1134+ if cmd != "bench" && cmd != "install" {
1135+ cargo. arg ( "--release" ) ;
1136+ }
1137+ }
1138+
1139+ // Remove make-related flags to ensure Cargo can correctly set things up
1140+ cargo. env_remove ( "MAKEFLAGS" ) ;
1141+ cargo. env_remove ( "MFLAGS" ) ;
1142+
1143+ cargo
1144+ }
1145+
10801146 /// Prepares an invocation of `cargo` to be run.
10811147 ///
10821148 /// This will create a `Command` that represents a pending execution of
@@ -1092,11 +1158,8 @@ impl<'a> Builder<'a> {
10921158 target : TargetSelection ,
10931159 cmd : & str ,
10941160 ) -> Cargo {
1095- let mut cargo = Command :: new ( & self . initial_cargo ) ;
1161+ let mut cargo = self . bare_cargo ( compiler , mode , target , cmd ) ;
10961162 let out_dir = self . stage_out ( compiler, mode) ;
1097- // Run cargo from the source root so it can find .cargo/config.
1098- // This matters when using vendoring and the working directory is outside the repository.
1099- cargo. current_dir ( & self . src ) ;
11001163
11011164 // Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
11021165 // so we need to explicitly clear out if they've been updated.
@@ -1121,8 +1184,6 @@ impl<'a> Builder<'a> {
11211184 self . clear_if_dirty ( & my_out, & rustdoc) ;
11221185 }
11231186
1124- cargo. env ( "CARGO_TARGET_DIR" , & out_dir) . arg ( cmd) ;
1125-
11261187 let profile_var = |name : & str | {
11271188 let profile = if self . config . rust_optimize { "RELEASE" } else { "DEV" } ;
11281189 format ! ( "CARGO_PROFILE_{}_{}" , profile, name)
@@ -1135,32 +1196,6 @@ impl<'a> Builder<'a> {
11351196 cargo. env ( "REAL_LIBRARY_PATH" , e) ;
11361197 }
11371198
1138- // Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger`
1139- // from out of tree it shouldn't matter, since x.py is only used for
1140- // building in-tree.
1141- let color_logs = [ "RUSTDOC_LOG_COLOR" , "RUSTC_LOG_COLOR" , "RUST_LOG_COLOR" ] ;
1142- match self . build . config . color {
1143- Color :: Always => {
1144- cargo. arg ( "--color=always" ) ;
1145- for log in & color_logs {
1146- cargo. env ( log, "always" ) ;
1147- }
1148- }
1149- Color :: Never => {
1150- cargo. arg ( "--color=never" ) ;
1151- for log in & color_logs {
1152- cargo. env ( log, "never" ) ;
1153- }
1154- }
1155- Color :: Auto => { } // nothing to do
1156- }
1157-
1158- if cmd != "install" {
1159- cargo. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
1160- } else {
1161- assert_eq ! ( target, compiler. host) ;
1162- }
1163-
11641199 // Set a flag for `check`/`clippy`/`fix`, so that certain build
11651200 // scripts can do less work (i.e. not building/requiring LLVM).
11661201 if cmd == "check" || cmd == "clippy" || cmd == "fix" {
@@ -1341,9 +1376,6 @@ impl<'a> Builder<'a> {
13411376 }
13421377
13431378 cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
1344- // Remove make-related flags to ensure Cargo can correctly set things up
1345- cargo. env_remove ( "MAKEFLAGS" ) ;
1346- cargo. env_remove ( "MFLAGS" ) ;
13471379
13481380 // FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
13491381 // Force cargo to output binaries with disambiguating hashes in the name
@@ -1827,13 +1859,6 @@ impl<'a> Builder<'a> {
18271859 }
18281860 }
18291861
1830- if self . config . rust_optimize {
1831- // FIXME: cargo bench/install do not accept `--release`
1832- if cmd != "bench" && cmd != "install" {
1833- cargo. arg ( "--release" ) ;
1834- }
1835- }
1836-
18371862 if self . config . locked_deps {
18381863 cargo. arg ( "--locked" ) ;
18391864 }
0 commit comments