Move Links into context module
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Sun, 29 Apr 2018 19:45:35 +0000 (21:45 +0200)
committerDirkjan Ochtman <dirkjan@ochtman.nl>
Wed, 2 May 2018 08:03:35 +0000 (10:03 +0200)
src/cargo/core/compiler/context/mod.rs
src/cargo/core/compiler/links.rs [deleted file]
src/cargo/core/compiler/mod.rs

index b9846f5c13e73b915d72bf153e31b73bd45bdd07..1a8230323762d29958ca0191d4a26e4150c7dffc 100644 (file)
@@ -1,11 +1,12 @@
 #![allow(deprecated)]
 use std::collections::{HashMap, HashSet};
+use std::fmt::Write;
 use std::path::PathBuf;
 use std::sync::Arc;
 
 use jobserver::Client;
 
-use core::{Package, PackageId, Target};
+use core::{Package, PackageId, Resolve, Target};
 use core::profiles::Profile;
 use ops::CompileMode;
 use util::errors::{CargoResult, CargoResultExt};
@@ -15,7 +16,6 @@ use super::custom_build::{self, BuildDeps, BuildScripts, BuildState};
 use super::fingerprint::Fingerprint;
 use super::job_queue::JobQueue;
 use super::layout::Layout;
-use super::links::Links;
 use super::{BuildContext, Compilation, Executor, FileFlavor, Kind};
 
 mod unit_dependencies;
@@ -430,3 +430,69 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         Ok(vec!["-C".to_string(), format!("incremental={}", dir)])
     }
 }
+
+#[derive(Default)]
+pub struct Links<'a> {
+    validated: HashSet<&'a PackageId>,
+    links: HashMap<String, &'a PackageId>,
+}
+
+impl<'a> Links<'a> {
+    pub fn new() -> Links<'a> {
+        Links {
+            validated: HashSet::new(),
+            links: HashMap::new(),
+        }
+    }
+
+    pub fn validate(&mut self, resolve: &Resolve, unit: &Unit<'a>) -> CargoResult<()> {
+        if !self.validated.insert(unit.pkg.package_id()) {
+            return Ok(());
+        }
+        let lib = match unit.pkg.manifest().links() {
+            Some(lib) => lib,
+            None => return Ok(()),
+        };
+        if let Some(prev) = self.links.get(lib) {
+            let pkg = unit.pkg.package_id();
+
+            let describe_path = |pkgid: &PackageId| -> String {
+                let dep_path = resolve.path_to_top(pkgid);
+                let mut dep_path_desc = format!("package `{}`", dep_path[0]);
+                for dep in dep_path.iter().skip(1) {
+                    write!(dep_path_desc, "\n    ... which is depended on by `{}`", dep).unwrap();
+                }
+                dep_path_desc
+            };
+
+            bail!(
+                "multiple packages link to native library `{}`, \
+                 but a native library can be linked only once\n\
+                 \n\
+                 {}\nlinks to native library `{}`\n\
+                 \n\
+                 {}\nalso links to native library `{}`",
+                lib,
+                describe_path(prev),
+                lib,
+                describe_path(pkg),
+                lib
+            )
+        }
+        if !unit.pkg
+            .manifest()
+            .targets()
+            .iter()
+            .any(|t| t.is_custom_build())
+        {
+            bail!(
+                "package `{}` specifies that it links to `{}` but does not \
+                 have a custom build script",
+                unit.pkg.package_id(),
+                lib
+            )
+        }
+        self.links.insert(lib.to_string(), unit.pkg.package_id());
+        Ok(())
+    }
+}
diff --git a/src/cargo/core/compiler/links.rs b/src/cargo/core/compiler/links.rs
deleted file mode 100644 (file)
index abcad2a..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-use std::collections::{HashMap, HashSet};
-use std::fmt::Write;
-
-use core::{PackageId, Resolve};
-use util::CargoResult;
-use super::Unit;
-
-#[derive(Default)]
-pub struct Links<'a> {
-    validated: HashSet<&'a PackageId>,
-    links: HashMap<String, &'a PackageId>,
-}
-
-impl<'a> Links<'a> {
-    pub fn new() -> Links<'a> {
-        Links {
-            validated: HashSet::new(),
-            links: HashMap::new(),
-        }
-    }
-
-    pub fn validate(&mut self, resolve: &Resolve, unit: &Unit<'a>) -> CargoResult<()> {
-        if !self.validated.insert(unit.pkg.package_id()) {
-            return Ok(());
-        }
-        let lib = match unit.pkg.manifest().links() {
-            Some(lib) => lib,
-            None => return Ok(()),
-        };
-        if let Some(prev) = self.links.get(lib) {
-            let pkg = unit.pkg.package_id();
-
-            let describe_path = |pkgid: &PackageId| -> String {
-                let dep_path = resolve.path_to_top(pkgid);
-                let mut dep_path_desc = format!("package `{}`", dep_path[0]);
-                for dep in dep_path.iter().skip(1) {
-                    write!(dep_path_desc, "\n    ... which is depended on by `{}`", dep).unwrap();
-                }
-                dep_path_desc
-            };
-
-            bail!(
-                "multiple packages link to native library `{}`, \
-                 but a native library can be linked only once\n\
-                 \n\
-                 {}\nlinks to native library `{}`\n\
-                 \n\
-                 {}\nalso links to native library `{}`",
-                lib,
-                describe_path(prev),
-                lib,
-                describe_path(pkg),
-                lib
-            )
-        }
-        if !unit.pkg
-            .manifest()
-            .targets()
-            .iter()
-            .any(|t| t.is_custom_build())
-        {
-            bail!(
-                "package `{}` specifies that it links to `{}` but does not \
-                 have a custom build script",
-                unit.pkg.package_id(),
-                lib
-            )
-        }
-        self.links.insert(lib.to_string(), unit.pkg.package_id());
-        Ok(())
-    }
-}
index 845d3d2c4fe93b9dbc5e04e3f209cf5fcd8e6534..4e87f66c6f4937aff22d19b2fd96956947030ffa 100644 (file)
@@ -37,7 +37,6 @@ mod fingerprint;
 mod job;
 mod job_queue;
 mod layout;
-mod links;
 mod output_depinfo;
 
 /// Whether an object is for the host arch, or the target arch.