diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 88a42383be0..55c6543731f 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -2,7 +2,6 @@ use std::cell::{RefCell, RefMut, Ref, Cell}; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::hash_map::{HashMap}; use std::env; -use std::ffi::OsString; use std::fmt; use std::fs::{self, File}; use std::io::prelude::*; @@ -243,26 +242,29 @@ impl Config { } fn scrape_target_dir_config(&mut self) -> CargoResult<()> { - if let Some((dir, dir2)) = try!(self.get_string("build.target-dir")) { + if let Some(dir) = env::var_os("CARGO_TARGET_DIR") { + *self.target_dir.borrow_mut() = Some(self.cwd.join(dir)); + } else if let Some((dir, dir2)) = try!(self.get_string("build.target-dir")) { let mut path = PathBuf::from(dir2); path.pop(); path.pop(); path.push(dir); *self.target_dir.borrow_mut() = Some(path); - } else if let Some(dir) = env::var_os("CARGO_TARGET_DIR") { - *self.target_dir.borrow_mut() = Some(self.cwd.join(dir)); } Ok(()) } fn get_tool(&self, tool: &str) -> CargoResult { + let var = tool.chars().flat_map(|c| c.to_uppercase()).collect::(); + if let Some(tool_path) = env::var_os(&var) { + return Ok(PathBuf::from(tool_path)); + } + let var = format!("build.{}", tool); if let Some(tool_path) = try!(self.get_path(&var)) { return Ok(tool_path); } - let var = tool.chars().flat_map(|c| c.to_uppercase()).collect::(); - let tool = env::var_os(&var).unwrap_or_else(|| OsString::from(tool)); Ok(PathBuf::from(tool)) } } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 6e33657759d..2fddc664cf3 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1913,9 +1913,9 @@ test!(custom_target_dir { fs::create_dir(p.root().join(".cargo")).unwrap(); File::create(p.root().join(".cargo/config")).unwrap().write_all(br#" [build] - target-dir = "bar/target" + target-dir = "foo/target" "#).unwrap(); - assert_that(p.cargo("build").env("CARGO_TARGET_DIR", "foo/target"), + assert_that(p.cargo("build").env("CARGO_TARGET_DIR", "bar/target"), execs().with_status(0)); assert_that(&p.root().join("bar/target/debug").join(&exe_name), existing_file());