conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.11k stars 960 forks source link

[feature] BazelDeps should allow custom path to `load_conan_dependencies` #9834

Open knzivid opened 2 years ago

knzivid commented 2 years ago

I have a repository_rule that wraps conan install ... with BazelDeps as the generator. However, conandeps/dependencies.bzl hardcodes the path to build_file as conandeps/<pkg>/BUILD. When I call load_conan_dependencies from @custom-repo//conandeps:dependencies.bzl, the build_file turns out to be incorrect.

My suggestion is to allow a conandeps_root parameter to load_conan_dependencies to allow customization.

knzivid commented 2 years ago

Here's a hacky workaround

From f979f6274d73dea9a7e412696a8a46270ad95d64 Mon Sep 17 00:00:00 2001
From: Karthik Nishanth <karthik.nishanth@zivid.com>
Date: Wed, 20 Oct 2021 09:56:05 +0200
Subject: [PATCH] add label customization to BazelDeps

---
 conan/tools/google/bazeldeps.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/conan/tools/google/bazeldeps.py b/conan/tools/google/bazeldeps.py
index 8df952a8d5..a2dd698801 100644
--- a/conan/tools/google/bazeldeps.py
+++ b/conan/tools/google/bazeldeps.py
@@ -105,21 +105,21 @@ def _get_dependency_buildfile_content(self, dependency):
     def _create_new_local_repository(self, dependency, dependency_buildfile_name):
         snippet = textwrap.dedent("""
             native.new_local_repository(
-                name="{}",
-                path="{}",
-                build_file="{}",
+                name="{name}",
+                path="{path}",
+                build_file=label_func("{build_file}") if label_func else "{build_file}",
             )
         """).format(
-            dependency.ref.name,
-            dependency.package_folder,
-            dependency_buildfile_name
+            name=dependency.ref.name,
+            path=dependency.package_folder,
+            build_file=dependency_buildfile_name,
         )

         return snippet

     def _get_main_buildfile_content(self, local_repositories):
         template = textwrap.dedent("""
-            def load_conan_dependencies():
+            def load_conan_dependencies(label_func = None):
                 {}
         """)
arunkant commented 2 years ago

Any update on this yet?