Skip to content

Commit

Permalink
Add alwayslink attribute to bazel static library import (#11560)
Browse files Browse the repository at this point in the history
* Add alwayslink attribute to bazel static library import

Fixes #11559

There is no test currently for the static library only version
Test exists only for the case when shared_with_interface_libs contains
elements.

* Remove always link in favor of do not sort

* fix tests

* Update conans/test/unittests/tools/google/test_bazeldeps.py

Co-authored-by: czoido <mrgalleta@gmail.com>
  • Loading branch information
a4z and czoido committed Jul 26, 2022
1 parent 237b26c commit 8389812
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion conan/tools/google/bazeldeps.py
Expand Up @@ -62,7 +62,7 @@ def _get_dependency_buildfile_content(self, dependency):
{% for libname, filepath in libs.items() %}
cc_import(
name = "{{ libname }}_precompiled",
{{ library_type }} = "{{ filepath }}"
{{ library_type }} = "{{ filepath }}",
)
{% endfor %}
Expand Down Expand Up @@ -91,6 +91,7 @@ def _get_dependency_buildfile_content(self, dependency):
visibility = ["//visibility:public"],
{% if libs or shared_with_interface_libs %}
deps = [
# do not sort
{% for lib in libs %}
":{{ lib }}_precompiled",
{% endfor %}
Expand Down
7 changes: 4 additions & 3 deletions conans/test/unittests/tools/google/test_bazeldeps.py
Expand Up @@ -58,7 +58,7 @@ def test_bazeldeps_dependency_buildfiles():
assert 'linkopts = ["/DEFAULTLIB:system_lib1"]' in dependency_content
else:
assert 'linkopts = ["-lsystem_lib1"],' in dependency_content
assert 'deps = [\n \n ":lib1_precompiled",' in dependency_content
assert """deps = [\n # do not sort\n \n ":lib1_precompiled",""" in dependency_content


def test_bazeldeps_get_lib_file_path_by_basename():
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_bazeldeps_get_lib_file_path_by_basename():
assert 'linkopts = ["/DEFAULTLIB:system_lib1"]' in dependency_content
else:
assert 'linkopts = ["-lsystem_lib1"],' in dependency_content
assert 'deps = [\n \n ":liblib1.a_precompiled",' in dependency_content
assert 'deps = [\n # do not sort\n \n ":liblib1.a_precompiled",' in dependency_content


def test_bazeldeps_dependency_transitive():
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_bazeldeps_dependency_transitive():

# Ensure that transitive dependency is referenced by the 'deps' attribute of the direct
# dependency
assert re.search(r'deps =\s*\[\s*":lib1_precompiled",\s*"@TransitiveDepName"',
assert re.search(r'deps =\s*\[\s*# do not sort\s*":lib1_precompiled",\s*"@TransitiveDepName"',
dependency_content)


Expand Down Expand Up @@ -220,6 +220,7 @@ def test_bazeldeps_shared_library_interface_buildfiles():
includes=["include"],
visibility=["//visibility:public"],
deps = [
# do not sort
":lib1_precompiled",
],
)
Expand Down

0 comments on commit 8389812

Please sign in to comment.