Skip to content

Commit

Permalink
Auto merge of #2365 - japaric:env-gt-config, r=alexcrichton
Browse files Browse the repository at this point in the history
This patches fixes the precedence in these cases:

- CARGO_TARGET_ROOT is now preferred over build.target-dir
- RUSTC is now preferred over build.rustc
- RUSTDOC is now preferred over build.rustdoc

r? @alexcrichton
  • Loading branch information
bors committed Feb 12, 2016
2 parents 2e267ec + 256d9dd commit 24ab9e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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<PathBuf> {
let var = tool.chars().flat_map(|c| c.to_uppercase()).collect::<String>();
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::<String>();
let tool = env::var_os(&var).unwrap_or_else(|| OsString::from(tool));
Ok(PathBuf::from(tool))
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 24ab9e9

Please sign in to comment.