]> git.lizzy.rs Git - rust.git/commitdiff
Append target-specific tools directory ($(RUST)/bin/rustlib/<triple>/bin/) to PATH...
authorVadim Chugunov <vadimcn@gmail.com>
Wed, 3 Sep 2014 07:46:23 +0000 (00:46 -0700)
committerVadim Chugunov <vadimcn@gmail.com>
Thu, 11 Sep 2014 16:40:20 +0000 (09:40 -0700)
so that rustc can invoke them.

src/librustc/driver/driver.rs
src/librustc/metadata/filesearch.rs

index 4c71c2df44d3e167ab159ba25cd1f2f3b4d71215..018bfecd369a7128617b343adc962780b5f112d8 100644 (file)
@@ -32,6 +32,7 @@
 
 use std::io;
 use std::io::fs;
+use std::os;
 use arena::TypedArena;
 use syntax::ast;
 use syntax::attr;
@@ -258,18 +259,26 @@ pub fn phase_2_configure_and_expand(sess: &Session,
             // dependent dlls. Note that this uses cfg!(windows) as opposed to
             // targ_cfg because syntax extensions are always loaded for the host
             // compiler, not for the target.
+            let mut _old_path = String::new();
             if cfg!(windows) {
-                sess.host_filesearch().add_dylib_search_paths();
+                _old_path = os::getenv("PATH").unwrap_or(_old_path);
+                let mut new_path = sess.host_filesearch().get_dylib_search_paths();
+                new_path.push_all_move(os::split_paths(_old_path.as_slice()));
+                os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap());
             }
             let cfg = syntax::ext::expand::ExpansionConfig {
                 deriving_hash_type_parameter: sess.features.default_type_params.get(),
                 crate_name: crate_name.to_string(),
             };
-            syntax::ext::expand::expand_crate(&sess.parse_sess,
+            let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
                                               cfg,
                                               macros,
                                               syntax_exts,
-                                              krate)
+                                              krate);
+            if cfg!(windows) {
+                os::setenv("PATH", _old_path);
+            }
+            ret
         }
     );
 
@@ -509,11 +518,18 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
 pub fn phase_6_link_output(sess: &Session,
                            trans: &CrateTranslation,
                            outputs: &OutputFilenames) {
+    let old_path = os::getenv("PATH").unwrap_or_else(||String::new());
+    let mut new_path = os::split_paths(old_path.as_slice());
+    new_path.push_all_move(sess.host_filesearch().get_tools_search_paths());
+    os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap());
+
     time(sess.time_passes(), "linking", (), |_|
          link::link_binary(sess,
                            trans,
                            outputs,
                            trans.link.crate_name.as_slice()));
+
+    os::setenv("PATH", old_path);
 }
 
 pub fn stop_after_phase_3(sess: &Session) -> bool {
index 49c24b190b22b98003b6786de8b3fac27a214b21..bdabb3efb98ba5dbbb9fb3a4cfb424997d3cbec4 100644 (file)
@@ -13,7 +13,6 @@
 use std::cell::RefCell;
 use std::os;
 use std::io::fs;
-use std::dynamic_lib::DynamicLibrary;
 use std::collections::HashSet;
 
 use util::fs as myfs;
@@ -134,11 +133,24 @@ pub fn new(sysroot: &'a Path,
         }
     }
 
-    pub fn add_dylib_search_paths(&self) {
+    // Returns a list of directories where target-specific dylibs might be located.
+    pub fn get_dylib_search_paths(&self) -> Vec<Path> {
+        let mut paths = Vec::new();
         self.for_each_lib_search_path(|lib_search_path| {
-            DynamicLibrary::prepend_search_path(lib_search_path);
+            paths.push(lib_search_path.clone());
             FileDoesntMatch
-        })
+        });
+        paths
+    }
+
+    // Returns a list of directories where target-specific tool binaries are located.
+    pub fn get_tools_search_paths(&self) -> Vec<Path> {
+        let mut p = Path::new(self.sysroot);
+        p.push(find_libdir(self.sysroot));
+        p.push(rustlibdir());
+        p.push(self.triple);
+        p.push("bin");
+        vec![p]
     }
 }