Simplify `build_map`
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 23 Mar 2018 09:20:01 +0000 (12:20 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 23 Mar 2018 09:20:01 +0000 (12:20 +0300)
This doesn't change semantics, but helps us not to rebuild BuildScripts
twice, and makes sure that we fail with assert if somehow we get cyclic
deps

src/cargo/ops/cargo_rustc/custom_build.rs

index 32fb3ef74e3523bcc495e7b1e42cf23e04d7e3b2..0457eecc1ec0fbf136b91f23a6b97204e7f39886 100644 (file)
@@ -1,4 +1,5 @@
-use std::collections::{BTreeSet, HashMap, HashSet};
+use std::collections::{BTreeSet, HashSet};
+use std::collections::hash_map::{Entry, HashMap};
 use std::fs;
 use std::path::{Path, PathBuf};
 use std::str;
@@ -597,12 +598,10 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>, units: &[Unit<'b>]) -> Ca
             }
         }
 
-        let prev = out.entry(*unit).or_insert_with(BuildScripts::default);
-        for (pkg, kind) in ret.to_link {
-            add_to_link(prev, &pkg, kind);
+        match out.entry(*unit) {
+            Entry::Vacant(entry) => Ok(entry.insert(ret)),
+            Entry::Occupied(_) => panic!("cyclic dependencies in `build_map`"),
         }
-        prev.plugins.extend(ret.plugins);
-        Ok(prev)
     }
 
     // When adding an entry to 'to_link' we only actually push it on if the