diff --git a/Cargo.toml b/Cargo.toml index 93eb7c29053..b1657a46d05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ home = "0.3" ignore = "0.4" lazy_static = "1.0.0" jobserver = "0.1.11" -lazycell = "1.0" +lazycell = "1.2.0" libc = "0.2" log = "0.4" libgit2-sys = "0.7.5" diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 6f6fd627648..af074036d3b 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -74,12 +74,9 @@ continuous integration systems.", } pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { + config.reload_rooted_at_cargo_home()?; let mut compile_opts = args.compile_options(config, CompileMode::Build)?; - // for `cargo-install` we want to use what the user specified via `--target` and ignore what's - // in `.cargo/config` and what the environment says - compile_opts.build_config.requested_target = args.target(); - compile_opts.build_config.release = !args.is_present("debug"); let krates = args.values_of("crate") diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index dd5464e2509..fb242d220bc 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -281,6 +281,13 @@ impl Config { } } + pub fn reload_rooted_at_cargo_home(&mut self) -> CargoResult<()> { + let home = self.home_path.clone().into_path_unlocked(); + let values = self.load_values_from(&home)?; + self.values.replace(values); + Ok(()) + } + pub fn cwd(&self) -> &Path { &self.cwd } @@ -611,9 +618,16 @@ impl Config { /// Loads configuration from the filesystem pub fn load_values(&self) -> CargoResult> { + self.load_values_from(&self.cwd) + } + + fn load_values_from(&self, path: &Path) + -> CargoResult> + { let mut cfg = CV::Table(HashMap::new(), PathBuf::from(".")); + let home = self.home_path.clone().into_path_unlocked(); - walk_tree(&self.cwd, |path| { + walk_tree(path, &home, |path| { let mut contents = String::new(); let mut file = File::open(&path)?; file.read_to_string(&mut contents) @@ -1535,7 +1549,7 @@ pub fn homedir(cwd: &Path) -> Option { ::home::cargo_home_with_cwd(cwd).ok() } -fn walk_tree(pwd: &Path, mut walk: F) -> CargoResult<()> +fn walk_tree(pwd: &Path, home: &Path, mut walk: F) -> CargoResult<()> where F: FnMut(&Path) -> CargoResult<()>, { @@ -1552,12 +1566,6 @@ where // 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 = homedir(pwd).ok_or_else(|| { - format_err!( - "Cargo couldn't find your home directory. \ - This probably means that $HOME was not set." - ) - })?; let config = home.join("config"); if !stash.contains(&config) && fs::metadata(&config).is_ok() { walk(&config)?; diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 928f6224154..5a47b5d7e04 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1256,16 +1256,16 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina } #[test] -fn install_ignores_cargo_config() { +fn install_ignores_local_cargo_config() { pkg("bar", "0.0.1"); let p = project() .file( ".cargo/config", r#" - [build] - target = "non-existing-target" - "#, + [build] + target = "non-existing-target" + "#, ) .file("src/main.rs", "fn main() {}") .build(); @@ -1273,3 +1273,22 @@ fn install_ignores_cargo_config() { p.cargo("install bar").run(); assert_has_installed_exe(cargo_home(), "bar"); } + +#[test] +fn install_global_cargo_config() { + pkg("bar", "0.0.1"); + + let config = cargo_home().join("config"); + let mut toml = fs::read_to_string(&config).unwrap_or(String::new()); + + toml.push_str(r#" + [build] + target = 'nonexistent' + "#); + fs::write(&config, toml).unwrap(); + + cargo_process("install bar") + .with_status(101) + .with_stderr_contains("[..]--target nonexistent[..]") + .run(); +}