Repository: conan-io/conan
Pull request #17444 (2024-12-10 14:35:36)

[BazelDeps] `glob()` compatible with bazel 8.x
Changelog: Fix: Added explicitly `allow_empty = True` to `glob()` function in BazelDeps (bazel 8.x compatible).
Docs: omit
Closes: https://github.com/conan-io/conan/issues/17438

**Note**: Updated the installed versions of Bazel to the latest ones too.


Patch:
diff --git a/conan/tools/google/bazeldeps.py b/conan/tools/google/bazeldeps.py
index c9d6363ff..4a9a1aca7 100644
--- a/conan/tools/google/bazeldeps.py
+++ b/conan/tools/google/bazeldeps.py
@@ -343,7 +343,9 @@ class _BazelBUILDGenerator:
             {% for bindir in obj["bindirs"] %}
             "{{ bindir }}/**",
             {% endfor %}
-        ]),
+        ],
+        allow_empty = True
+        ),
         visibility = ["//visibility:public"],
     )
     {% endif %}


Test patch:
diff --git a/.ci/docker/conan-tests b/.ci/docker/conan-tests
index 2d176b181..18a912e84 100644
--- a/.ci/docker/conan-tests
+++ b/.ci/docker/conan-tests
@@ -20,8 +20,9 @@ ENV PY36=3.6.15 \
     GXX_11=/usr/bin/g++-11 \
     CLANG_14=/usr/bin/clang-14 \
     CLANGXX_14=/usr/bin/clang++-14 \
-    BAZEL_6_3_2=6.3.2 \
-    BAZEL_7_1_2=7.1.2
+    BAZEL_6_5_0=6.5.0 \
+    BAZEL_7_4_1=7.4.1 \
+    BAZEL_8_0_0=8.0.0
 
 RUN apt-get update && \
     apt-get install -y --no-install-recommends \
@@ -131,14 +132,19 @@ RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 10 && \
     update-alternatives --set clang /usr/bin/clang-14 && \
     update-alternatives --set clang++ /usr/bin/clang++-14
 
-RUN mkdir -p /usr/share/bazel-$BAZEL_6_3_2/bin && \
-    wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_6_3_2}/bazel-${BAZEL_6_3_2}-linux-x86_64 && \
-    chmod +x bazel-${BAZEL_6_3_2}-linux-x86_64 && \
-    mv bazel-${BAZEL_6_3_2}-linux-x86_64 /usr/share/bazel-$BAZEL_6_3_2/bin/bazel && \
-    mkdir -p /usr/share/bazel-$BAZEL_7_1_2/bin && \
-    wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_7_1_2}/bazel-${BAZEL_7_1_2}-linux-x86_64 && \
-    chmod +x bazel-${BAZEL_7_1_2}-linux-x86_64 && \
-    mv bazel-${BAZEL_7_1_2}-linux-x86_64 /usr/share/bazel-$BAZEL_7_1_2/bin/bazel
+RUN mkdir -p /usr/share/bazel-$BAZEL_6_5_0/bin && \
+    wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_6_5_0}/bazel-${BAZEL_6_5_0}-linux-x86_64 && \
+    chmod +x bazel-${BAZEL_6_5_0}-linux-x86_64 && \
+    mv bazel-${BAZEL_6_5_0}-linux-x86_64 /usr/share/bazel-$BAZEL_6_5_0/bin/bazel && \
+    mkdir -p /usr/share/bazel-$BAZEL_7_4_1/bin && \
+    wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_7_4_1}/bazel-${BAZEL_7_4_1}-linux-x86_64 && \
+    chmod +x bazel-${BAZEL_7_4_1}-linux-x86_64 && \
+    mv bazel-${BAZEL_7_4_1}-linux-x86_64 /usr/share/bazel-$BAZEL_7_4_1/bin/bazel && \
+    mkdir -p /usr/share/bazel-$BAZEL_8_0_0/bin && \
+    wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_8_0_0}/bazel-${BAZEL_8_0_0}-linux-x86_64 && \
+    chmod +x bazel-${BAZEL_8_0_0}-linux-x86_64 && \
+    mv bazel-${BAZEL_8_0_0}-linux-x86_64 /usr/share/bazel-$BAZEL_8_0_0/bin/bazel
+
 
 USER conan
 WORKDIR $HOME
diff --git a/.github/workflows/osx-tests.yml b/.github/workflows/osx-tests.yml
index 550bad222..671f8d6bf 100644
--- a/.github/workflows/osx-tests.yml
+++ b/.github/workflows/osx-tests.yml
@@ -64,8 +64,9 @@ jobs:
             ~/Applications/CMake/3.15.7
             ~/Applications/CMake/3.19.7
             ~/Applications/CMake/3.23.5
