Skip to content

Commit

Permalink
Auto merge of #6804 - ehuss:install-path-config2, r=alexcrichton
Browse files Browse the repository at this point in the history
Allow `cargo install --path P` to load config from P.

`cargo install` was changed to ignore configs except for the home directory (#6026). However, it seems like there are legitimate needs when using `--path`, so allow loading from that path, too.

Closes #6498.
Closes #6397.
  • Loading branch information
bors committed Apr 1, 2019
2 parents d338c49 + fe8f294 commit 527017f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ continuous integration systems.",
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let registry = args.registry(config)?;

config.reload_rooted_at_cargo_home()?;
if let Some(path) = args.value_of_path("path", config) {
config.reload_rooted_at(path)?;
} else {
config.reload_rooted_at(config.home().clone().into_path_unlocked())?;
}

let workspace = args.workspace(config).ok();
let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref())?;
Expand Down
5 changes: 2 additions & 3 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,8 @@ 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)?;
pub fn reload_rooted_at<P: AsRef<Path>>(&mut self, path: P) -> CargoResult<()> {
let values = self.load_values_from(path.as_ref())?;
self.values.replace(values);
Ok(())
}
Expand Down
18 changes: 18 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,3 +1358,21 @@ fn install_global_cargo_config() {
.with_stderr_contains("[..]--target nonexistent[..]")
.run();
}

#[test]
fn install_path_config() {
project()
.file(
".cargo/config",
r#"
[build]
target = 'nonexistent'
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
cargo_process("install --path foo")
.with_status(101)
.with_stderr_contains("[..]--target nonexistent[..]")
.run();
}

0 comments on commit 527017f

Please sign in to comment.