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

[auto_location][fix] Symlinks #17421

Merged
merged 2 commits into from
Dec 5, 2024
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
3 changes: 1 addition & 2 deletions conans/model/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,7 @@ def _lib_match_by_regex(dir_, pattern):
# then os.path.realpath("libmylib.1.0.0.dylib") == "libmylib.dylib"
# Note: os.readlink() returns the path which the symbolic link points to.
real_path = os.path.realpath(full_path)
if pattern.match(os.path.basename(real_path)):
ret.add(real_path)
ret.add(real_path)
else:
ret.add(full_path)
return list(ret)
Expand Down
21 changes: 14 additions & 7 deletions test/unittests/model/build_info/test_deduce_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,33 @@ def test_windows_several_shared_link_locations(lib_info, conanfile):
assert result.components[f"_{lib_name}"].type == "shared-library"


@pytest.mark.parametrize("lib, symlinks", [
# symlinks == "real_file <- symlink1 <- symlink2 <- ... <- symlinkN"
# Issue related: https://github.com/conan-io/conan/issues/17417
("png", "libpng16.so.16.44.0 <- libpng16.so.16 <- libpng16.so <- libpng.so")
])
@pytest.mark.skipif(platform.system() == "Windows", reason="Can't apply symlink on Windows")
def test_shared_link_locations_symlinks(conanfile):
def test_shared_link_locations_symlinks(lib, symlinks, conanfile):
"""
Tests auto deduce location is able to find the real path of
any symlink created in the libs folder
"""
folder = temp_folder()
all_files = symlinks.split(" <- ") # [real_one, sym1, sym2, ...]
# forcing a folder that it's not going to be analysed by the deduce_location() function
real_location = os.path.join(folder, "other", "mylib.so")
real_location = os.path.join(folder, "other", all_files.pop(0))
save(real_location, "")
# Symlinks
os.makedirs(os.path.join(folder, "libdir"))
sym_1 = os.path.join(folder, "libdir", "mylib.1.0.0.so")
sym_2 = os.path.join(folder, "libdir", "mylib.2.0.0.so")
os.symlink(real_location, sym_1)
os.symlink(sym_1, sym_2)
prev_path = real_location
for file in all_files:
sym = os.path.join(folder, "libdir", file)
os.symlink(prev_path, sym)
prev_path = sym

cppinfo = CppInfo()
cppinfo.libdirs = ["libdir"]
cppinfo.libs = ["mylib"]
cppinfo.libs = [lib]
cppinfo.set_relative_base_folder(folder)

result = cppinfo.deduce_full_cpp_info(conanfile)
Expand Down
Loading