Skip to content

Commit 527017f

Browse files
committed
Auto merge of #6804 - ehuss:install-path-config2, r=alexcrichton
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.
2 parents d338c49 + fe8f294 commit 527017f

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ continuous integration systems.",
7878
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
7979
let registry = args.registry(config)?;
8080

81-
config.reload_rooted_at_cargo_home()?;
81+
if let Some(path) = args.value_of_path("path", config) {
82+
config.reload_rooted_at(path)?;
83+
} else {
84+
config.reload_rooted_at(config.home().clone().into_path_unlocked())?;
85+
}
8286

8387
let workspace = args.workspace(config).ok();
8488
let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref())?;

src/cargo/util/config.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,8 @@ impl Config {
285285
}
286286
}
287287

288-
pub fn reload_rooted_at_cargo_home(&mut self) -> CargoResult<()> {
289-
let home = self.home_path.clone().into_path_unlocked();
290-
let values = self.load_values_from(&home)?;
288+
pub fn reload_rooted_at<P: AsRef<Path>>(&mut self, path: P) -> CargoResult<()> {
289+
let values = self.load_values_from(path.as_ref())?;
291290
self.values.replace(values);
292291
Ok(())
293292
}

tests/testsuite/install.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,3 +1358,21 @@ fn install_global_cargo_config() {
13581358
.with_stderr_contains("[..]--target nonexistent[..]")
13591359
.run();
13601360
}
1361+
1362+
#[test]
1363+
fn install_path_config() {
1364+
project()
1365+
.file(
1366+
".cargo/config",
1367+
r#"
1368+
[build]
1369+
target = 'nonexistent'
1370+
"#,
1371+
)
1372+
.file("src/main.rs", "fn main() {}")
1373+
.build();
1374+
cargo_process("install --path foo")
1375+
.with_status(101)
1376+
.with_stderr_contains("[..]--target nonexistent[..]")
1377+
.run();
1378+
}

0 commit comments

Comments
 (0)