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