From 877766e9b1e90150cccb7fb57eb7d2a2b5641338 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 25 Jun 2022 12:30:00 +0300 Subject: [PATCH] keep only one flavor of libs in collect_libs() it's quite generic, but usecase is mainy for dylib --- conan/tools/files/files.py | 24 ++++++++++++++++-------- conans/client/tools/files.py | 24 ++++++++++++++++-------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/conan/tools/files/files.py b/conan/tools/files/files.py index 7eca6af893f..61f7d0b705d 100644 --- a/conan/tools/files/files.py +++ b/conan/tools/files/files.py @@ -500,18 +500,26 @@ def collect_libs(conanfile, folder=None): conanfile.output.warn("Lib folder doesn't exist, can't collect libraries: " "{0}".format(lib_folder)) continue + # In case of symlinks, only keep shortest file name in the same "group" files = os.listdir(lib_folder) + ref_libs = {} for f in files: name, ext = os.path.splitext(f) if ext in (".so", ".lib", ".a", ".dylib", ".bc"): - if ext != ".lib" and name.startswith("lib"): - name = name[3:] - if name in result: - conanfile.output.warn("Library '%s' was either already found in a previous " - "'conanfile.cpp_info.libdirs' folder or appears several " - "times with a different file extension" % name) - else: - result.append(name) + real_lib = os.path.basename(os.path.realpath(os.path.join(lib_folder, f))) + if real_lib not in ref_libs or len(f) < len(ref_libs[real_lib]): + ref_libs[real_lib] = f + # Collect reference libs + for f in ref_libs.values(): + name, ext = os.path.splitext(f) + if ext != ".lib" and name.startswith("lib"): + name = name[3:] + if name in result: + conanfile.output.warn("Library '%s' was either already found in a previous " + "'conanfile.cpp_info.libdirs' folder or appears several " + "times with a different file extension" % name) + else: + result.append(name) result.sort() return result diff --git a/conans/client/tools/files.py b/conans/client/tools/files.py index 199581c0ee6..24c93990251 100644 --- a/conans/client/tools/files.py +++ b/conans/client/tools/files.py @@ -357,18 +357,26 @@ def collect_libs(conanfile, folder=None): conanfile.output.warn("Lib folder doesn't exist, can't collect libraries: " "{0}".format(lib_folder)) continue + # In case of symlinks, only keep shortest file name in the same "group" files = os.listdir(lib_folder) + ref_libs = {} for f in files: name, ext = os.path.splitext(f) if ext in VALID_LIB_EXTENSIONS: - if ext != ".lib" and name.startswith("lib"): - name = name[3:] - if name in result: - conanfile.output.warn("Library '%s' was either already found in a previous " - "'conanfile.cpp_info.libdirs' folder or appears several " - "times with a different file extension" % name) - else: - result.append(name) + real_lib = os.path.basename(os.path.realpath(os.path.join(lib_folder, f))) + if real_lib not in ref_libs or len(f) < len(ref_libs[real_lib]): + ref_libs[real_lib] = f + # Collect reference libs + for f in ref_libs.values(): + name, ext = os.path.splitext(f) + if ext != ".lib" and name.startswith("lib"): + name = name[3:] + if name in result: + conanfile.output.warn("Library '%s' was either already found in a previous " + "'conanfile.cpp_info.libdirs' folder or appears several " + "times with a different file extension" % name) + else: + result.append(name) result.sort() return result