From febd17ef590f3c52c84d5eb06e8703364fa79e27 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 1 Dec 2025 11:18:47 +0100 Subject: [PATCH 01/11] Add conditional argumant creation --- src/codechecker.bzl | 10 +++++----- src/compile_commands.bzl | 13 ++++++++----- src/tools.bzl | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/codechecker.bzl b/src/codechecker.bzl index fc8ee7d2..f2e21103 100644 --- a/src/codechecker.bzl +++ b/src/codechecker.bzl @@ -9,6 +9,7 @@ load( load( "@default_codechecker_tools//:defs.bzl", "CODECHECKER_BIN_PATH", + "BAZEL_VERSION" ) load( "per_file.bzl", @@ -252,10 +253,6 @@ _codechecker_test = rule( cfg = platforms_transition, doc = "List of compilable targets which should be checked.", ), - "_whitelist_function_transition": attr.label( - default = "@bazel_tools//tools/whitelists/function_transition_whitelist", - doc = "needed for transitions", - ), "_compile_commands_filter": attr.label( allow_files = True, executable = True, @@ -287,7 +284,10 @@ _codechecker_test = rule( default = [], doc = "List of analyze command arguments, e.g. --ctu", ), - }, + } | ({"_whitelist_function_transition": attr.label( + default = "@bazel_tools//tools/whitelists/function_transition_whitelist", + doc = "needed for transitions", + )} if BAZEL_VERSION.split(".")[0] in "0123456" else {}), outputs = { "compile_commands": "%{name}/compile_commands.json", "codechecker_commands": "%{name}/codechecker_commands.json", diff --git a/src/compile_commands.bzl b/src/compile_commands.bzl index 25a78a9c..358ee802 100644 --- a/src/compile_commands.bzl +++ b/src/compile_commands.bzl @@ -39,6 +39,10 @@ load( "CPP_COMPILE_ACTION_NAME", "C_COMPILE_ACTION_NAME", ) +load( + "@default_codechecker_tools//:defs.bzl", + "BAZEL_VERSION" +) load( "@codechecker_bazel//src:tools.bzl", @@ -432,11 +436,10 @@ _compile_commands = rule( cfg = platforms_transition, doc = "List of compilable targets which should be checked.", ), - "_whitelist_function_transition": attr.label( - default = "@bazel_tools//tools/whitelists/function_transition_whitelist", - doc = "needed for transitions", - ), - }, + } | ({"_whitelist_function_transition": attr.label( + default = "@bazel_tools//tools/whitelists/function_transition_whitelist", + doc = "needed for transitions", + )} if BAZEL_VERSION.split(".")[0] in "0123456" else {}), outputs = { "compile_commands": "%{name}/compile_commands.json", }, diff --git a/src/tools.bzl b/src/tools.bzl index 31cc9903..88543402 100644 --- a/src/tools.bzl +++ b/src/tools.bzl @@ -96,6 +96,7 @@ def _codechecker_local_repository_impl(repository_ctx): fail("ERROR! CodeChecker is not detected") defs = "CODECHECKER_BIN_PATH = '{}'\n".format(codechecker_bin_path) + defs += "BAZEL_VERSION = '{}'\n".format(native.bazel_version) repository_ctx.file( repository_ctx.path("defs.bzl"), content = defs, From b2c3ccf0e15fecc6189b6bd8d4a27034605e72f4 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 9 Jan 2026 08:27:00 +0100 Subject: [PATCH 02/11] Remove code repetition --- src/codechecker.bzl | 14 +++++++++----- src/common.bzl | 12 ++++++++++++ src/compile_commands.bzl | 10 ++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 src/common.bzl diff --git a/src/codechecker.bzl b/src/codechecker.bzl index f2e21103..904e6b95 100644 --- a/src/codechecker.bzl +++ b/src/codechecker.bzl @@ -19,6 +19,10 @@ load( "tools.bzl", "warning" ) +load( + "common.bzl", + "old_bazel_attributes", +) load( "@codechecker_bazel//src:codechecker_config.bzl", "get_config_file", @@ -284,10 +288,7 @@ _codechecker_test = rule( default = [], doc = "List of analyze command arguments, e.g. --ctu", ), - } | ({"_whitelist_function_transition": attr.label( - default = "@bazel_tools//tools/whitelists/function_transition_whitelist", - doc = "needed for transitions", - )} if BAZEL_VERSION.split(".")[0] in "0123456" else {}), + } | old_bazel_attributes(), outputs = { "compile_commands": "%{name}/compile_commands.json", "codechecker_commands": "%{name}/codechecker_commands.json", @@ -319,7 +320,10 @@ def codechecker_test( name = name, targets = targets, options = analyze, - config = config, + # Bazel 7 recognizes that the per_file_rule does not yet have a + # config attribute, and fails. TODO: uncomment when config files + # are supported in per_file rule + #config = config, tags = tags, **kwargs ) diff --git a/src/common.bzl b/src/common.bzl new file mode 100644 index 00000000..2b545d1a --- /dev/null +++ b/src/common.bzl @@ -0,0 +1,12 @@ +load( + "@default_codechecker_tools//:defs.bzl", + "BAZEL_VERSION" +) + +def old_bazel_attributes(): + if BAZEL_VERSION.split(".")[0] in "0123456": + return ({"_whitelist_function_transition": attr.label( + default = "@bazel_tools//tools/whitelists/function_transition_whitelist", + doc = "needed for transitions", + )}) + return {} diff --git a/src/compile_commands.bzl b/src/compile_commands.bzl index 358ee802..d22f6a5f 100644 --- a/src/compile_commands.bzl +++ b/src/compile_commands.bzl @@ -49,6 +49,11 @@ load( "source_attr" ) +load( + "@codechecker_bazel//src:common.bzl", + "old_bazel_attributes" +) + SourceFilesInfo = provider( doc = "Source files and corresponding compilation database (or compile commands)", fields = { @@ -436,10 +441,7 @@ _compile_commands = rule( cfg = platforms_transition, doc = "List of compilable targets which should be checked.", ), - } | ({"_whitelist_function_transition": attr.label( - default = "@bazel_tools//tools/whitelists/function_transition_whitelist", - doc = "needed for transitions", - )} if BAZEL_VERSION.split(".")[0] in "0123456" else {}), + } | old_bazel_attributes(), outputs = { "compile_commands": "%{name}/compile_commands.json", }, From d18fff05ab6603036fd27226a73361cf44e153f0 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 9 Jan 2026 08:49:35 +0100 Subject: [PATCH 03/11] Add bazel 7.7 to github testing --- .github/bazel_version.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/bazel_version.json b/.github/bazel_version.json index 2ada6a5b..0fcae114 100644 --- a/.github/bazel_version.json +++ b/.github/bazel_version.json @@ -1,4 +1,5 @@ [ - "6.5.0" + "6.5.0", + "7.7.0" ] From 8cbc75b16e4178b6264e1e42cf0585d962a28a38 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 9 Jan 2026 22:49:57 +0100 Subject: [PATCH 04/11] Fix CI by adding init system to docker container --- .github/workflows/foss.yaml | 4 +++- .github/workflows/unit_test.yaml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index 8dbf76f3..8463e740 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -66,7 +66,9 @@ jobs: foss_rhel_test: name: "Test rules on FOSS projects Bazel ${{ matrix.bazel_version }} (RHEL)" runs-on: ubuntu-24.04 - container: redhat/ubi9:latest + container: + image: redhat/ubi9:latest + options: --init needs: load_versions strategy: fail-fast: false diff --git a/.github/workflows/unit_test.yaml b/.github/workflows/unit_test.yaml index 40e28e8e..c3fbfd96 100644 --- a/.github/workflows/unit_test.yaml +++ b/.github/workflows/unit_test.yaml @@ -76,7 +76,9 @@ jobs: rhel9_test: name: "Unit tests: Bazel ${{ matrix.bazel_version }} (RHEL9)" runs-on: ubuntu-24.04 - container: redhat/ubi9:latest + container: + image: redhat/ubi9:latest + options: --init needs: load_versions strategy: fail-fast: false From 9c0d78694b6bf4ac78d36fc2a93cbe918302a526 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 12 Jan 2026 09:12:11 +0100 Subject: [PATCH 05/11] Remove unnecessary load --- src/codechecker.bzl | 1 - src/compile_commands.bzl | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/codechecker.bzl b/src/codechecker.bzl index 904e6b95..8819d227 100644 --- a/src/codechecker.bzl +++ b/src/codechecker.bzl @@ -9,7 +9,6 @@ load( load( "@default_codechecker_tools//:defs.bzl", "CODECHECKER_BIN_PATH", - "BAZEL_VERSION" ) load( "per_file.bzl", diff --git a/src/compile_commands.bzl b/src/compile_commands.bzl index d22f6a5f..303c4288 100644 --- a/src/compile_commands.bzl +++ b/src/compile_commands.bzl @@ -39,11 +39,6 @@ load( "CPP_COMPILE_ACTION_NAME", "C_COMPILE_ACTION_NAME", ) -load( - "@default_codechecker_tools//:defs.bzl", - "BAZEL_VERSION" -) - load( "@codechecker_bazel//src:tools.bzl", "source_attr" From 1fcc3b88622b63cea9c3f8f0daf6774ce9dfa374 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 12 Jan 2026 10:33:49 +0100 Subject: [PATCH 06/11] Make test version avare --- .../external_repository/test_external_repo.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index 259e2314..c451cfeb 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -30,6 +30,7 @@ class TestImplDepExternalDep(TestBase): __test_path__ = os.path.dirname(os.path.abspath(__file__)) BAZEL_BIN_DIR = os.path.join("bazel-bin") BAZEL_TESTLOGS_DIR = os.path.join("bazel-testlogs") + BAZEL_VERSION = None @final @classmethod @@ -40,6 +41,8 @@ def setUpClass(cls): """ super().setUpClass() try: + with open("../../../.bazelversion") as f: + cls.BAZEL_VERSION = f.read() shutil.copy("../../../.bazelversion", ".bazelversion") shutil.copy( "../../../.bazelversion", "third_party/my_lib/.bazelversion") @@ -71,13 +74,21 @@ def test_compile_commands_external_lib(self): "compile_commands.json") # The ~override part is a consquence of using Bzlmod. + if self.BAZEL_VERSION.startswith("6"): # type: ignore + pattern1 = "-isystem external/external_lib~override/include" + pattern2 = "-isystem " + \ + "bazel-out/k8-fastbuild/bin/external/external_lib~override/include" + else: + pattern1 = "-isystem external/external_lib~/include" + pattern2 = "-isystem " + \ + "bazel-out/k8-fastbuild/bin/external/external_lib~/include" + self.assertTrue(self.contains_regex_in_file( comp_json_file, - "-isystem external/external_lib~override/include")) + pattern1)) self.assertTrue(self.contains_regex_in_file( comp_json_file, - "-isystem " + - "bazel-out/k8-fastbuild/bin/external/external_lib~override/include")) + pattern2)) def test_codechecker_external_lib(self): """Test: bazel build :codechecker_external_deps""" From 0f5957795f70fa684008768a281d6c196b707632 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 12 Jan 2026 10:46:17 +0100 Subject: [PATCH 07/11] Add comments and license to common.bzl --- src/common.bzl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/common.bzl b/src/common.bzl index 2b545d1a..c67a60b0 100644 --- a/src/common.bzl +++ b/src/common.bzl @@ -1,9 +1,34 @@ +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Provide a collection of functions used by multiple bzl files. +""" + load( "@default_codechecker_tools//:defs.bzl", "BAZEL_VERSION" ) def old_bazel_attributes(): + """ + Returns a map with necessary attributes for the used Bazel version + + In older Bazel versions (e.g. 6) rulesets using transitions + must have the attribute _whitelist_function_transition. + In newer versions this is an error. + """ if BAZEL_VERSION.split(".")[0] in "0123456": return ({"_whitelist_function_transition": attr.label( default = "@bazel_tools//tools/whitelists/function_transition_whitelist", From 07e11627cbcbcb9e2bb53b44b397a556b85a0ff2 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 12 Jan 2026 10:46:17 +0100 Subject: [PATCH 08/11] Add comments and license to common.bzl --- src/common.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.bzl b/src/common.bzl index c67a60b0..7d2f4f09 100644 --- a/src/common.bzl +++ b/src/common.bzl @@ -27,7 +27,7 @@ def old_bazel_attributes(): In older Bazel versions (e.g. 6) rulesets using transitions must have the attribute _whitelist_function_transition. - In newer versions this is an error. + In newer versions (e.g. 7) this is an error. """ if BAZEL_VERSION.split(".")[0] in "0123456": return ({"_whitelist_function_transition": attr.label( From 6efbe8997555517de665e5e1ef8172e050f3fe18 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 12 Jan 2026 10:56:02 +0100 Subject: [PATCH 09/11] Change version handling --- test/unit/external_repository/test_external_repo.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index c451cfeb..591d5f1a 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -41,13 +41,14 @@ def setUpClass(cls): """ super().setUpClass() try: - with open("../../../.bazelversion") as f: - cls.BAZEL_VERSION = f.read() shutil.copy("../../../.bazelversion", ".bazelversion") shutil.copy( "../../../.bazelversion", "third_party/my_lib/.bazelversion") + except: logging.debug("No bazel version set, using system default") + _, stdout, _ = cls.run_command("bazel --version") + cls.BAZEL_VERSION = stdout.split(' ')[2].strip() @final @classmethod From 2af90b8dd9532681ff14a3595feaa90a77398759 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 12 Jan 2026 11:51:41 +0100 Subject: [PATCH 10/11] Clear bazel folders to remove duplicate test in wrong directory --- test/unit/external_repository/test_external_repo.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index 591d5f1a..0028bd3c 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -39,6 +39,10 @@ def setUpClass(cls): Copy bazelversion from main, otherwise bazelisk will download the latest bazel version. """ + # The folder bazel-external_repository contains this script + # and the unittest test discovery finds it. + # This is why, it is imperative that these directories get cleared + cls.run_command("bazel clean") super().setUpClass() try: shutil.copy("../../../.bazelversion", ".bazelversion") @@ -49,12 +53,17 @@ def setUpClass(cls): logging.debug("No bazel version set, using system default") _, stdout, _ = cls.run_command("bazel --version") cls.BAZEL_VERSION = stdout.split(' ')[2].strip() + logging.debug("Using Bazel", cls.BAZEL_VERSION) @final @classmethod def tearDownClass(cls): """Remove bazelversion from this test""" super().tearDownClass() + # The folder bazel-external_repository contains this script + # and the unittest test discovery finds it. + # This is why, it is imperative that these directories get cleared + cls.run_command("bazel clean") try: os.remove(".bazelversion") except: From d2b3bec1ff1a01003ab4b96cc8df60352deb7bac Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 12 Jan 2026 12:37:21 +0100 Subject: [PATCH 11/11] Update README, to indicate Bazel 7 support --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5b43d346..c55acf7d 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Prerequisites We need the following tools: - Git 2 or newer (we use 2.36) -- Bazel 6, not yet bazel 7 (we recommend version 6.5.0) +- Bazel 6 or 7, not yet bazel 8 (we recommend version 7.7.0) - Clang 16 or newer (we use 16), we use clang-tidy - Python 3.8 or newer (we use 3.11) - CodeChecker 6.26 or newer (we use 6.26.0) @@ -100,13 +100,13 @@ pip3 install codechecker ``` Install Bazel: -We recommend bazel 6.5.0 +We recommend bazel 7.7.0 ```bash -wget https://github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-linux-x86_64 && \ -chmod +x bazel-6.5.0-linux-x86_64 && \ -sudo mv bazel-6.5.0-linux-x86_64 /usr/local/bin/bazel +wget https://github.com/bazelbuild/bazel/releases/download/7.7.0/bazel-7.7.0-linux-x86_64 && \ +chmod +x bazel-7.7.0-linux-x86_64 && \ +sudo mv bazel-7.7.0-linux-x86_64 /usr/local/bin/bazel ``` -Or choose a suitable binary for your system from this list: https://github.com/bazelbuild/bazel/releases/tag/6.5.0 +Or choose a suitable binary for your system from this list: https://github.com/bazelbuild/bazel/releases/tag/7.7.0 Alternatively follow the official guide at: https://bazel.build/install > [!CAUTION]