From d5cb6b532f0bd3d2e4c8bc2302ea8db4473a2499 Mon Sep 17 00:00:00 2001 From: Lin Yihai Date: Mon, 23 Sep 2024 09:27:32 +0800 Subject: [PATCH 1/3] test: Add test for issue-14560 --- tests/testsuite/config.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 6d0a3ff8ef2..2582670a736 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -16,7 +16,7 @@ use cargo::CargoResult; use cargo_test_support::compare::assert_e2e; use cargo_test_support::prelude::*; use cargo_test_support::str; -use cargo_test_support::{paths, project, symlink_supported, t}; +use cargo_test_support::{paths, project, project_in_home, symlink_supported, t}; use cargo_util_schemas::manifest::TomlTrimPaths; use cargo_util_schemas::manifest::TomlTrimPathsValue; use cargo_util_schemas::manifest::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB}; @@ -299,6 +299,28 @@ f1 = 1 assert_e2e().eq(&output, expected); } +#[cargo_test] +fn home_config_works_without_extension() { + write_config_at( + paths::cargo_home().join("config"), + "\ +[foo] +f1 = 1 +", + ); + let p = project_in_home("foo").file("src/lib.rs", "").build(); + + p.cargo("-vV") + .with_stderr_data(str![[r#" +[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml` +[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml` +[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml` +[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml` + +"#]]) + .run(); +} + #[cargo_test] fn config_ambiguous_filename_symlink_doesnt_warn() { // Windows requires special permissions to create symlinks. From 0b83e92a260601235d0b144239aed57a9b5e300e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 25 Sep 2024 09:45:38 -0500 Subject: [PATCH 2/3] refactor(config): Clarify duplicate-load check --- src/cargo/util/context/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index 1db5b9a3c98..5bd30a43626 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -1581,12 +1581,12 @@ impl GlobalContext { where F: FnMut(&Path) -> CargoResult<()>, { - let mut stash: HashSet = HashSet::new(); + let mut seen = HashSet::new(); for current in paths::ancestors(pwd, self.search_stop_path.as_deref()) { if let Some(path) = self.get_file_path(¤t.join(".cargo"), "config", true)? { walk(&path)?; - stash.insert(path); + seen.insert(path); } } @@ -1594,7 +1594,7 @@ impl GlobalContext { // in our history to be sure we pick up that standard location for // information. if let Some(path) = self.get_file_path(home, "config", true)? { - if !stash.contains(&path) { + if !seen.contains(&path) { walk(&path)?; } } From fe917f224decb340287d475a1f7eb43627647097 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 25 Sep 2024 12:03:39 -0500 Subject: [PATCH 3/3] fix(config): Don't double-warn about `$CARGO_HOME/config` The core requirements for this bug are - You have a `$CARGO_HOME/.config` - Your project is inside of `$HOME` We have a check to make sure we don't double-walk `$CARGO/config` but that check is *after* we warn about there being no `.toml` extension. To fix this, we just need to move that check outside of the file lookup. This required changing the `seen` check from checking whether walked the config file to checking if we've walked the config dir. As we only have one file per directory, this should work. --- src/cargo/util/context/mod.rs | 11 ++++++----- tests/testsuite/config.rs | 2 -- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index 5bd30a43626..ab283aa2481 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -1581,20 +1581,21 @@ impl GlobalContext { where F: FnMut(&Path) -> CargoResult<()>, { - let mut seen = HashSet::new(); + let mut seen_dir = HashSet::new(); for current in paths::ancestors(pwd, self.search_stop_path.as_deref()) { - if let Some(path) = self.get_file_path(¤t.join(".cargo"), "config", true)? { + let config_root = current.join(".cargo"); + if let Some(path) = self.get_file_path(&config_root, "config", true)? { walk(&path)?; - seen.insert(path); } + seen_dir.insert(config_root); } // 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. - if let Some(path) = self.get_file_path(home, "config", true)? { - if !seen.contains(&path) { + if !seen_dir.contains(home) { + if let Some(path) = self.get_file_path(home, "config", true)? { walk(&path)?; } } diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 2582670a736..8f9092c2fb2 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -314,8 +314,6 @@ f1 = 1 .with_stderr_data(str![[r#" [WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml` [NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml` -[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml` -[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml` "#]]) .run();