]> git.lizzy.rs Git - rust.git/commitdiff
rustbuild: sort rules by the order of matching CLI paths.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Tue, 28 Feb 2017 18:13:21 +0000 (20:13 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Tue, 28 Feb 2017 18:13:21 +0000 (20:13 +0200)
src/bootstrap/step.rs

index 01431c50ed764f5f4592b8f1484e5984f0897cd4..af99eea3ffb37973a0827abf68a76038656f4735 100644 (file)
@@ -985,6 +985,8 @@ fn plan(&self) -> Vec<Step<'a>> {
         // 2. Next, we determine which rules we're actually executing. If a
         //    number of path filters were specified on the command line we look
         //    for those, otherwise we look for anything tagged `default`.
+        //    Here we also compute the priority of each rule based on how early
+        //    in the command line the matching path filter showed up.
         //
         // 3. Finally, we generate some steps with host and target information.
         //
@@ -1015,11 +1017,22 @@ fn plan(&self) -> Vec<Step<'a>> {
             Subcommand::Clean => panic!(),
         };
 
-        self.rules.values().filter(|rule| rule.kind == kind).filter(|rule| {
-            (paths.len() == 0 && rule.default) || paths.iter().any(|path| {
-                path.ends_with(rule.path)
-            })
-        }).flat_map(|rule| {
+        let mut rules: Vec<_> = self.rules.values().filter_map(|rule| {
+            if rule.kind != kind {
+                return None;
+            }
+
+            if paths.len() == 0 && rule.default {
+                Some((rule, 0))
+            } else {
+                paths.iter().position(|path| path.ends_with(rule.path))
+                     .map(|priority| (rule, priority))
+            }
+        }).collect();
+
+        rules.sort_by_key(|&(_, priority)| priority);
+
+        rules.into_iter().flat_map(|(rule, _)| {
             let hosts = if rule.only_host_build || rule.only_build {
                 &self.build.config.host[..1]
             } else if self.build.flags.host.len() > 0 {