28
28
29
29
use std:: collections:: { HashMap , HashSet } ;
30
30
use std:: mem;
31
+ use std:: cmp:: min;
31
32
32
33
use check:: { self , TestKind } ;
33
34
use compile;
@@ -982,10 +983,14 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
982
983
// product of the two and then create a step based off them. Note that
983
984
// the stage each step is associated was specified with the `--step`
984
985
// flag on the command line.
986
+ let mut split = None ;
985
987
let ( kind, paths) = match self . build . flags . cmd {
986
988
Subcommand :: Build { ref paths } => ( Kind :: Build , & paths[ ..] ) ,
987
989
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
+ }
989
994
Subcommand :: Bench { ref paths, test_args : _ } => ( Kind :: Bench , & paths[ ..] ) ,
990
995
Subcommand :: Dist { ref paths, install } => {
991
996
if install {
@@ -996,8 +1001,7 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
996
1001
}
997
1002
Subcommand :: Clean => panic ! ( ) ,
998
1003
} ;
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| {
1001
1005
( paths. len ( ) == 0 && rule. default ) || paths. iter ( ) . any ( |path| {
1002
1006
path. ends_with ( rule. path )
1003
1007
} )
@@ -1041,7 +1045,23 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
1041
1045
self . sbuild . name ( rule. name ) . target ( target) . host ( host)
1042
1046
} )
1043
1047
} )
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
+
1045
1065
}
1046
1066
1047
1067
/// Execute all top-level targets indicated by `steps`.
0 commit comments