@@ -216,7 +216,27 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
216216 } ;
217217
218218 // 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 ( ) {
220240 "test" | "t" => {
221241 opts. optflag ( "" , "no-fail-fast" , "Run all tests regardless of failure" ) ;
222242 opts. optmulti ( "" , "test-args" , "extra arguments" , "ARGS" ) ;
@@ -247,20 +267,26 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
247267 "enable this to generate a Rustfix coverage file, which is saved in \
248268 `/<build_base>/rustfix_missing_coverage.txt`",
249269 ) ;
270+ run_stage ( & mut opts)
250271 }
251272 "bench" => {
252273 opts. optmulti ( "" , "test-args" , "extra arguments" , "ARGS" ) ;
274+ link_stage ( & mut opts)
253275 }
276+ "build" | "b" => link_stage ( & mut opts) ,
254277 "doc" => {
255278 opts. optflag ( "" , "open" , "open the docs in a browser" ) ;
279+ run_stage ( & mut opts)
256280 }
257281 "clean" => {
258282 opts. optflag ( "" , "all" , "clean all build artifacts" ) ;
283+ None
259284 }
260285 "fmt" => {
261286 opts. optflag ( "" , "check" , "check formatting instead of applying." ) ;
287+ None
262288 }
263- _ => { }
289+ _ => None ,
264290 } ;
265291
266292 // Done specifying what options are possible, so do the getopts parsing
@@ -517,9 +543,21 @@ Arguments:
517543 }
518544 }
519545
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+
520558 Flags {
521559 verbose : matches. opt_count ( "verbose" ) ,
522- stage : matches . opt_str ( "stage" ) . map ( |j| j . parse ( ) . expect ( "`stage` should be a number" ) ) ,
560+ stage,
523561 dry_run : matches. opt_present ( "dry-run" ) ,
524562 on_fail : matches. opt_str ( "on-fail" ) ,
525563 rustc_error_format : matches. opt_str ( "error-format" ) ,
0 commit comments