Remove find_host_deps and use Compilation field.
authorLucas Kolstad <lkolstad@uw.edu>
Wed, 30 Aug 2017 22:16:52 +0000 (15:16 -0700)
committerLucas Kolstad <lkolstad@uw.edu>
Wed, 30 Aug 2017 22:16:52 +0000 (15:16 -0700)
This patch removes the addition of the find_host_deps() function by
adding a host_deps_output field to the Compilation struct instead. The
test case is altered to not use an external crate from crates.io but
instead use the Package.publish(..) method.

src/cargo/ops/cargo_rustc/compilation.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_test.rs
tests/test.rs

index f1227f3dca5565a72bea9b8dde38c1b9a470ecbf..2f5c4855353d6267827ce4193a5fd0f1bf312abe 100644 (file)
@@ -28,9 +28,13 @@ pub struct Compilation<'cfg> {
     /// Root output directory (for the local package's artifacts)
     pub root_output: PathBuf,
 
-    /// Output directory for rust dependencies
+    /// Output directory for rust dependencies.
+    /// May be for the host or for a specific target.
     pub deps_output: PathBuf,
 
+    /// Output directory for the rust host dependencies.
+    pub host_deps_output: PathBuf,
+
     /// Library search path for compiler plugins and build scripts
     /// which have dynamic dependencies.
     pub plugins_dylib_path: PathBuf,
@@ -64,6 +68,7 @@ impl<'cfg> Compilation<'cfg> {
             native_dirs: HashSet::new(),  // TODO: deprecated, remove
             root_output: PathBuf::from("/"),
             deps_output: PathBuf::from("/"),
+            host_deps_output: PathBuf::from("/"),
             plugins_dylib_path: PathBuf::from("/"),
             host_dylib_path: None,
             target_dylib_path: None,
index 865f8b42a50d64400fc0dbb65603891db050d238..0d34df739efb9845a0293be53e4da71c7e840181 100755 (executable)
@@ -176,6 +176,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         }
 
         self.compilation.plugins_dylib_path = self.host.deps().to_path_buf();
+        self.compilation.host_deps_output = self.host.deps().to_path_buf();
 
         let layout = self.target.as_ref().unwrap_or(&self.host);
         self.compilation.root_output = layout.dest().to_path_buf();
index d6c1717f86138e95ef9f09dc8fdfc2164c1d0b43..32c92e7315674d48c6f19be2d8b63c7c5b9e3e91 100644 (file)
@@ -126,7 +126,6 @@ fn run_doc_tests(options: &TestOptions,
                  -> CargoResult<(Test, Vec<ProcessError>)> {
     let mut errors = Vec::new();
     let config = options.compile_opts.config;
-    let host_deps = find_host_deps(options, compilation);
 
     // We don't build/rust doctests if target != host
     if config.rustc()?.host != compilation.target {
@@ -145,17 +144,22 @@ fn run_doc_tests(options: &TestOptions,
             p.arg("--test").arg(lib)
              .arg("--crate-name").arg(&crate_name);
 
-            p.arg("-L").arg(&host_deps);
-
             for &rust_dep in &[&compilation.deps_output] {
                 let mut arg = OsString::from("dependency=");
                 arg.push(rust_dep);
                 p.arg("-L").arg(arg);
             }
+
             for native_dep in compilation.native_dirs.iter() {
                 p.arg("-L").arg(native_dep);
             }
 
+            for &host_rust_dep in &[&compilation.host_deps_output] {
+                let mut arg = OsString::from("dependency=");
+                arg.push(host_rust_dep);
+                p.arg("-L").arg(arg);
+            }
+
             for arg in test_args {
                 p.arg("--test-args").arg(arg);
             }
@@ -201,24 +205,3 @@ fn run_doc_tests(options: &TestOptions,
     }
     Ok((Test::Doc, errors))
 }
-
-fn find_host_deps(options: &TestOptions, compilation: &Compilation) -> OsString {
-    let build_type = if options.compile_opts.release { "release" } else { "debug" };
-    let mut dir = compilation.root_output.clone();
-
-    // first pop off the build_type
-    dir.pop();
-    // if we see the target next, pop it off
-    let target: &OsStr = compilation.target.as_ref();
-    if dir.file_name().unwrap() == target {
-        dir.pop();
-    }
-    // push the build_type back on
-    dir.push(build_type);
-    // and we are looking for the deps directory
-    dir.push("deps");
-
-    let mut host_deps = OsString::from("dependency=");
-    host_deps.push(dir);
-    host_deps
-}
index adb89f9190a01057a4dd2322238348bc18926cc8..40642db91ccf6a5339b508dfa67eea4765c7cefa 100644 (file)
@@ -2816,10 +2816,10 @@ fn find_dependency_of_proc_macro_dependency_with_target() {
             proc-macro = true
 
             [dependencies]
-            base64 = "^0.6"
+            dep_of_proc_macro_dep = "^0.1"
         "#)
         .file("proc_macro_dep/src/lib.rs", r#"
-            extern crate base64;
+            extern crate dep_of_proc_macro_dep;
             extern crate proc_macro;
             use proc_macro::TokenStream;
 
@@ -2828,6 +2828,7 @@ fn find_dependency_of_proc_macro_dependency_with_target() {
                 "".parse().unwrap()
             }
         "#);
+        Package::new("dep_of_proc_macro_dep", "0.1.0").publish();
         workspace.build();
     assert_that(workspace.cargo("test").arg("--all").arg("--target").arg(rustc_host()),
                 execs().with_status(0));