Skip to content

Commit

Permalink
[auto_location][fix] Symlinks (#17421)
Browse files Browse the repository at this point in the history
* Trusting the real path is the good one

* wip
  • Loading branch information
franramirez688 authored Dec 5, 2024
1 parent 50a16ba commit fd1a84a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
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

0 comments on commit fd1a84a

Please sign in to comment.