Skip to content

Commit

Permalink
[BazelDeps] Improved libs search (#17233)
Browse files Browse the repository at this point in the history
* Adding libiconv to test

* Fixed last chance search

* Removed useless ref_name param

* wip

* splitted libs
  • Loading branch information
franramirez688 authored Oct 28, 2024
1 parent 9d3af22 commit 43be0c0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
6 changes: 2 additions & 4 deletions conan/tools/google/bazeldeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ def _get_requirements(conanfile, build_context_activated):
yield require, dep


def _get_libs(dep, cpp_info=None, reference_name=None) -> list:
def _get_libs(dep, cpp_info=None) -> list:
"""
Get the static/shared library paths
:param dep: normally a <ConanFileInterface obj>
:param cpp_info: <CppInfo obj> of the component.
:param reference_name: <str> Package/Component's reference name. ``None`` by default.
:return: list of tuples per static/shared library ->
[(name, is_shared, lib_path, import_lib_path)]
Note: ``library_path`` could be both static and shared ones in case of UNIX systems.
Expand Down Expand Up @@ -119,7 +118,7 @@ def _save_lib_path(file_name, file_path):
shared_windows_libs[libs[0]] = formatted_path
else: # let's cross the fingers... This is the last chance.
for lib in libs:
if ref_name in name and ref_name in lib and lib not in shared_windows_libs:
if lib in name and lib not in shared_windows_libs:
shared_windows_libs[lib] = formatted_path
break
elif lib_name is not None:
Expand All @@ -132,7 +131,6 @@ def _save_lib_path(file_name, file_path):
is_shared = _is_shared()
libdirs = cpp_info.libdirs
bindirs = cpp_info.bindirs if is_shared else [] # just want to get shared libraries
ref_name = reference_name or dep.ref.name
if hasattr(cpp_info, "aggregated_components"):
# Global cpp_info
total_libs_number = len(cpp_info.aggregated_components().libs)
Expand Down
43 changes: 40 additions & 3 deletions test/integration/toolchains/google/test_bazeldeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,25 @@ def package(self):
def package_info(self):
self.cpp_info.libs = ["zdll"]
""")
libiconv = textwrap.dedent("""
import os
from conan import ConanFile
from conan.tools.files import save
class Example(ConanFile):
name = "libiconv"
version = "1.0"
options = {"shared": [True, False]}
default_options = {"shared": False}
def package(self):
bindirs = os.path.join(self.package_folder, "bin")
libdirs = os.path.join(self.package_folder, "lib")
save(self, os.path.join(bindirs, "charset-1.dll"), "")
save(self, os.path.join(bindirs, "iconv-2.dll"), "")
save(self, os.path.join(libdirs, "charset.lib"), "")
save(self, os.path.join(libdirs, "iconv.lib"), "")
def package_info(self):
self.cpp_info.libs = ["iconv", "charset"]
""")
openssl = textwrap.dedent("""
import os
from conan import ConanFile
Expand Down Expand Up @@ -1081,20 +1100,25 @@ def package_info(self):
zlib/1.0
openssl/1.0
libcurl/1.0
libiconv/1.0
[options]
*:shared=True
""")
c.save({"conanfile.txt": consumer,
"zlib/conanfile.py": zlib,
"openssl/conanfile.py": openssl,
"libcurl/conanfile.py": libcurl})
"libcurl/conanfile.py": libcurl,
"libiconv/conanfile.py": libiconv,
})
c.run("export-pkg zlib -o:a shared=True")
c.run("export-pkg openssl -o:a shared=True")
c.run("export-pkg libcurl -o:a shared=True")
c.run("export-pkg libiconv -o:a shared=True")
c.run("install . -g BazelDeps")
libcurl_bazel_build = load(None, os.path.join(c.current_folder, "libcurl", "BUILD.bazel"))
zlib_bazel_build = load(None, os.path.join(c.current_folder, "zlib", "BUILD.bazel"))
openssl_bazel_build = load(None, os.path.join(c.current_folder, "openssl", "BUILD.bazel"))
libiconv_bazel_build = load(None, os.path.join(c.current_folder, "libiconv", "BUILD.bazel"))
libcurl_expected = textwrap.dedent("""\
# Components precompiled libs
cc_import(
Expand All @@ -1118,14 +1142,27 @@ def package_info(self):
)
""")
zlib_expected = textwrap.dedent("""\
# Components precompiled libs
# Root package precompiled libs
cc_import(
name = "zdll_precompiled",
shared_library = "bin/zlib1.dll",
interface_library = "lib/zdll.lib",
)
""")
iconv_expected = textwrap.dedent("""\
cc_import(
name = "iconv_precompiled",
shared_library = "bin/iconv-2.dll",
interface_library = "lib/iconv.lib",
)
""")
charset_expected = textwrap.dedent("""\
cc_import(
name = "charset_precompiled",
shared_library = "bin/charset-1.dll",
interface_library = "lib/charset.lib",
)
""")
assert libcurl_expected in libcurl_bazel_build
assert zlib_expected in zlib_bazel_build
assert openssl_expected in openssl_bazel_build
assert iconv_expected in libiconv_bazel_build and charset_expected in libiconv_bazel_build

0 comments on commit 43be0c0

Please sign in to comment.