@@ -13,7 +13,6 @@ use std::time::{Duration, Instant};
13
13
14
14
use crate :: cache:: { Cache , Interned , INTERNER } ;
15
15
use crate :: config:: { SplitDebuginfo , TargetSelection } ;
16
- use crate :: dist;
17
16
use crate :: doc;
18
17
use crate :: flags:: { Color , Subcommand } ;
19
18
use crate :: install;
@@ -25,6 +24,7 @@ use crate::tool::{self, SourceType};
25
24
use crate :: util:: { self , add_dylib_path, add_link_lib_path, exe, libdir, output, t} ;
26
25
use crate :: EXTRA_CHECK_CFGS ;
27
26
use crate :: { check, compile, Crate } ;
27
+ use crate :: { clean, dist} ;
28
28
use crate :: { Build , CLang , DocTests , GitRepo , Mode } ;
29
29
30
30
pub use crate :: Compiler ;
@@ -96,6 +96,17 @@ impl RunConfig<'_> {
96
96
pub fn build_triple ( & self ) -> TargetSelection {
97
97
self . builder . build . build
98
98
}
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
+ }
99
110
}
100
111
101
112
struct StepDescription {
@@ -764,8 +775,9 @@ impl<'a> Builder<'a> {
764
775
run:: GenerateCopyright ,
765
776
) ,
766
777
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 ! [ ] ,
769
781
}
770
782
}
771
783
@@ -827,14 +839,12 @@ impl<'a> Builder<'a> {
827
839
Subcommand :: Dist { ref paths } => ( Kind :: Dist , & paths[ ..] ) ,
828
840
Subcommand :: Install { ref paths } => ( Kind :: Install , & paths[ ..] ) ,
829
841
Subcommand :: Run { ref paths, .. } => ( Kind :: Run , & paths[ ..] ) ,
842
+ Subcommand :: Clean { ref paths, .. } => ( Kind :: Clean , & paths[ ..] ) ,
830
843
Subcommand :: Format { .. } => ( Kind :: Format , & [ ] [ ..] ) ,
831
844
Subcommand :: Setup { profile : ref path } => (
832
845
Kind :: Setup ,
833
846
path. as_ref ( ) . map_or ( [ ] . as_slice ( ) , |path| std:: slice:: from_ref ( path) ) ,
834
847
) ,
835
- Subcommand :: Clean { .. } => {
836
- panic ! ( )
837
- }
838
848
} ;
839
849
840
850
Self :: new_internal ( build, kind, paths. to_owned ( ) )
@@ -1077,6 +1087,62 @@ impl<'a> Builder<'a> {
1077
1087
None
1078
1088
}
1079
1089
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
+
1080
1146
/// Prepares an invocation of `cargo` to be run.
1081
1147
///
1082
1148
/// This will create a `Command` that represents a pending execution of
@@ -1092,11 +1158,8 @@ impl<'a> Builder<'a> {
1092
1158
target : TargetSelection ,
1093
1159
cmd : & str ,
1094
1160
) -> Cargo {
1095
- let mut cargo = Command :: new ( & self . initial_cargo ) ;
1161
+ let mut cargo = self . bare_cargo ( compiler , mode , target , cmd ) ;
1096
1162
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 ) ;
1100
1163
1101
1164
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
1102
1165
// so we need to explicitly clear out if they've been updated.
@@ -1121,8 +1184,6 @@ impl<'a> Builder<'a> {
1121
1184
self . clear_if_dirty ( & my_out, & rustdoc) ;
1122
1185
}
1123
1186
1124
- cargo. env ( "CARGO_TARGET_DIR" , & out_dir) . arg ( cmd) ;
1125
-
1126
1187
let profile_var = |name : & str | {
1127
1188
let profile = if self . config . rust_optimize { "RELEASE" } else { "DEV" } ;
1128
1189
format ! ( "CARGO_PROFILE_{}_{}" , profile, name)
@@ -1135,32 +1196,6 @@ impl<'a> Builder<'a> {
1135
1196
cargo. env ( "REAL_LIBRARY_PATH" , e) ;
1136
1197
}
1137
1198
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
-
1164
1199
// Set a flag for `check`/`clippy`/`fix`, so that certain build
1165
1200
// scripts can do less work (i.e. not building/requiring LLVM).
1166
1201
if cmd == "check" || cmd == "clippy" || cmd == "fix" {
@@ -1341,9 +1376,6 @@ impl<'a> Builder<'a> {
1341
1376
}
1342
1377
1343
1378
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" ) ;
1347
1379
1348
1380
// FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
1349
1381
// Force cargo to output binaries with disambiguating hashes in the name
@@ -1827,13 +1859,6 @@ impl<'a> Builder<'a> {
1827
1859
}
1828
1860
}
1829
1861
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
-
1837
1862
if self . config . locked_deps {
1838
1863
cargo. arg ( "--locked" ) ;
1839
1864
}
0 commit comments