[go: up one dir, main page]

Skip to content

Commit

Permalink
Auto merge of rust-lang#4999 - alexcrichton:beta-next, r=alexcrichton
Browse files Browse the repository at this point in the history
[beta] Fix `RUSTC=./relative-path` when building

This is a backport of rust-lang#4995
  • Loading branch information
bors committed Feb 1, 2018
2 parents 64326d7 + 64f72af commit 8c93e08
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn run_unit_tests(options: &TestOptions,
let (kind, test, e) = errors.pop().unwrap();
Ok((Test::UnitTest(kind, test), vec![e]))
} else {
Ok((Test::Multiple, errors.into_iter().map((|(_, _, e)| e)).collect()))
Ok((Test::Multiple, errors.into_iter().map(|(_, _, e)| e).collect()))
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,16 @@ impl Config {
fn maybe_get_tool(&self, tool: &str) -> CargoResult<Option<PathBuf>> {
let var = tool.chars().flat_map(|c| c.to_uppercase()).collect::<String>();
if let Some(tool_path) = env::var_os(&var) {
return Ok(Some(PathBuf::from(tool_path)));
let maybe_relative = match tool_path.to_str() {
Some(s) => s.contains("/") || s.contains("\\"),
None => false,
};
let path = if maybe_relative {
self.cwd.join(tool_path)
} else {
PathBuf::from(tool_path)
};
return Ok(Some(path))
}

let var = format!("build.{}", tool);
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/lazy_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<T> LazyCell<T> {
}

/// Consumes this `LazyCell`, returning the underlying value.
#[allow(unused_unsafe)]
pub fn into_inner(self) -> Option<T> {
unsafe {
self.inner.into_inner()
Expand Down
1 change: 1 addition & 0 deletions tests/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ fn many_similar_names() {
}

#[test]
#[ignore] // unignored on the master branch of cargo
fn cargo_bench_failing_test() {
if !is_nightly() { return }

Expand Down
51 changes: 50 additions & 1 deletion tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
extern crate cargotest;
extern crate hamcrest;

use std::env;
use std::fs::{self, File};
use std::io::{Read, Write};
use std::fs::File;

use cargotest::sleep_ms;
use cargotest::support::{project, execs, git};
Expand Down Expand Up @@ -1807,3 +1808,51 @@ fn cargo_home_at_root_works() {
assert_that(p.cargo("build").arg("--frozen").env("CARGO_HOME", p.root()),
execs().with_status(0));
}

#[test]
fn relative_rustc() {
let p = project("the_exe")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
"#)
.file("src/main.rs", r#"
use std::process::Command;
use std::env;
fn main() {
let mut cmd = Command::new("rustc");
for arg in env::args_os().skip(1) {
cmd.arg(arg);
}
std::process::exit(cmd.status().unwrap().code().unwrap());
}
"#)
.build();
assert_that(p.cargo("build"), execs().with_status(0));

let src = p.root()
.join("target/debug/foo")
.with_extension(env::consts::EXE_EXTENSION);

Package::new("a", "0.1.0").publish();

let p = project("lib")
.file("Cargo.toml", r#"
[package]
name = "lib"
version = "0.1.0"
[dependencies]
a = "0.1"
"#)
.file("src/lib.rs", "")
.build();

fs::copy(&src, p.root().join(src.file_name().unwrap())).unwrap();

let file = format!("./foo{}", env::consts::EXE_SUFFIX);
assert_that(p.cargo("build").env("RUSTC", &file),
execs().with_status(0));
}

0 comments on commit 8c93e08

Please sign in to comment.