From e3177c6f3f164a4ff28d246c5028123251942164 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 3 Aug 2018 15:31:03 -0600 Subject: [PATCH] Move rustc::util::fs into separate (new) crate --- src/Cargo.lock | 6 ++++++ src/librustc/Cargo.toml | 1 + src/librustc/lib.rs | 2 +- src/librustc/session/filesearch.rs | 4 ++-- src/librustc_codegen_llvm/back/link.rs | 2 +- src/librustc_codegen_llvm/back/write.rs | 2 +- src/librustc_codegen_llvm/lib.rs | 1 + src/librustc_fs_util/Cargo.toml | 11 +++++++++++ .../util/fs.rs => librustc_fs_util/lib.rs} | 16 ++++++++++------ src/librustc_incremental/Cargo.toml | 1 + src/librustc_incremental/lib.rs | 1 + src/librustc_incremental/persist/fs.rs | 8 ++++---- src/librustc_incremental/persist/work_product.rs | 2 +- 13 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 src/librustc_fs_util/Cargo.toml rename src/{librustc/util/fs.rs => librustc_fs_util/lib.rs} (93%) diff --git a/src/Cargo.lock b/src/Cargo.lock index 2a7dbce2ddc..1ef6b2a571e 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1887,6 +1887,7 @@ dependencies = [ "rustc_apfloat 0.0.0", "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", + "rustc_fs_util 0.0.0", "rustc_target 0.0.0", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", @@ -2185,6 +2186,10 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc_fs_util" +version = "0.0.0" + [[package]] name = "rustc_incremental" version = "0.0.0" @@ -2194,6 +2199,7 @@ dependencies = [ "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_data_structures 0.0.0", + "rustc_fs_util 0.0.0", "serialize 0.0.0", "syntax 0.0.0", "syntax_pos 0.0.0", diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index 457a9f2f625..088b9436d0f 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -32,6 +32,7 @@ backtrace = "0.3.3" parking_lot = "0.5.5" byteorder = { version = "1.1", features = ["i128"]} chalk-engine = { version = "0.6.0", default-features=false } +rustc_fs_util = { path = "../librustc_fs_util" } # Note that these dependencies are a lie, they're just here to get linkage to # work. diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 804481846af..62f244acc9a 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -99,6 +99,7 @@ extern crate syntax_pos; extern crate jobserver; extern crate proc_macro; extern crate chalk_engine; +extern crate rustc_fs_util; extern crate serialize as rustc_serialize; // used by deriving @@ -162,7 +163,6 @@ pub mod util { pub mod common; pub mod ppaux; pub mod nodemap; - pub mod fs; pub mod time_graph; pub mod profiling; } diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs index b636fc6c995..32044fdf2a8 100644 --- a/src/librustc/session/filesearch.rs +++ b/src/librustc/session/filesearch.rs @@ -19,7 +19,7 @@ use std::fs; use std::path::{Path, PathBuf}; use session::search_paths::{SearchPaths, PathKind}; -use util::fs as rustcfs; +use rustc_fs_util::fix_windows_verbatim_for_gcc; #[derive(Copy, Clone)] pub enum FileMatch { @@ -151,7 +151,7 @@ pub fn get_or_default_sysroot() -> PathBuf { // 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)), + Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)), Err(e) => bug!("failed to get realpath: {}", e), } }) diff --git a/src/librustc_codegen_llvm/back/link.rs b/src/librustc_codegen_llvm/back/link.rs index 50d41d76986..bbe1ccf3696 100644 --- a/src/librustc_codegen_llvm/back/link.rs +++ b/src/librustc_codegen_llvm/back/link.rs @@ -26,7 +26,7 @@ use rustc::middle::cstore::{NativeLibrary, LibSource, NativeLibraryKind}; use rustc::middle::dependency_format::Linkage; use {CodegenResults, CrateInfo}; use rustc::util::common::time; -use rustc::util::fs::fix_windows_verbatim_for_gcc; +use rustc_fs_util::fix_windows_verbatim_for_gcc; use rustc::hir::def_id::CrateNum; use tempfile::{Builder as TempFileBuilder, TempDir}; use rustc_target::spec::{PanicStrategy, RelroLevel, LinkerFlavor}; diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index 640e1c1f3d4..7630849d675 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -31,7 +31,7 @@ use rustc::hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc::ty::TyCtxt; use rustc::util::common::{time_ext, time_depth, set_time_depth, print_time_passes_entry}; use rustc::util::common::path2cstr; -use rustc::util::fs::{link_or_copy}; +use rustc_fs_util::link_or_copy; use errors::{self, Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId}; use errors::emitter::{Emitter}; use syntax::attr; diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 9599ccfe979..4572f5891a4 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -55,6 +55,7 @@ extern crate rustc_incremental; extern crate rustc_llvm; extern crate rustc_platform_intrinsics as intrinsics; extern crate rustc_codegen_utils; +extern crate rustc_fs_util; #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustc_fs_util/Cargo.toml b/src/librustc_fs_util/Cargo.toml new file mode 100644 index 00000000000..e40b44204b3 --- /dev/null +++ b/src/librustc_fs_util/Cargo.toml @@ -0,0 +1,11 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_fs_util" +version = "0.0.0" + +[lib] +name = "rustc_fs_util" +path = "lib.rs" +crate-type = ["dylib"] + +[dependencies] diff --git a/src/librustc/util/fs.rs b/src/librustc_fs_util/lib.rs similarity index 93% rename from src/librustc/util/fs.rs rename to src/librustc_fs_util/lib.rs index 090753b18c0..d25e187186e 100644 --- a/src/librustc/util/fs.rs +++ b/src/librustc_fs_util/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,8 +8,7 @@ // 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; +use std::path::{Path, PathBuf}; use std::fs; use std::io; @@ -29,10 +28,10 @@ use std::io; // // For some more information, see this comment: // https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737 +#[cfg(windows)] pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf { - if !cfg!(windows) { - return p.to_path_buf(); - } + use std::path; + use std::ffi::OsString; let mut components = p.components(); let prefix = match components.next() { Some(path::Component::Prefix(p)) => p, @@ -56,6 +55,11 @@ pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf { } } +#[cfg(not(windows))] +pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf { + p.to_path_buf() +} + pub enum LinkOrCopy { Link, Copy, diff --git a/src/librustc_incremental/Cargo.toml b/src/librustc_incremental/Cargo.toml index dd05679589e..c3f6062e799 100644 --- a/src/librustc_incremental/Cargo.toml +++ b/src/librustc_incremental/Cargo.toml @@ -17,3 +17,4 @@ rustc_data_structures = { path = "../librustc_data_structures" } serialize = { path = "../libserialize" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } +rustc_fs_util = { path = "../librustc_fs_util" } diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs index 73886e5e281..c17af24b4d5 100644 --- a/src/librustc_incremental/lib.rs +++ b/src/librustc_incremental/lib.rs @@ -23,6 +23,7 @@ extern crate graphviz; extern crate rustc_data_structures; extern crate serialize as rustc_serialize; extern crate rand; +extern crate rustc_fs_util; #[macro_use] extern crate log; extern crate syntax; diff --git a/src/librustc_incremental/persist/fs.rs b/src/librustc_incremental/persist/fs.rs index 65bc7f3f856..28d53dc7fb3 100644 --- a/src/librustc_incremental/persist/fs.rs +++ b/src/librustc_incremental/persist/fs.rs @@ -115,7 +115,7 @@ //! implemented. use rustc::session::{Session, CrateDisambiguator}; -use rustc::util::fs as fs_util; +use rustc_fs_util::{link_or_copy, LinkOrCopy}; use rustc_data_structures::{flock, base_n}; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; use rustc_data_structures::svh::Svh; @@ -429,11 +429,11 @@ fn copy_files(sess: &Session, let source_path = entry.path(); debug!("copying into session dir: {}", source_path.display()); - match fs_util::link_or_copy(source_path, target_file_path) { - Ok(fs_util::LinkOrCopy::Link) => { + match link_or_copy(source_path, target_file_path) { + Ok(LinkOrCopy::Link) => { files_linked += 1 } - Ok(fs_util::LinkOrCopy::Copy) => { + Ok(LinkOrCopy::Copy) => { files_copied += 1 } Err(_) => return Err(()) diff --git a/src/librustc_incremental/persist/work_product.rs b/src/librustc_incremental/persist/work_product.rs index c0ccbd67a31..cfe59b1f672 100644 --- a/src/librustc_incremental/persist/work_product.rs +++ b/src/librustc_incremental/persist/work_product.rs @@ -13,7 +13,7 @@ use persist::fs::*; use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind}; use rustc::session::Session; -use rustc::util::fs::link_or_copy; +use rustc_fs_util::link_or_copy; use std::path::PathBuf; use std::fs as std_fs;