Repository: conan-io/conan

Issue:
Exact matches for internal python find-libraries for CMakeConfigDeps
Message while installing abseil from ConanCenter:
```
abseil/20230125.3: WARN: There were several matches for Lib absl_flags_commandlineflag: ['C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_commandlineflag.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_commandlineflag_internal.lib']
abseil/20230125.3: WARN: There were several matches for Lib absl_flags: ['C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_commandlineflag.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_commandlineflag_internal.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_config.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_internal.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_marshalling.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_parse.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_private_handle_accessor.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_program_name.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_reflection.lib', 'C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_usage.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_usage_internal.lib']
abseil/20230125.3: WARN: There were several matches for Lib absl_flags_usage: ['C:\\Users\\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_usage.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_flags_usage_internal.lib']
abseil/20230125.3: WARN: There were several matches for Lib absl_random_internal_randen: ['C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_random_internal_randen.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_random_internal_randen_hwaes.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_random_internal_randen_hwaes_impl.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_random_internal_randen_slow.lib']
abseil/20230125.3: WARN: There were several matches for Lib absl_random_internal_randen_hwaes: ['C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_random_internal_randen_hwaes.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_random_internal_randen_hwaes_impl.lib']
abseil/20230125.3: WARN: There were several matches for Lib absl_strings: ['C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_strings.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_strings_internal.lib']
abseil/20230125.3: WARN: There were several matches for Lib absl_cord: ['C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_cord.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_cord_internal.lib']
abseil/20230125.3: WARN: There were several matches for Lib absl_time: ['C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_time.lib', 'C:\\Users\\.conan2\\p\\absei5d08e4715d124\\p\\lib\\absl_time_zone.lib']
```

Maybe when there is an exact file match we can go for it?


Discussion:

Patch:
diff --git a/conan/internal/model/cpp_info.py b/conan/internal/model/cpp_info.py
index d33d6c03376..7967b75bf0c 100644
--- a/conan/internal/model/cpp_info.py
+++ b/conan/internal/model/cpp_info.py
@@ -527,7 +527,9 @@ def _find_matching(dirs, pattern):
                 if lib_found:
                     if len(lib_found) > 1:
                         lib_found.sort()
-                        out.warning(f"There were several matches for Lib {libname}: {lib_found}")
+                        found, _ = os.path.splitext(os.path.basename(lib_found[0]))
+                        if found != libname and found != f"lib{libname}":
+                            out.warning(f"There were several matches for Lib {libname}: {lib_found}")
                     return lib_found[0].replace("\\", "/")
 
         out = ConanOutput(scope=str(conanfile))


Test patch:
diff --git a/test/unittests/model/build_info/test_deduce_locations.py b/test/unittests/model/build_info/test_deduce_locations.py
index 3c4e99ad994..1fd6349b7e4 100644
--- a/test/unittests/model/build_info/test_deduce_locations.py
+++ b/test/unittests/model/build_info/test_deduce_locations.py
@@ -4,8 +4,9 @@
 
 import pytest
 
-from conan.test.utils.mocks import ConanFileMock
+from conan.test.utils.mocks import ConanFileMock, RedirectedTestOutput
 from conan.test.utils.test_files import temp_folder
+from conan.test.utils.tools import redirect_output
 from conan.tools.files import save
 from conan.internal.model.cpp_info import CppInfo
 from conan.internal.model.pkg_type import PackageType
@@ -225,6 +226,31 @@ def test_warning_windows_if_more_than_one_dll(conanfile):
     cppinfo.libs = ["mylib"]
     cppinfo.set_relative_base_folder(folder)
     folder = folder.replace("\\", "/")
-    result = cppinfo.deduce_full_cpp_info(conanfile)
+    output = RedirectedTestOutput()  # Initialize each command
+    with redirect_output(output):
+        result = cppinfo.deduce_full_cpp_info(conanfile)
+    assert "WARN: There were several matches for Lib mylib" in output
     assert result.location == f"{folder}/bindir/libx.dll"
     assert result.type == "shared-library"
+
+
+@pytest.mark.parametrize("prefix", [True, False])
+def test_multiple_matches_exact_match(conanfile, prefix):
+    # If the match is perfect, do not warn
+    folder = temp_folder()
+    prefix = "lib" if prefix else ""
+    save(os.path.join(folder, "libdir", f"{prefix}mylib.a"), "")
+    save(os.path.join(folder, "libdir", f"{prefix}mylib_imp.a"), "")
+    save(os.path.join(folder, "libdir", f"{prefix}mylib_other.a"), "")
+
+    cppinfo = CppInfo()
+    cppinfo.libdirs = ["libdir"]
+    cppinfo.libs = ["mylib"]
+    cppinfo.set_relative_base_folder(folder)
+    folder = folder.replace("\\", "/")
+    output = RedirectedTestOutput()  # Initialize each command
+    with redirect_output(output):
+        result = cppinfo.deduce_full_cpp_info(conanfile)
+    assert "WARN: There were several matches for Lib mylib" not in output
+    assert result.location == f"{folder}/libdir/{prefix}mylib.a"
+    assert result.type == "static-library"