about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-06-08 07:43:29 -0700
committerbors <bors@rust-lang.org>2016-06-08 07:43:29 -0700
commit4b240fe96a8b8fcaa412624c398547dbc447a81e (patch)
treef3aefe96d07bf31edebc5800f42841aa57df606d
parentd3e014e295febf1c286b7261058ba850794aee55 (diff)
parent1564e92940fcc50e566bc5031dbc73540523688d (diff)
downloadrust-4b240fe96a8b8fcaa412624c398547dbc447a81e.tar.gz
rust-4b240fe96a8b8fcaa412624c398547dbc447a81e.zip
Auto merge of #34083 - alexcrichton:dumb-hack, r=nrc
rustc: Try to contain prepends to PATH

This commit attempts to bring our prepends to PATH on Windows when loading
plugins because we've been seeing quite a few issues with failing to spawn a
process on Windows, the leading theory of which is that PATH is too large as a
result of this. Currently this is mostly a stab in the dark as it's not
confirmed to actually fix the problem, but it's probably not a bad change to
have anyway!

cc #33844
Closes #17360
-rw-r--r--src/librustc_driver/driver.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs
index b28d203ed8d..c63122948ff 100644
--- a/src/librustc_driver/driver.rs
+++ b/src/librustc_driver/driver.rs
@@ -669,12 +669,24 @@ pub fn phase_2_configure_and_expand<'a>(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 = OsString::new();
+        //
+        // This is somewhat of an inherently racy operation, however, as
+        // multiple threads calling this function could possibly continue
+        // extending PATH far beyond what it should. To solve this for now we
+        // just don't add any new elements to PATH which are already there
+        // within PATH. This is basically a targeted fix at #17360 for rustdoc
+        // which runs rustc in parallel but has been seen (#33844) to cause
+        // problems with PATH becoming too long.
+        let mut old_path = OsString::new();
         if cfg!(windows) {
-            _old_path = env::var_os("PATH").unwrap_or(_old_path);
+            old_path = env::var_os("PATH").unwrap_or(old_path);
             let mut new_path = sess.host_filesearch(PathKind::All)
                                    .get_dylib_search_paths();
-            new_path.extend(env::split_paths(&_old_path));
+            for path in env::split_paths(&old_path) {
+                if !new_path.contains(&path) {
+                    new_path.push(path);
+                }
+            }
             env::set_var("PATH", &env::join_paths(new_path).unwrap());
         }
         let features = sess.features.borrow();
@@ -694,7 +706,7 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
                                                                    syntax_exts,
                                                                    krate);
         if cfg!(windows) {
-            env::set_var("PATH", &_old_path);
+            env::set_var("PATH", &old_path);
         }
         *sess.available_macros.borrow_mut() = macro_names;
         ret