pub mod nodemap;
pub mod lev_distance;
pub mod num;
+ pub mod fs;
}
pub mod lib {
use std::path::{Path, PathBuf};
use session::search_paths::{SearchPaths, PathKind};
+use util::fs as rustcfs;
#[derive(Copy, Clone)]
pub enum FileMatch {
fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
path.and_then(|path| {
match fs::canonicalize(&path) {
- Ok(canon) => Some(canon),
+ // See comments on this target function, but the gist is that
+ // gcc chokes on verbatim paths which fs::canonicalize generates
+ // so we try to avoid those kinds of paths.
+ Ok(canon) => Some(rustcfs::fix_windows_verbatim_for_gcc(&canon)),
Err(e) => panic!("failed to get realpath: {}", e),
}
})
pub entry_type: Cell<Option<config::EntryFnType>>,
pub plugin_registrar_fn: Cell<Option<ast::NodeId>>,
pub default_sysroot: Option<PathBuf>,
- // The name of the root source file of the crate, in the local file system. The path is always
- // expected to be absolute. `None` means that there is no source file.
+ // The name of the root source file of the crate, in the local file system.
+ // The path is always expected to be absolute. `None` means that there is no
+ // source file.
pub local_crate_source_file: Option<PathBuf>,
pub working_dir: PathBuf,
pub lint_store: RefCell<lint::LintStore>,
--- /dev/null
+// 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)
+}
let mut _old_path = OsString::new();
if cfg!(windows) {
_old_path = env::var_os("PATH").unwrap_or(_old_path);
- let mut new_path = sess.host_filesearch(PathKind::All).get_dylib_search_paths();
+ let mut new_path = sess.host_filesearch(PathKind::All)
+ .get_dylib_search_paths();
new_path.extend(env::split_paths(&_old_path));
env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap());
}
use util::common::time;
use util::ppaux;
use util::sha2::{Digest, Sha256};
+use util::fs::fix_windows_verbatim_for_gcc;
use rustc_back::tempdir::TempDir;
use std::ffi::OsString;
use std::fs::{self, PathExt};
use std::io::{self, Read, Write};
use std::mem;
-use std::path::{self, Path, PathBuf};
+use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;
use flate;
}
}
}
-
-// 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...
-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)
-}