@@ -216,7 +216,27 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
216
216
} ;
217
217
218
218
// Some subcommands get extra options
219
- match subcommand. as_str ( ) {
219
+ let run_stage = |opts : & mut Options | {
220
+ opts. optopt (
221
+ "" ,
222
+ "run-stage" ,
223
+ "stage to run, in terms of which libraries it runs with (e.g. `--run-stage 1` means use `build/stage1/bin`). \
224
+ This is an alias for `--stage`.",
225
+ "N" ,
226
+ ) ;
227
+ Some ( "run-stage" )
228
+ } ;
229
+ let link_stage = |opts : & mut Options | {
230
+ opts. optopt (
231
+ "" ,
232
+ "link-stage" ,
233
+ "stage to use, in terms of what libraries it is linked to (e.g. `--link-stage 1` means use `build/stage1-<component>`). \
234
+ This is an alias for `--stage`.",
235
+ "N" ,
236
+ ) ;
237
+ Some ( "link-stage" )
238
+ } ;
239
+ let extra_stage_arg = match subcommand. as_str ( ) {
220
240
"test" | "t" => {
221
241
opts. optflag ( "" , "no-fail-fast" , "Run all tests regardless of failure" ) ;
222
242
opts. optmulti ( "" , "test-args" , "extra arguments" , "ARGS" ) ;
@@ -247,20 +267,26 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
247
267
"enable this to generate a Rustfix coverage file, which is saved in \
248
268
`/<build_base>/rustfix_missing_coverage.txt`",
249
269
) ;
270
+ run_stage ( & mut opts)
250
271
}
251
272
"bench" => {
252
273
opts. optmulti ( "" , "test-args" , "extra arguments" , "ARGS" ) ;
274
+ link_stage ( & mut opts)
253
275
}
276
+ "build" | "b" => link_stage ( & mut opts) ,
254
277
"doc" => {
255
278
opts. optflag ( "" , "open" , "open the docs in a browser" ) ;
279
+ run_stage ( & mut opts)
256
280
}
257
281
"clean" => {
258
282
opts. optflag ( "" , "all" , "clean all build artifacts" ) ;
283
+ None
259
284
}
260
285
"fmt" => {
261
286
opts. optflag ( "" , "check" , "check formatting instead of applying." ) ;
287
+ None
262
288
}
263
- _ => { }
289
+ _ => None ,
264
290
} ;
265
291
266
292
// Done specifying what options are possible, so do the getopts parsing
@@ -517,9 +543,21 @@ Arguments:
517
543
}
518
544
}
519
545
546
+ let parse_stage =
547
+ |name| -> Option < u32 > { matches. opt_get ( name) . expect ( "`stage` should be a number" ) } ;
548
+ // We ensure above that `run-stage` and `link-stage` are mutually exclusive
549
+ let stage = match ( parse_stage ( "stage" ) , extra_stage_arg. and_then ( parse_stage) ) {
550
+ ( None , None ) => None ,
551
+ ( Some ( x) , None ) | ( None , Some ( x) ) => Some ( x) ,
552
+ ( Some ( _) , Some ( _) ) => {
553
+ println ! ( "--stage, --run-stage, and --link-stage are mutually exclusive" ) ;
554
+ process:: exit ( 1 ) ;
555
+ }
556
+ } ;
557
+
520
558
Flags {
521
559
verbose : matches. opt_count ( "verbose" ) ,
522
- stage : matches . opt_str ( "stage" ) . map ( |j| j . parse ( ) . expect ( "`stage` should be a number" ) ) ,
560
+ stage,
523
561
dry_run : matches. opt_present ( "dry-run" ) ,
524
562
on_fail : matches. opt_str ( "on-fail" ) ,
525
563
rustc_error_format : matches. opt_str ( "error-format" ) ,
0 commit comments