diff options
Diffstat (limited to 'src/librustc_back/archive.rs')
| -rw-r--r-- | src/librustc_back/archive.rs | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/src/librustc_back/archive.rs b/src/librustc_back/archive.rs index 97b1a8aaaba..a6994387f8d 100644 --- a/src/librustc_back/archive.rs +++ b/src/librustc_back/archive.rs @@ -10,11 +10,12 @@ //! A helper class for dealing with static archives -use std::old_io::fs::PathExtensions; -use std::old_io::process::{Command, ProcessOutput}; -use std::old_io::{fs, TempDir}; -use std::old_io; -use std::os; +use std::env; +use std::fs::{self, TempDir}; +use std::io::prelude::*; +use std::io; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output, Stdio}; use std::str; use syntax::diagnostic::Handler as ErrorHandler; @@ -22,8 +23,8 @@ pub const METADATA_FILENAME: &'static str = "rust.metadata.bin"; pub struct ArchiveConfig<'a> { pub handler: &'a ErrorHandler, - pub dst: Path, - pub lib_search_paths: Vec<Path>, + pub dst: PathBuf, + pub lib_search_paths: Vec<PathBuf>, pub slib_prefix: String, pub slib_suffix: String, pub maybe_ar_prog: Option<String> @@ -31,8 +32,8 @@ pub struct ArchiveConfig<'a> { pub struct Archive<'a> { handler: &'a ErrorHandler, - dst: Path, - lib_search_paths: Vec<Path>, + dst: PathBuf, + lib_search_paths: Vec<PathBuf>, slib_prefix: String, slib_suffix: String, maybe_ar_prog: Option<String> @@ -45,25 +46,25 @@ pub struct ArchiveBuilder<'a> { archive: Archive<'a>, work_dir: TempDir, /// Filename of each member that should be added to the archive. - members: Vec<Path>, + members: Vec<PathBuf>, should_update_symbols: bool, } fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option<String>, args: &str, cwd: Option<&Path>, - paths: &[&Path]) -> ProcessOutput { + paths: &[&Path]) -> Output { let ar = match *maybe_ar_prog { Some(ref ar) => &ar[..], None => "ar" }; let mut cmd = Command::new(ar); - cmd.arg(args).args(paths); + cmd.arg(args).args(paths).stdout(Stdio::piped()).stderr(Stdio::piped()); debug!("{:?}", cmd); match cwd { Some(p) => { - cmd.cwd(p); + cmd.current_dir(p); debug!("inside {:?}", p.display()); } None => {} @@ -75,9 +76,9 @@ fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option<String>, if !o.status.success() { handler.err(&format!("{:?} failed with: {}", cmd, o.status)); handler.note(&format!("stdout ---\n{}", - str::from_utf8(&o.output).unwrap())); + str::from_utf8(&o.stdout).unwrap())); handler.note(&format!("stderr ---\n{}", - str::from_utf8(&o.error).unwrap()) + str::from_utf8(&o.stderr).unwrap()) ); handler.abort_if_errors(); } @@ -93,14 +94,15 @@ fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option<String>, } pub fn find_library(name: &str, osprefix: &str, ossuffix: &str, - search_paths: &[Path], handler: &ErrorHandler) -> Path { + search_paths: &[PathBuf], + handler: &ErrorHandler) -> PathBuf { // On Windows, static libraries sometimes show up as libfoo.a and other // times show up as foo.lib let oslibname = format!("{}{}{}", osprefix, name, ossuffix); let unixlibname = format!("lib{}.a", name); for path in search_paths { - debug!("looking for {} inside {:?}", name, path.display()); + debug!("looking for {} inside {:?}", name, path); let test = path.join(&oslibname[..]); if test.exists() { return test } if oslibname != unixlibname { @@ -142,7 +144,7 @@ impl<'a> Archive<'a> { /// Lists all files in an archive pub fn files(&self) -> Vec<String> { let output = run_ar(self.handler, &self.maybe_ar_prog, "t", None, &[&self.dst]); - let output = str::from_utf8(&output.output).unwrap(); + let output = str::from_utf8(&output.stdout).unwrap(); // use lines_any because windows delimits output with `\r\n` instead of // just `\n` output.lines_any().map(|s| s.to_string()).collect() @@ -172,7 +174,7 @@ impl<'a> ArchiveBuilder<'a> { /// Adds all of the contents of a native library to this archive. This will /// search in the relevant locations for a library named `name`. - pub fn add_native_library(&mut self, name: &str) -> old_io::IoResult<()> { + pub fn add_native_library(&mut self, name: &str) -> io::Result<()> { let location = find_library(name, &self.archive.slib_prefix, &self.archive.slib_suffix, @@ -187,7 +189,7 @@ impl<'a> ArchiveBuilder<'a> { /// This ignores adding the bytecode from the rlib, and if LTO is enabled /// then the object file also isn't added. pub fn add_rlib(&mut self, rlib: &Path, name: &str, - lto: bool) -> old_io::IoResult<()> { + lto: bool) -> io::Result<()> { // Ignoring obj file starting with the crate name // as simple comparison is not enough - there // might be also an extra name suffix @@ -205,11 +207,11 @@ impl<'a> ArchiveBuilder<'a> { } /// Adds an arbitrary file to this archive - pub fn add_file(&mut self, file: &Path) -> old_io::IoResult<()> { - let filename = Path::new(file.filename().unwrap()); + pub fn add_file(&mut self, file: &Path) -> io::Result<()> { + let filename = Path::new(file.file_name().unwrap()); let new_file = self.work_dir.path().join(&filename); try!(fs::copy(file, &new_file)); - self.members.push(filename); + self.members.push(filename.to_path_buf()); Ok(()) } @@ -224,10 +226,10 @@ impl<'a> ArchiveBuilder<'a> { pub fn build(self) -> Archive<'a> { // Get an absolute path to the destination, so `ar` will work even // though we run it from `self.work_dir`. - let abs_dst = os::getcwd().unwrap().join(&self.archive.dst); + let abs_dst = env::current_dir().unwrap().join(&self.archive.dst); assert!(!abs_dst.is_relative()); - let mut args = vec![&abs_dst]; - let mut total_len = abs_dst.as_vec().len(); + let mut args = vec![&*abs_dst]; + let mut total_len = abs_dst.to_string_lossy().len(); if self.members.is_empty() { // OSX `ar` does not allow using `r` with no members, but it does @@ -245,7 +247,7 @@ impl<'a> ArchiveBuilder<'a> { const ARG_LENGTH_LIMIT: uint = 32_000; for member_name in &self.members { - let len = member_name.as_vec().len(); + let len = member_name.to_string_lossy().len(); // `len + 1` to account for the space that's inserted before each // argument. (Windows passes command-line arguments as a single @@ -258,7 +260,7 @@ impl<'a> ArchiveBuilder<'a> { args.clear(); args.push(&abs_dst); - total_len = abs_dst.as_vec().len(); + total_len = abs_dst.to_string_lossy().len(); } args.push(member_name); @@ -275,7 +277,7 @@ impl<'a> ArchiveBuilder<'a> { } fn add_archive<F>(&mut self, archive: &Path, name: &str, - mut skip: F) -> old_io::IoResult<()> + mut skip: F) -> io::Result<()> where F: FnMut(&str) -> bool, { let loc = TempDir::new("rsar").unwrap(); @@ -283,7 +285,7 @@ impl<'a> ArchiveBuilder<'a> { // First, extract the contents of the archive to a temporary directory. // We don't unpack directly into `self.work_dir` due to the possibility // of filename collisions. - let archive = os::getcwd().unwrap().join(archive); + let archive = env::current_dir().unwrap().join(archive); run_ar(self.archive.handler, &self.archive.maybe_ar_prog, "x", Some(loc.path()), &[&archive]); @@ -296,9 +298,10 @@ impl<'a> ArchiveBuilder<'a> { // We skip any files explicitly desired for skipping, and we also skip // all SYMDEF files as these are just magical placeholders which get // re-created when we make a new archive anyway. - let files = try!(fs::readdir(loc.path())); - for file in &files { - let filename = file.filename_str().unwrap(); + let files = try!(fs::read_dir(loc.path())); + for file in files { + let file = try!(file).path(); + let filename = file.file_name().unwrap().to_str().unwrap(); if skip(filename) { continue } if filename.contains(".SYMDEF") { continue } @@ -313,8 +316,8 @@ impl<'a> ArchiveBuilder<'a> { filename }; let new_filename = self.work_dir.path().join(&filename[..]); - try!(fs::rename(file, &new_filename)); - self.members.push(Path::new(filename)); + try!(fs::rename(&file, &new_filename)); + self.members.push(PathBuf::new(&filename)); } Ok(()) } |
