diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-05-05 15:19:36 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-05-05 15:21:52 -0700 |
| commit | 2dc0e561634d91bd788e86461b08f2eb52049ac7 (patch) | |
| tree | ca51ec0f4981f1e924ef793da8bb562bd49ed018 /src/librustc/util | |
| parent | 70db76602e0fbd88c718e4f564b90a8819978773 (diff) | |
| download | rust-2dc0e561634d91bd788e86461b08f2eb52049ac7.tar.gz rust-2dc0e561634d91bd788e86461b08f2eb52049ac7.zip | |
rustc: Fix more verbatim paths leaking to gcc
Turns out that a verbatim path was leaking through to gcc via the PATH environment variable (pointing to the bundled gcc provided by the main distribution) which was wreaking havoc when gcc itself was run. The fix here is to just stop passing verbatim paths down by adding more liberal uses of `fix_windows_verbatim_for_gcc`. Closes #25072
Diffstat (limited to 'src/librustc/util')
| -rw-r--r-- | src/librustc/util/fs.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/librustc/util/fs.rs b/src/librustc/util/fs.rs new file mode 100644 index 00000000000..3ae78fa7c19 --- /dev/null +++ b/src/librustc/util/fs.rs @@ -0,0 +1,38 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::path::{self, Path, PathBuf}; +use std::ffi::OsString; + +// Unfortunately, on windows, gcc cannot accept paths of the form `\\?\C:\...` +// (a verbatim path). This form of path is generally pretty rare, but the +// implementation of `fs::canonicalize` currently generates paths of this form, +// meaning that we're going to be passing quite a few of these down to gcc. +// +// For now we just strip the "verbatim prefix" of `\\?\` from the path. This +// will probably lose information in some cases, but there's not a whole lot +// more we can do with a buggy gcc... +pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf { + if !cfg!(windows) { + return p.to_path_buf() + } + let mut components = p.components(); + let prefix = match components.next() { + Some(path::Component::Prefix(p)) => p, + _ => return p.to_path_buf(), + }; + let disk = match prefix.kind() { + path::Prefix::VerbatimDisk(disk) => disk, + _ => return p.to_path_buf(), + }; + let mut base = OsString::from(format!("{}:", disk as char)); + base.push(components.as_path()); + PathBuf::from(base) +} |
