Use absolute path for CARGO_HOME

This commit is contained in:
Eduardo Bautista 2015-05-28 15:18:45 -05:00
parent de903c7739
commit f8b91b577b
2 changed files with 36 additions and 4 deletions

View file

@ -39,7 +39,7 @@ impl Config {
}));
let mut cfg = Config {
home_path: try!(homedir().chain_error(|| {
home_path: try!(homedir(cwd.as_path()).chain_error(|| {
human("Cargo couldn't find your home directory. \
This probably means that $HOME was not set.")
})),
@ -423,8 +423,10 @@ impl ConfigValue {
}
}
fn homedir() -> Option<PathBuf> {
let cargo_home = env::var_os("CARGO_HOME").map(PathBuf::from);
fn homedir(cwd: &Path) -> Option<PathBuf> {
let cargo_home = env::var_os("CARGO_HOME").map(|home| {
cwd.join(home)
});
let user_home = env::home_dir().map(|p| p.join(".cargo"));
return cargo_home.or(user_home);
}
@ -450,7 +452,7 @@ fn walk_tree<F>(pwd: &Path, mut walk: F) -> CargoResult<()>
// Once we're done, also be sure to walk the home directory even if it's not
// in our history to be sure we pick up that standard location for
// information.
let home = try!(homedir().chain_error(|| {
let home = try!(homedir(pwd).chain_error(|| {
human("Cargo couldn't find your home directory. \
This probably means that $HOME was not set.")
}));

View file

@ -52,3 +52,33 @@ test!(build_with_no_lib {
execs().with_status(101)
.with_stderr("no library targets found"));
});
test!(build_with_relative_cargo_home_path {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = ["wycats@example.com"]
[dependencies]
"test-dependency" = { path = "src/test_dependency" }
"#)
.file("src/main.rs", r#"
fn main() {}
"#)
.file("src/test_dependency/src/lib.rs", r#" "#)
.file("src/test_dependency/Cargo.toml", r#"
[package]
name = "test-dependency"
version = "0.0.1"
authors = ["wycats@example.com"]
"#);
assert_that(p.cargo_process("build").env("CARGO_HOME", "./cargo_home/"),
execs()
.with_status(0));
});