Don't push empty paths in LD_LIBRARY_PATH
authorMatt Brubeck <mbrubeck@limpet.net>
Thu, 13 Jul 2017 03:28:39 +0000 (20:28 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 13 Jul 2017 13:56:22 +0000 (06:56 -0700)
Fixes #4277.

src/cargo/ops/cargo_rustc/compilation.rs
tests/build.rs

index be3e16a04375539e5ccf006c0952925f9049fe57..f1227f3dca5565a72bea9b8dde38c1b9a470ecbf 100644 (file)
@@ -125,7 +125,7 @@ impl<'cfg> Compilation<'cfg> {
 
         let mut search_path = if is_host {
             let mut search_path = vec![self.plugins_dylib_path.clone()];
-            search_path.push(self.host_dylib_path.iter().collect());
+            search_path.extend(self.host_dylib_path.clone());
             search_path
         } else {
             let mut search_path =
@@ -133,7 +133,7 @@ impl<'cfg> Compilation<'cfg> {
                                                   &self.root_output);
             search_path.push(self.root_output.clone());
             search_path.push(self.deps_output.clone());
-            search_path.push(self.target_dylib_path.iter().collect());
+            search_path.extend(self.target_dylib_path.clone());
             search_path
         };
 
index a5293b31424116bac7a00e92ebc8cf4939e3f434..89135fc6013083719eeaccad9db0989c77c46cbe 100644 (file)
@@ -7,6 +7,7 @@ use std::env;
 use std::fs::{self, File};
 use std::io::prelude::*;
 
+use cargo::util::paths::dylib_path_envvar;
 use cargo::util::process;
 use cargotest::{is_nightly, rustc_host, sleep_ms};
 use cargotest::support::paths::{CargoPathExt,root};
@@ -977,6 +978,47 @@ fn crate_authors_env_vars() {
                 execs().with_status(0));
 }
 
+// Regression test for #4277
+#[test]
+fn crate_library_path_env_var() {
+    let mut p = project("foo");
+
+    p = p.file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", &format!(r##"
+            fn main() {{
+                let search_path = env!("{}");
+                let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
+                assert!(!paths.contains(&"".into()));
+            }}
+        "##, dylib_path_envvar()));
+
+    assert_that(p.cargo_process("run"), execs().with_status(0));
+}
+
+// Regression test for #4277
+#[test]
+fn build_with_fake_libc_not_loading() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/lib.rs", r#" "#)
+        .file("libc.so.6", r#""#);
+
+    assert_that(p.cargo_process("build"), execs().with_status(0));
+}
+
 // this is testing that src/<pkg-name>.rs still works (for now)
 #[test]
 fn many_crate_types_old_style_lib_location() {