Skip to content

Commit

Permalink
keep only one flavor among real file & symlinks in collect_libs()
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Jun 28, 2022
1 parent b7a8198 commit a53756d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
27 changes: 18 additions & 9 deletions conan/tools/files/files.py
Expand Up @@ -494,24 +494,33 @@ def collect_libs(conanfile, folder=None):
else:
lib_folders = [os.path.join(conanfile.package_folder, folder)
for folder in conanfile.cpp_info.libdirs]
result = []

ref_libs = {}
for lib_folder in lib_folders:
if not os.path.exists(lib_folder):
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)
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

result = []
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

Expand Down
24 changes: 16 additions & 8 deletions conans/client/tools/files.py
Expand Up @@ -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

Expand Down

0 comments on commit a53756d

Please sign in to comment.