@@ -3,7 +3,7 @@ use std::cell::{Cell, RefCell};
3
3
use std:: collections:: BTreeSet ;
4
4
use std:: env;
5
5
use std:: ffi:: OsStr ;
6
- use std:: fmt:: Debug ;
6
+ use std:: fmt:: { Debug , Write } ;
7
7
use std:: fs;
8
8
use std:: hash:: Hash ;
9
9
use std:: ops:: Deref ;
@@ -125,7 +125,8 @@ impl TaskPath {
125
125
if found_kind. is_empty ( ) {
126
126
panic ! ( "empty kind in task path {}" , path. display( ) ) ;
127
127
}
128
- kind = Some ( Kind :: parse ( found_kind) ) ;
128
+ kind = Kind :: parse ( found_kind) ;
129
+ assert ! ( kind. is_some( ) ) ;
129
130
path = Path :: new ( found_prefix) . join ( components. as_path ( ) ) ;
130
131
}
131
132
}
@@ -406,43 +407,53 @@ pub enum Kind {
406
407
Check ,
407
408
Clippy ,
408
409
Fix ,
410
+ Format ,
409
411
Test ,
410
412
Bench ,
411
- Dist ,
412
413
Doc ,
414
+ Clean ,
415
+ Dist ,
413
416
Install ,
414
417
Run ,
418
+ Setup ,
415
419
}
416
420
417
421
impl Kind {
418
- fn parse ( string : & str ) -> Kind {
419
- match string {
420
- "build" => Kind :: Build ,
421
- "check" => Kind :: Check ,
422
+ pub fn parse ( string : & str ) -> Option < Kind > {
423
+ // these strings, including the one-letter aliases, must match the x.py help text
424
+ Some ( match string {
425
+ "build" | "b" => Kind :: Build ,
426
+ "check" | "c" => Kind :: Check ,
422
427
"clippy" => Kind :: Clippy ,
423
428
"fix" => Kind :: Fix ,
424
- "test" => Kind :: Test ,
429
+ "fmt" => Kind :: Format ,
430
+ "test" | "t" => Kind :: Test ,
425
431
"bench" => Kind :: Bench ,
432
+ "doc" | "d" => Kind :: Doc ,
433
+ "clean" => Kind :: Clean ,
426
434
"dist" => Kind :: Dist ,
427
- "doc" => Kind :: Doc ,
428
435
"install" => Kind :: Install ,
429
- "run" => Kind :: Run ,
430
- other => panic ! ( "unknown kind: {}" , other) ,
431
- }
436
+ "run" | "r" => Kind :: Run ,
437
+ "setup" => Kind :: Setup ,
438
+ _ => return None ,
439
+ } )
432
440
}
433
441
434
- fn as_str ( & self ) -> & ' static str {
442
+ pub fn as_str ( & self ) -> & ' static str {
435
443
match self {
436
444
Kind :: Build => "build" ,
437
445
Kind :: Check => "check" ,
438
446
Kind :: Clippy => "clippy" ,
439
447
Kind :: Fix => "fix" ,
448
+ Kind :: Format => "fmt" ,
440
449
Kind :: Test => "test" ,
441
450
Kind :: Bench => "bench" ,
442
- Kind :: Dist => "dist" ,
443
451
Kind :: Doc => "doc" ,
452
+ Kind :: Clean => "clean" ,
453
+ Kind :: Dist => "dist" ,
444
454
Kind :: Install => "install" ,
445
455
Kind :: Run => "run" ,
456
+ Kind :: Setup => "setup" ,
446
457
}
447
458
}
448
459
}
@@ -486,7 +497,7 @@ impl<'a> Builder<'a> {
486
497
native:: Lld ,
487
498
native:: CrtBeginEnd
488
499
) ,
489
- Kind :: Check | Kind :: Clippy { .. } | Kind :: Fix => describe ! (
500
+ Kind :: Check => describe ! (
490
501
check:: Std ,
491
502
check:: Rustc ,
492
503
check:: Rustdoc ,
@@ -616,32 +627,29 @@ impl<'a> Builder<'a> {
616
627
install:: Rustc
617
628
) ,
618
629
Kind :: Run => describe ! ( run:: ExpandYamlAnchors , run:: BuildManifest , run:: BumpStage0 ) ,
630
+ // These commands either don't use paths, or they're special-cased in Build::build()
631
+ Kind :: Clean | Kind :: Clippy | Kind :: Fix | Kind :: Format | Kind :: Setup => vec ! [ ] ,
619
632
}
620
633
}
621
634
622
- pub fn get_help ( build : & Build , subcommand : & str ) -> Option < String > {
623
- let kind = match subcommand {
624
- "build" | "b" => Kind :: Build ,
625
- "doc" | "d" => Kind :: Doc ,
626
- "test" | "t" => Kind :: Test ,
627
- "bench" => Kind :: Bench ,
628
- "dist" => Kind :: Dist ,
629
- "install" => Kind :: Install ,
630
- _ => return None ,
631
- } ;
635
+ pub fn get_help ( build : & Build , kind : Kind ) -> Option < String > {
636
+ let step_descriptions = Builder :: get_step_descriptions ( kind) ;
637
+ if step_descriptions. is_empty ( ) {
638
+ return None ;
639
+ }
632
640
633
641
let builder = Self :: new_internal ( build, kind, vec ! [ ] ) ;
634
642
let builder = & builder;
635
643
// The "build" kind here is just a placeholder, it will be replaced with something else in
636
644
// the following statement.
637
645
let mut should_run = ShouldRun :: new ( builder, Kind :: Build ) ;
638
- for desc in Builder :: get_step_descriptions ( builder . kind ) {
646
+ for desc in step_descriptions {
639
647
should_run. kind = desc. kind ;
640
648
should_run = ( desc. should_run ) ( should_run) ;
641
649
}
642
650
let mut help = String :: from ( "Available paths:\n " ) ;
643
651
let mut add_path = |path : & Path | {
644
- help . push_str ( & format ! ( " ./x.py {} {}\n " , subcommand , path. display( ) ) ) ;
652
+ t ! ( write! ( help , " ./x.py {} {}\n " , kind . as_str ( ) , path. display( ) ) ) ;
645
653
} ;
646
654
for pathset in should_run. paths {
647
655
match pathset {
0 commit comments