From 6eb791c7b93b27c80bf34eb703f0a3f3f7485c7c Mon Sep 17 00:00:00 2001 From: zvms Date: Thu, 15 May 2014 15:06:28 -0700 Subject: [PATCH 1/2] Update util::process_builder to use the new Command API introduced in Rust commit 046062d. --- src/cargo/core/dependency.rs | 2 +- src/cargo/util/process_builder.rs | 32 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index fcffed66d3d..dd0aa2cf7d5 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -1,5 +1,5 @@ use semver::Version; -use core::{NameVer,VersionReq}; +use core::VersionReq; use util::CargoResult; #[deriving(Eq,Clone,Show)] diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index e8aea0e0ec9..b0dd6b3d241 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -2,7 +2,7 @@ use std::fmt; use std::fmt::{Show,Formatter}; use std::os; use std::path::Path; -use std::io::process::{Process,ProcessConfig,ProcessOutput,InheritFd}; +use std::io::process::{Command,ProcessOutput,InheritFd}; use util::{CargoResult,io_error,process_error}; use collections::HashMap; @@ -53,16 +53,16 @@ impl ProcessBuilder { // TODO: should InheritFd be hardcoded? pub fn exec(&self) -> CargoResult<()> { - let mut config = try!(self.build_config()); + let mut command = try!(self.build_command()); let env = self.build_env(); // Set where the output goes - config.env = Some(env.as_slice()); - config.stdout = InheritFd(1); - config.stderr = InheritFd(2); + command.env(env.as_slice()) + .stdout(InheritFd(1)) + .stderr(InheritFd(2)); - let mut process = try!(Process::configure(config).map_err(io_error)); - let exit = process.wait(); + let mut process = try!(command.spawn().map_err(io_error)); + let exit = process.wait().unwrap(); if exit.success() { Ok(()) @@ -73,12 +73,13 @@ impl ProcessBuilder { } pub fn exec_with_output(&self) -> CargoResult { - let mut config = try!(self.build_config()); + let mut command = try!(self.build_command()); let env = self.build_env(); - config.env = Some(env.as_slice()); + // Set the environment + command.env(env.as_slice()); - let output = try!(Process::configure(config).map(|mut ok| ok.wait_with_output()).map_err(io_error)); + let output = try!(command.spawn().map(|ok| ok.wait_with_output()).map_err(io_error)).unwrap(); if output.status.success() { Ok(output) @@ -88,14 +89,13 @@ impl ProcessBuilder { } } - fn build_config<'a>(&'a self) -> CargoResult> { - let mut config = ProcessConfig::new(); + fn build_command(&self) -> CargoResult { + let mut command = Command::new(self.program.as_slice()); - config.program = self.program.as_slice(); - config.args = self.args.as_slice(); - config.cwd = Some(&self.cwd); + command.args(self.args.as_slice()) + .cwd(&self.cwd); - Ok(config) + Ok(command) } fn debug_string(&self) -> ~str { From 6d1c5af1d0cde8648eeb318040aa6982ccbc2904 Mon Sep 17 00:00:00 2001 From: zvms Date: Thu, 15 May 2014 22:54:50 -0700 Subject: [PATCH 2/2] Fix test failure on Mac. Previously cargo_compile_with_invalid_code failed on Mac OS X 10.9 because $TMPDIR was a child of a symlinked directory. As a result this the error messages from rustc used the real path while the test created the expected output using the symlink. This patch normalizes the root path used by the tests to use the real path. The solution to this isn't as elegant as I'd like. Because fs::realpath isn't implemented in libstd (mozilla/rust #11857) I had to copy the implementation from librustc to avoid having to link librustc into the test binary. --- tests/support.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/support.rs b/tests/support.rs index 338564da598..4ecf0b96471 100644 --- a/tests/support.rs +++ b/tests/support.rs @@ -55,6 +55,7 @@ struct ProjectBuilder { impl ProjectBuilder { pub fn new(name: &str, root: Path) -> ProjectBuilder { + let root = realpath(&root).unwrap(); ProjectBuilder { name: name.to_owned(), root: root, @@ -118,6 +119,48 @@ pub fn project(name: &str) -> ProjectBuilder { // === Helpers === +/// Temporary hack until mozilla/rust #11857 is resolved +/// Copyright 2014 The Rust Project Developers under the Apache License, Version +/// 2.0 or the MIT License. +/// Returns an absolute path in the filesystem that `path` points to. The +/// returned path does not contain any symlinks in its hierarchy. +pub fn realpath(original: &Path) -> io::IoResult { + static MAX_LINKS_FOLLOWED: uint = 256; + let original = os::make_absolute(original); + + // Right now lstat on windows doesn't work quite well + if cfg!(windows) { + return Ok(original) + } + + let result = original.root_path(); + let mut result = result.expect("make_absolute has no root_path"); + let mut followed = 0; + + for part in original.components() { + result.push(part); + + loop { + if followed == MAX_LINKS_FOLLOWED { + return Err(io::standard_error(io::InvalidInput)) + } + + match fs::lstat(&result) { + Err(..) => break, + Ok(ref stat) if stat.kind != io::TypeSymlink => break, + Ok(..) => { + followed += 1; + let path = try!(fs::readlink(&result)); + result.pop(); + result.push(path); + } + } + } + } + + return Ok(result); +} + pub fn mkdir_recursive(path: &Path) -> Result<(), ~str> { fs::mkdir_recursive(path, io::UserDir) .with_err_msg(format!("could not create directory; path={}", path.display()))