@@ -985,6 +985,8 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
985
985
// 2. Next, we determine which rules we're actually executing. If a
986
986
// number of path filters were specified on the command line we look
987
987
// for those, otherwise we look for anything tagged `default`.
988
+ // Here we also compute the priority of each rule based on how early
989
+ // in the command line the matching path filter showed up.
988
990
//
989
991
// 3. Finally, we generate some steps with host and target information.
990
992
//
@@ -1015,11 +1017,22 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
1015
1017
Subcommand :: Clean => panic ! ( ) ,
1016
1018
} ;
1017
1019
1018
- self . rules . values ( ) . filter ( |rule| rule. kind == kind) . filter ( |rule| {
1019
- ( paths. len ( ) == 0 && rule. default ) || paths. iter ( ) . any ( |path| {
1020
- path. ends_with ( rule. path )
1021
- } )
1022
- } ) . flat_map ( |rule| {
1020
+ let mut rules: Vec < _ > = self . rules . values ( ) . filter_map ( |rule| {
1021
+ if rule. kind != kind {
1022
+ return None ;
1023
+ }
1024
+
1025
+ if paths. len ( ) == 0 && rule. default {
1026
+ Some ( ( rule, 0 ) )
1027
+ } else {
1028
+ paths. iter ( ) . position ( |path| path. ends_with ( rule. path ) )
1029
+ . map ( |priority| ( rule, priority) )
1030
+ }
1031
+ } ) . collect ( ) ;
1032
+
1033
+ rules. sort_by_key ( |& ( _, priority) | priority) ;
1034
+
1035
+ rules. into_iter ( ) . flat_map ( |( rule, _) | {
1023
1036
let hosts = if rule. only_host_build || rule. only_build {
1024
1037
& self . build . config . host [ ..1 ]
1025
1038
} else if self . build . flags . host . len ( ) > 0 {
0 commit comments