Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test failure on Mac #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use semver::Version;
use core::{NameVer,VersionReq};
use core::VersionReq;
use util::CargoResult;

#[deriving(Eq,Clone,Show)]
Expand Down
32 changes: 16 additions & 16 deletions src/cargo/util/process_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(())
Expand All @@ -73,12 +73,13 @@ impl ProcessBuilder {
}

pub fn exec_with_output(&self) -> CargoResult<ProcessOutput> {
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)
Expand All @@ -88,14 +89,13 @@ impl ProcessBuilder {
}
}

fn build_config<'a>(&'a self) -> CargoResult<ProcessConfig<'a>> {
let mut config = ProcessConfig::new();
fn build_command(&self) -> CargoResult<Command> {
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 {
Expand Down
43 changes: 43 additions & 0 deletions tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Path> {
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()))
Expand Down