-            ~/Applications/bazel/6.3.2
-            ~/Applications/bazel/7.1.2
+            ~/Applications/bazel/6.5.0
+            ~/Applications/bazel/7.4.1
+            ~/Applications/bazel/8.0.0
           key: ${{ runner.os }}-conan-tools-cache
 
       - name: Build CMake old versions not available for ARM
@@ -111,7 +112,7 @@ jobs:
         if: steps.cache-tools.outputs.cache-hit != 'true'
         run: |
           set -e
-          for version in 6.3.2 7.1.2; do
+          for version in 6.5.0 7.4.1 8.0.0; do
             mkdir -p ${HOME}/Applications/bazel/${version}
             wget -q -O ${HOME}/Applications/bazel/${version}/bazel https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-darwin-arm64
             chmod +x ${HOME}/Applications/bazel/${version}/bazel
@@ -146,8 +147,9 @@ jobs:
             ~/Applications/CMake/3.15.7
             ~/Applications/CMake/3.19.7
             ~/Applications/CMake/3.23.5
-            ~/Applications/bazel/6.3.2
-            ~/Applications/bazel/7.1.2
+            ~/Applications/bazel/6.5.0
+            ~/Applications/bazel/7.4.1
+            ~/Applications/bazel/8.0.0
           key: ${{ runner.os }}-conan-tools-cache
 
       - name: Set up Python ${{ matrix.python-version }}
diff --git a/.github/workflows/win-tests.yml b/.github/workflows/win-tests.yml
index 044af919d..2b0df32c8 100644
--- a/.github/workflows/win-tests.yml
+++ b/.github/workflows/win-tests.yml
@@ -169,8 +169,9 @@ jobs:
             C:\tools\cmake\3.15.7
             C:\tools\cmake\3.19.7
             C:\tools\cmake\3.23.5
-            C:\tools\bazel\6.3.2
-            C:\tools\bazel\7.1.2
+            C:\tools\bazel\6.5.0
+            C:\tools\bazel\7.4.1
+            C:\tools\bazel\8.0.0
           key: ${{ runner.os }}-conan-tools-cache
 
       - name: Build CMake old versions of CMake
@@ -211,7 +212,7 @@ jobs:
       - name: Install Bazel versions
         if: steps.cache-tools.outputs.cache-hit != 'true'
         run: |
