Skip to content

Commit 8c93e08

Browse files
committed
Auto merge of #4999 - alexcrichton:beta-next, r=alexcrichton
[beta] Fix `RUSTC=./relative-path` when building This is a backport of #4995
2 parents 64326d7 + 64f72af commit 8c93e08

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn run_unit_tests(options: &TestOptions,
120120
let (kind, test, e) = errors.pop().unwrap();
121121
Ok((Test::UnitTest(kind, test), vec![e]))
122122
} else {
123-
Ok((Test::Multiple, errors.into_iter().map((|(_, _, e)| e)).collect()))
123+
Ok((Test::Multiple, errors.into_iter().map(|(_, _, e)| e).collect()))
124124
}
125125
}
126126

src/cargo/util/config.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,16 @@ impl Config {
605605
fn maybe_get_tool(&self, tool: &str) -> CargoResult<Option<PathBuf>> {
606606
let var = tool.chars().flat_map(|c| c.to_uppercase()).collect::<String>();
607607
if let Some(tool_path) = env::var_os(&var) {
608-
return Ok(Some(PathBuf::from(tool_path)));
608+
let maybe_relative = match tool_path.to_str() {
609+
Some(s) => s.contains("/") || s.contains("\\"),
610+
None => false,
611+
};
612+
let path = if maybe_relative {
613+
self.cwd.join(tool_path)
614+
} else {
615+
PathBuf::from(tool_path)
616+
};
617+
return Ok(Some(path))
609618
}
610619

611620
let var = format!("build.{}", tool);

src/cargo/util/lazy_cell.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl<T> LazyCell<T> {
5555
}
5656

5757
/// Consumes this `LazyCell`, returning the underlying value.
58+
#[allow(unused_unsafe)]
5859
pub fn into_inner(self) -> Option<T> {
5960
unsafe {
6061
self.inner.into_inner()

tests/bench.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ fn many_similar_names() {
257257
}
258258

259259
#[test]
260+
#[ignore] // unignored on the master branch of cargo
260261
fn cargo_bench_failing_test() {
261262
if !is_nightly() { return }
262263

tests/workspaces.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
extern crate cargotest;
33
extern crate hamcrest;
44

5+
use std::env;
6+
use std::fs::{self, File};
57
use std::io::{Read, Write};
6-
use std::fs::File;
78

89
use cargotest::sleep_ms;
910
use cargotest::support::{project, execs, git};
@@ -1807,3 +1808,51 @@ fn cargo_home_at_root_works() {
18071808
assert_that(p.cargo("build").arg("--frozen").env("CARGO_HOME", p.root()),
18081809
execs().with_status(0));
18091810
}
1811+
1812+
#[test]
1813+
fn relative_rustc() {
1814+
let p = project("the_exe")
1815+
.file("Cargo.toml", r#"
1816+
[package]
1817+
name = "foo"
1818+
version = "0.1.0"
1819+
"#)
1820+
.file("src/main.rs", r#"
1821+
use std::process::Command;
1822+
use std::env;
1823+
1824+
fn main() {
1825+
let mut cmd = Command::new("rustc");
1826+
for arg in env::args_os().skip(1) {
1827+
cmd.arg(arg);
1828+
}
1829+
std::process::exit(cmd.status().unwrap().code().unwrap());
1830+
}
1831+
"#)
1832+
.build();
1833+
assert_that(p.cargo("build"), execs().with_status(0));
1834+
1835+
let src = p.root()
1836+
.join("target/debug/foo")
1837+
.with_extension(env::consts::EXE_EXTENSION);
1838+
1839+
Package::new("a", "0.1.0").publish();
1840+
1841+
let p = project("lib")
1842+
.file("Cargo.toml", r#"
1843+
[package]
1844+
name = "lib"
1845+
version = "0.1.0"
1846+
1847+
[dependencies]
1848+
a = "0.1"
1849+
"#)
1850+
.file("src/lib.rs", "")
1851+
.build();
1852+
1853+
fs::copy(&src, p.root().join(src.file_name().unwrap())).unwrap();
1854+
1855+
let file = format!("./foo{}", env::consts::EXE_SUFFIX);
1856+
assert_that(p.cargo("build").env("RUSTC", &file),
1857+
execs().with_status(0));
1858+
}

0 commit comments

Comments
 (0)