2828
2929use std:: collections:: { HashMap , HashSet } ;
3030use std:: mem;
31+ use std:: cmp:: min;
3132
3233use check:: { self , TestKind } ;
3334use compile;
@@ -982,10 +983,14 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
982983 // product of the two and then create a step based off them. Note that
983984 // the stage each step is associated was specified with the `--step`
984985 // flag on the command line.
986+ let mut split = None ;
985987 let ( kind, paths) = match self . build . flags . cmd {
986988 Subcommand :: Build { ref paths } => ( Kind :: Build , & paths[ ..] ) ,
987989 Subcommand :: Doc { ref paths } => ( Kind :: Doc , & paths[ ..] ) ,
988- Subcommand :: Test { ref paths, test_args : _ } => ( Kind :: Test , & paths[ ..] ) ,
990+ Subcommand :: Test { ref paths, test_args : _, split : new_split } => {
991+ split = new_split;
992+ ( Kind :: Test , & paths[ ..] )
993+ }
989994 Subcommand :: Bench { ref paths, test_args : _ } => ( Kind :: Bench , & paths[ ..] ) ,
990995 Subcommand :: Dist { ref paths, install } => {
991996 if install {
@@ -996,8 +1001,7 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
9961001 }
9971002 Subcommand :: Clean => panic ! ( ) ,
9981003 } ;
999-
1000- self . rules . values ( ) . filter ( |rule| rule. kind == kind) . filter ( |rule| {
1004+ let steps = self . rules . values ( ) . filter ( |rule| rule. kind == kind) . filter ( |rule| {
10011005 ( paths. len ( ) == 0 && rule. default ) || paths. iter ( ) . any ( |path| {
10021006 path. ends_with ( rule. path )
10031007 } )
@@ -1041,7 +1045,23 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
10411045 self . sbuild . name ( rule. name ) . target ( target) . host ( host)
10421046 } )
10431047 } )
1044- } ) . collect ( )
1048+ } ) . collect :: < Vec < _ > > ( ) ;
1049+
1050+ if let Some ( ( offset, nb_split) ) = split {
1051+ assert ! ( nb_split <= steps. len( ) ,
1052+ "you asked for {} slices but there are only {} tasks" ,
1053+ nb_split,
1054+ steps. len( ) ) ;
1055+ let index = |i| {
1056+ i * ( steps. len ( ) / nb_split) + min ( steps. len ( ) % nb_split, i)
1057+ } ;
1058+ let from = index ( offset) ;
1059+ let to = index ( offset + 1 ) ;
1060+ steps[ from..to] . into ( )
1061+ } else {
1062+ steps
1063+ }
1064+
10451065 }
10461066
10471067 /// Execute all top-level targets indicated by `steps`.
0 commit comments