@@ -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
}
@@ -431,43 +432,53 @@ pub enum Kind {
431
432
Check ,
432
433
Clippy ,
433
434
Fix ,
435
+ Format ,
434
436
Test ,
435
437
Bench ,
436
- Dist ,
437
438
Doc ,
439
+ Clean ,
440
+ Dist ,
438
441
Install ,
439
442
Run ,
443
+ Setup ,
440
444
}
441
445
442
446
impl Kind {
443
- fn parse ( string : & str ) -> Kind {
444
- match string {
445
- "build" => Kind :: Build ,
446
- "check" => Kind :: Check ,
447
+ pub fn parse ( string : & str ) -> Option < Kind > {
448
+ // these strings, including the one-letter aliases, must match the x.py help text
449
+ Some ( match string {
450
+ "build" | "b" => Kind :: Build ,
451
+ "check" | "c" => Kind :: Check ,
447
452
"clippy" => Kind :: Clippy ,
448
453
"fix" => Kind :: Fix ,
449
- "test" => Kind :: Test ,
454
+ "fmt" => Kind :: Format ,
455
+ "test" | "t" => Kind :: Test ,
450
456
"bench" => Kind :: Bench ,
457
+ "doc" | "d" => Kind :: Doc ,
458
+ "clean" => Kind :: Clean ,
451
459
"dist" => Kind :: Dist ,
452
- "doc" => Kind :: Doc ,
453
460
"install" => Kind :: Install ,
454
- "run" => Kind :: Run ,
455
- other => panic ! ( "unknown kind: {}" , other) ,
456
- }
461
+ "run" | "r" => Kind :: Run ,
462
+ "setup" => Kind :: Setup ,
463
+ _ => return None ,
464
+ } )
457
465
}
458
466
459
- fn as_str ( & self ) -> & ' static str {
467
+ pub fn as_str ( & self ) -> & ' static str {
460
468
match self {
461
469
Kind :: Build => "build" ,
462
470
Kind :: Check => "check" ,
463
471
Kind :: Clippy => "clippy" ,
464
472
Kind :: Fix => "fix" ,
473
+ Kind :: Format => "fmt" ,
465
474
Kind :: Test => "test" ,
466
475
Kind :: Bench => "bench" ,
467
- Kind :: Dist => "dist" ,
468
476
Kind :: Doc => "doc" ,
477
+ Kind :: Clean => "clean" ,
478
+ Kind :: Dist => "dist" ,
469
479
Kind :: Install => "install" ,
470
480
Kind :: Run => "run" ,
481
+ Kind :: Setup => "setup" ,
471
482
}
472
483
}
473
484
}
@@ -511,7 +522,7 @@ impl<'a> Builder<'a> {
511
522
native:: Lld ,
512
523
native:: CrtBeginEnd
513
524
) ,
514
- Kind :: Check | Kind :: Clippy { .. } | Kind :: Fix => describe ! (
525
+ Kind :: Check => describe ! (
515
526
check:: Std ,
516
527
check:: Rustc ,
517
528
check:: Rustdoc ,
@@ -641,32 +652,29 @@ impl<'a> Builder<'a> {
641
652
install:: Rustc
642
653
) ,
643
654
Kind :: Run => describe ! ( run:: ExpandYamlAnchors , run:: BuildManifest , run:: BumpStage0 ) ,
655
+ // These commands either don't use paths, or they're special-cased in Build::build()
656
+ Kind :: Clean | Kind :: Clippy | Kind :: Fix | Kind :: Format | Kind :: Setup => vec ! [ ] ,
644
657
}
645
658
}
646
659
647
- pub fn get_help ( build : & Build , subcommand : & str ) -> Option < String > {
648
- let kind = match subcommand {
649
- "build" | "b" => Kind :: Build ,
650
- "doc" | "d" => Kind :: Doc ,
651
- "test" | "t" => Kind :: Test ,
652
- "bench" => Kind :: Bench ,
653
- "dist" => Kind :: Dist ,
654
- "install" => Kind :: Install ,
655
- _ => return None ,
656
- } ;
660
+ pub fn get_help ( build : & Build , kind : Kind ) -> Option < String > {
661
+ let step_descriptions = Builder :: get_step_descriptions ( kind) ;
662
+ if step_descriptions. is_empty ( ) {
663
+ return None ;
664
+ }
657
665
658
666
let builder = Self :: new_internal ( build, kind, vec ! [ ] ) ;
659
667
let builder = & builder;
660
668
// The "build" kind here is just a placeholder, it will be replaced with something else in
661
669
// the following statement.
662
670
let mut should_run = ShouldRun :: new ( builder, Kind :: Build ) ;
663
- for desc in Builder :: get_step_descriptions ( builder . kind ) {
671
+ for desc in step_descriptions {
664
672
should_run. kind = desc. kind ;
665
673
should_run = ( desc. should_run ) ( should_run) ;
666
674
}
667
675
let mut help = String :: from ( "Available paths:\n " ) ;
668
676
let mut add_path = |path : & Path | {
669
- help . push_str ( & format ! ( " ./x.py {} {}\n " , subcommand , path. display( ) ) ) ;
677
+ t ! ( write! ( help , " ./x.py {} {}\n " , kind . as_str ( ) , path. display( ) ) ) ;
670
678
} ;
671
679
for pathset in should_run. paths {
672
680
match pathset {
0 commit comments