let (rustc_version, rustc_host) = try!(ops::rustc_version());
Ok(Config {
- home_path: try!(os::homedir().require(|| {
+ home_path: try!(homedir().require(|| {
human("Cargo couldn't find your home directory. \
This probably means that $HOME was not set.")
})),
}
}
+fn homedir() -> Option<Path> {
+ let cargo_home = os::getenv("CARGO_HOME").map(|p| Path::new(p));
+ let user_home = os::homedir();
+ return cargo_home.or(user_home);
+}
+
pub fn get_config(pwd: Path, key: &str) -> CargoResult<ConfigValue> {
find_in_tree(&pwd, |file| extract_config(file, key)).map_err(|_|
human(format!("`{}` not found in your configuration", key)))
// 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!(os::homedir().require(|| {
+ let home = try!(homedir().require(|| {
human("Cargo couldn't find your home directory. \
This probably means that $HOME was not set.")
}));
use std::io::fs::{mod, PathExtensions};
use std::io;
+use std::io::{USER_RWX, File};
use std::os;
use std::str;
use cargo::util::process;
.with_stderr("No such subcommand
"));
});
+
+test!(override_cargo_home {
+ let root = paths::root();
+ let my_home = root.join("my_home");
+ fs::mkdir(&my_home, USER_RWX).assert();
+ fs::mkdir(&my_home.join(".cargo"), USER_RWX).assert();
+ File::create(&my_home.join(".cargo/config")).write_str(r#"
+ [cargo-new]
+ name = "foo"
+ email = "bar"
+ git = false
+ "#).assert();
+
+ assert_that(process(cargo_dir().join("cargo")).unwrap()
+ .arg("new").arg("foo")
+ .cwd(paths::root())
+ .env("USER", Some("foo"))
+ .env("HOME", Some(paths::home()))
+ .env("CARGO_HOME", Some(my_home.clone())),
+ execs().with_status(0));
+
+ let toml = paths::root().join("foo/Cargo.toml");
+ let toml = File::open(&toml).read_to_string().assert();
+ assert!(toml.as_slice().contains(r#"authors = ["foo <bar>"]"#));
+});