Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BazelDeps][bugfix] Reading dependencies.direct_host #12543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conan/tools/google/bazeldeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _relativize_path(p, base_path):
lib_dir = 'lib'

dependencies = []
for req, dep in dependency.dependencies.items():
for dep in dependency.dependencies.direct_host.values():
dependencies.append(dep.ref.name)

shared_library = dependency.options.get_safe("shared") if dependency.options else False
Expand Down
45 changes: 45 additions & 0 deletions conans/test/integration/toolchains/google/test_bazel.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,48 @@ def package_info(self):
c.run("install dep/0.1@ -g BazelDeps")
build_file = c.load("dep/BUILD")
assert 'static_library = "lib/libmymath.a"' in build_file


def test_bazeldeps_and_build_requires():
"""
Testing that direct build requires are not included in dependencies BUILD files

Issues related:
* https://github.com/conan-io/conan/issues/12444
* https://github.com/conan-io/conan/issues/12236
"""
c = TestClient()
tool = textwrap.dedent("""
import os
from conan import ConanFile

class ToolConanfile(ConanFile):
name = "tool"
version = "0.1"

def package_info(self):
self.cpp_info.libs = ["mymath"]
""")
c.save({"tool/conanfile.py": tool})
c.run("create tool")
dep = textwrap.dedent("""
import os
from conan import ConanFile
from conan.tools.files import save
class ExampleConanIntegration(ConanFile):
name = "dep"
version = "0.1"

def build_requirements(self):
self.build_requires("tool/0.1")
def package(self):
save(self, os.path.join(self.package_folder, "lib", "mymath", "otherfile.a"), "")
save(self, os.path.join(self.package_folder, "lib", "libmymath.a"), "")
def package_info(self):
self.cpp_info.libs = ["mymath"]
""")
c.save({"dep/conanfile.py": dep})
c.run("export dep")
c.run("install dep/0.1@ -g BazelDeps --build=missing")
build_file = c.load("dep/BUILD")
assert '@tool' not in build_file