Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow cargo install --path P to load config from P. #6804

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}