Skip to content

Commit

Permalink
keep only one flavor of libs in collect_libs()
Browse files Browse the repository at this point in the history
it's quite generic, but usecase is mainy for dylib
  • Loading branch information
SpaceIm committed Jun 25, 2022
1 parent b7a8198 commit b0c156f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
24 changes: 16 additions & 8 deletions conan/tools/files/files.py
Expand Up @@ -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 "groups"
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(f)) if os.path.islink(f) else 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
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 "groups"
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(f)) if os.path.islink(f) else 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 b0c156f

Please sign in to comment.