10000 Fix/warn deduce find location by memsharded · Pull Request #17923 · conan-io/conan · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix/warn deduce find location #17923

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

Merged
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
4 changes: 3 additions & 1 deletion conan/internal/model/cpp_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
30 changes: 28 additions & 2 deletions test/unittests/model/build_info/test_deduce_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
0