-          $BAZEL_BUILD_VERSIONS = "6.3.2", "7.1.2"
+          $BAZEL_BUILD_VERSIONS = "6.5.0", "7.4.1", "8.0.0"
           foreach ($version in $BAZEL_BUILD_VERSIONS) {
               Write-Host "Downloading Bazel version $version for Windows..."
               $destination = "C:\tools\bazel\$version"
diff --git a/test/conftest.py b/test/conftest.py
index 572bbfa23..12a683f94 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -146,13 +146,16 @@ tools_locations = {
         "system": {"path": {'Windows': "C:/tools/cygwin/bin"}},
     },
     'bazel': {
-        "default": "6.3.2",
-        "6.3.2": {"path": {'Linux': '/usr/share/bazel-6.3.2/bin',
-                           'Windows': 'C:/tools/bazel/6.3.2',
-                           'Darwin': '/Users/runner/Applications/bazel/6.3.2'}},
-        "7.1.2": {"path": {'Linux': '/usr/share/bazel-7.1.2/bin',
-                           'Windows': 'C:/tools/bazel/7.1.2',
-                           'Darwin': '/Users/runner/Applications/bazel/7.1.2'}},
+        "default": "7",
+        "6.5.0": {"path": {'Linux': '/usr/share/bazel-6.5.0/bin',
+                           'Windows': 'C:/tools/bazel/6.5.0',
+                           'Darwin': '/Users/runner/Applications/bazel/6.5.0'}},
+        "7.4.1": {"path": {'Linux': '/usr/share/bazel-7.4.1/bin',
+                           'Windows': 'C:/tools/bazel/7.4.1',
+                           'Darwin': '/Users/runner/Applications/bazel/7.4.1'}},
+        "8.0.0": {"path": {'Linux': '/usr/share/bazel-8.0.0/bin',
+                           'Windows': 'C:/tools/bazel/8.0.0',
+                           'Darwin': '/Users/runner/Applications/bazel/8.0.0'}},
     },
     'premake': {
         "disabled": True,
diff --git a/test/functional/toolchains/google/test_bazel.py b/test/functional/toolchains/google/test_bazel.py
index a686f9056..8886211e8 100644
--- a/test/functional/toolchains/google/test_bazel.py
+++ b/test/functional/toolchains/google/test_bazel.py
@@ -38,7 +38,7 @@ def base_profile():
 
 
 @pytest.mark.parametrize("build_type", ["Debug", "Release", "RelWithDebInfo", "MinSizeRel"])
-@pytest.mark.tool("bazel", "6.3.2")
+@pytest.mark.tool("bazel", "6.5.0")
 def test_basic_exe_6x(bazelrc, build_type, base_profile, bazel_output_root_dir):
     client = TestClient(path_with_spaces=False)
     client.run(f"new bazel_exe -d name=myapp -d version=1.0 -d output_root_dir={bazel_output_root_dir}")
@@ -56,7 +56,7 @@ def test_basic_exe_6x(bazelrc, build_type, base_profile, bazel_output_root_dir):
 
 
 @pytest.mark.parametrize("build_type", ["Debug", "Release", "RelWithDebInfo", "MinSizeRel"])
-@pytest.mark.tool("bazel", "7.1.2")
+@pytest.mark.tool("bazel", "7.4.1")
 def test_basic_exe(bazelrc, build_type, base_profile, bazel_output_root_dir):
     client = TestClient(path_with_spaces=False)
     client.run(f"new bazel_7_exe -d name=myapp -d version=1.0 -d output_root_dir={bazel_output_root_dir}")
@@ -73,8 +73,19 @@ def test_basic_exe(bazelrc, build_type, base_profile, bazel_output_root_dir):
         assert "myapp/1.0: Hello World Debug!" in client.out
 
 
+@pytest.mark.tool("bazel", "8.0.0")
+def test_basic_lib(bazelrc, base_profile, bazel_output_root_dir):
+    """
+    Issue related: https://github.com/conan-io/conan/issues/17438
+    """
+    client = TestClient(path_with_spaces=False)
+    client.run(f"new bazel_7_lib -d name=mylib -d version=1.0 -d output_root_dir={bazel_output_root_dir}")
+    client.run("create .")
+    assert "mylib/1.0: Hello World Release!" in client.out
+
+
 @pytest.mark.parametrize("shared", [False, True])
-@pytest.mark.tool("bazel", "6.3.2")
+@pytest.mark.tool("bazel", "6.5.0")
 def test_transitive_libs_consuming_6x(shared, bazel_output_root_dir):
     """
     Testing the next dependencies structure for shared/static libs
@@ -200,7 +211,7 @@ def test_transitive_libs_consuming_6x(shared, bazel_output_root_dir):
 
 
 @pytest.mark.parametrize("shared", [False, True])
-@pytest.mark.tool("bazel", "7.1.2")
+@pytest.mark.tool("bazel", "7.4.1")
 @pytest.mark.skipif(platform.system() == "Linux",
                     reason="Conan CI fails (likely related to parallel "
                            "tests running??). Skipping it for now!")
diff --git a/test/functional/toolchains/google/test_bazeltoolchain_cross_compilation.py b/test/functional/toolchains/google/test_bazeltoolchain_cross_compilation.py
index 3a67abe97..036a4445d 100644
--- a/test/functional/toolchains/google/test_bazeltoolchain_cross_compilation.py
+++ b/test/functional/toolchains/google/test_bazeltoolchain_cross_compilation.py
@@ -10,7 +10,7 @@ from conan.test.utils.tools import TestClient
 
 
 @pytest.mark.skipif(platform.system() != "Darwin", reason="Only for Darwin")
-@pytest.mark.tool("bazel", "6.3.2")  # not working for Bazel 7.x
+@pytest.mark.tool("bazel", "6.5.0")  # not working for Bazel 7.x
 def test_bazel_simple_cross_compilation():
     profile = textwrap.dedent("""
     [settings]
diff --git a/test/integration/toolchains/google/test_bazeldeps.py b/test/integration/toolchains/google/test_bazeldeps.py
index de31863da..9d6633c1b 100644
--- a/test/integration/toolchains/google/test_bazeldeps.py
+++ b/test/integration/toolchains/google/test_bazeldeps.py
@@ -76,7 +76,9 @@ def test_bazel_relative_paths():
         name = "dep_binaries",
         srcs = glob([
             "bin/**",
-        ]),
+        ],
+        allow_empty = True
+        ),
         visibility = ["//visibility:public"],
     )
     """)
@@ -180,7 +182,9 @@ def test_bazeldeps_and_tool_requires():
         srcs = glob([
             "bin1/**",
             "bin2/**",
-        ]),
+        ],
+        allow_empty = True
+        ),
         visibility = ["//visibility:public"],
     )
     """)