From dcd8b412171851d96f80f55f08b937d10c51b35f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 16 May 2016 11:09:52 -0700 Subject: [PATCH] Fix relative `build.target-dir` configuration Closes #2700 --- src/cargo/util/config.rs | 3 ++- tests/test_cargo_compile_custom_build.rs | 30 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index cc048ea3659..b03b6837902 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -366,7 +366,8 @@ impl Config { if let Some(dir) = env::var_os("CARGO_TARGET_DIR") { *self.target_dir.borrow_mut() = Some(Filesystem::new(self.cwd.join(dir))); } else if let Some(val) = try!(self.get_path("build.target-dir")) { - *self.target_dir.borrow_mut() = Some(Filesystem::new(val.val)); + let val = self.cwd.join(val.val); + *self.target_dir.borrow_mut() = Some(Filesystem::new(val)); } Ok(()) } diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index dc5d384f9f2..6a4d3679ee7 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -1892,3 +1892,33 @@ test!(non_utf8_output { assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0)); }); + +test!(custom_target_dir { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + + [dependencies] + a = { path = "a" } + "#) + .file("src/lib.rs", "") + .file(".cargo/config", r#" + [build] + target-dir = 'test' + "#) + .file("a/Cargo.toml", r#" + [project] + name = "a" + version = "0.5.0" + authors = [] + build = "build.rs" + "#) + .file("a/build.rs", "fn main() {}") + .file("a/src/lib.rs", ""); + + assert_that(p.cargo_process("build").arg("-v"), + execs().with_status(0)); +});