From ec5ce1cd790a3fe8857a90574d0e7549a6a3f780 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 23 Feb 2026 10:01:24 +0100 Subject: [PATCH 1/8] Apply buildifier suggestions to tools --- src/tools.bzl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools.bzl b/src/tools.bzl index b2bd7959..769cf43a 100644 --- a/src/tools.bzl +++ b/src/tools.bzl @@ -86,6 +86,8 @@ default_python_tools = repository_rule( implementation = _python_local_repository_impl, ) +# buildifier: disable=unused-variable +# This parameter is provided, regardless if we use it or not def register_default_python_toolchain(ctx = None): default_python_tools(name = "default_python_tools") @@ -120,6 +122,8 @@ default_codechecker_tools = repository_rule( implementation = _codechecker_local_repository_impl, ) +# buildifier: disable=unused-variable +# This parameter is provided, regardless if we use it or not def register_default_codechecker(ctx = None): default_codechecker_tools(name = "default_codechecker_tools") From d98206affe6115564c515415220e61f5cb597211 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 23 Feb 2026 10:01:36 +0100 Subject: [PATCH 2/8] Apply buildifier lint suggestions to common --- src/common.bzl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common.bzl b/src/common.bzl index 198b800e..2cc948e6 100644 --- a/src/common.bzl +++ b/src/common.bzl @@ -52,7 +52,12 @@ def python_toolchain_type(): def python_path(ctx): """ - Returns version specific Python path + Function to obtain a python executable path + + Args: + ctx: The context variable + Returns: + version specific Python path """ py_toolchain = ctx.toolchains[python_toolchain_type()] if hasattr(py_toolchain, "py3_runtime_info"): @@ -74,4 +79,5 @@ def warning(ctx, msg): NOTE: "debug" in tags works only for rules, not aspects """ if hasattr(ctx.attr, "tags") and "debug" in ctx.attr.tags: + # buildifier: disable=print print(msg) From d76d9f1c0e0fab3f125cb6fe8c38a35f1806a072 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 23 Feb 2026 10:01:48 +0100 Subject: [PATCH 3/8] Apply buildifier lint suggestions to compile_commands --- src/compile_commands.bzl | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/compile_commands.bzl b/src/compile_commands.bzl index 7d9b3c09..64d2feb6 100644 --- a/src/compile_commands.bzl +++ b/src/compile_commands.bzl @@ -82,6 +82,9 @@ QUOTE_INCLUDE = "-iquote " def get_compile_flags(ctx, dep): """ Return a list of compile options + Args: + ctx: The context variable. + dep: A target with CcInfo. Returns: List of compile options. """ @@ -137,6 +140,8 @@ def get_compile_flags(ctx, dep): def get_sources(ctx): """ Return a list of source files + Args: + ctx: The context variable. Returns: List of source files. """ @@ -211,6 +216,9 @@ def _cc_compiler_info(ctx, target, src, feature_configuration, cc_toolchain): def get_compilation_database(target, ctx): """ Return a "compilation database" or "compile commands" ready to create a JSON file + Args: + ctx: The context variable. + target: Target to create the compilation database for. Returns: List of struct(file, command, directory). """ @@ -262,6 +270,9 @@ def get_compilation_database(target, ctx): def collect_headers(target, ctx): """ Return list of required header files + Args: + ctx: The context variable. + target: Target which headers should be collected Returns: depset of header files """ @@ -375,6 +386,8 @@ def _compile_commands_json(compilation_db): def compile_commands_impl(ctx): """ Creates compile_commands.json file for given targets and platform + Args: + ctx: The context variable. Returns: DefaultInfo( files, # as compile_commands.json @@ -448,7 +461,18 @@ def compile_commands( platform = "", #"@platforms//os:linux", tags = [], **kwargs): - """ Bazel rule to generate compile_commands.json file """ + """ + Bazel rule to generate compile_commands.json file + + Args: + name: Name of the target. + targets: List of targets to generate compile_commands.json for. + platform: Platform to consider during compile database creation. + tags: Bazel tags + **kwargs: Other miscellaneous arguments. + Returns: + None + """ compile_commands_tags = [] + tags if "compile_commands" not in tags: compile_commands_tags.append("compile_commands") @@ -457,4 +481,5 @@ def compile_commands( platform = platform, targets = targets, tags = compile_commands_tags, + **kwargs ) From 5ece70818538b2b1b2d164ac8bb7b778c4e805b8 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 23 Feb 2026 10:02:04 +0100 Subject: [PATCH 4/8] Apply buildifier lint suggestions to codechecker_config --- src/codechecker_config.bzl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/codechecker_config.bzl b/src/codechecker_config.bzl index e946ccf7..ef48e20b 100644 --- a/src/codechecker_config.bzl +++ b/src/codechecker_config.bzl @@ -18,9 +18,15 @@ Ruleset for configuring codechecker. def _get_config_file_name(ctx): """ + Get the name of the config file. + Returns the name of the config file to be used, with correct extension If no config file is given, we write the configuration options into a config.json file. + Args: + ctx: The context variable + Returns: + Path of the config file """ if ctx.attr.config: if type(ctx.attr.config) == "list": @@ -37,8 +43,13 @@ def _get_config_file_name(ctx): def get_config_file(ctx): """ - Returns (config_file, environment_variables) - config_file is a file object that is readable during Codechecker execution + Create config file for analysis + + Args: + ctx: The context variable + Returns: + A tuple: (config_file, environment_variables) + config_file is the file object to be read by Codechecker """ # Declare config file to use during analysis From 679e6b935d35fd9e0ea556b796b184cab83de595 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 23 Feb 2026 10:02:46 +0100 Subject: [PATCH 5/8] Apply buildifier lint suggestions to codechecker --- src/codechecker.bzl | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/codechecker.bzl b/src/codechecker.bzl index 6030b201..eb696160 100644 --- a/src/codechecker.bzl +++ b/src/codechecker.bzl @@ -46,6 +46,8 @@ def get_platform_alias(platform): """ Get platform alias for full platform names being used + Args: + platform: A string containing the platform Returns: string: If the full platform name is consistent with valid syntax, returns the short alias to represent it. @@ -190,7 +192,7 @@ codechecker = rule( "_compile_commands_filter": attr.label( allow_files = True, executable = True, - cfg = "host", + cfg = "exec", default = ":compile_commands_filter", ), "_codechecker_script_template": attr.label( @@ -267,7 +269,7 @@ _codechecker_test = rule( "_compile_commands_filter": attr.label( allow_files = True, executable = True, - cfg = "host", + cfg = "exec", default = ":compile_commands_filter", ), "_codechecker_script_template": attr.label( @@ -316,7 +318,24 @@ def codechecker_test( tags = [], per_file = False, **kwargs): - """ Bazel test to run CodeChecker """ + """ + Macro to choose the appropriate codechecker rule + + Args: + name: Name of the target invoking CodeChecker. + targets: List of targets to be analyzed by CodeChecker. + platform: Platform to be analyzed on. + severities: List of warning levels that should be considered failing. + skip: Skip patterns for CodeChecker. + config: Config target for CodeChecker. + analyze: List of analyze command arguments. + tags: Bazel tags + per_file: Boolean value, toggles wether to run the analysis + with the experimental per_file rule. + **kwargs: Other miscellaneous arguments. + Returns: + none + """ codechecker_tags = [] + tags if "codechecker" not in tags: codechecker_tags.append("codechecker") @@ -352,7 +371,22 @@ def codechecker_suite( analyze = [], tags = [], **kwargs): - """ Bazel test suite to run CodeChecker for different platforms """ + """ + Bazel test suite to run CodeChecker for different platforms + + Args: + name: Name of the target invoking CodeChecker. + targets: List of targets to be analyzed by CodeChecker. + platforms: List of platform to be analyzed on. + severities: List of warning levels that should be considered failing. + skip: Skip patterns for CodeChecker. + config: Config target for CodeChecker. + analyze: List of analyze command arguments. + tags: Bazel tags + **kwargs: Other miscellaneous arguments. + Returns: + none + """ tests = [] for platform in platforms: shortname = get_platform_alias(platform) From cd96bc65ce143793fc898f8d12c8e3d134e428d9 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 23 Feb 2026 10:03:04 +0100 Subject: [PATCH 6/8] Apply (most) buildifier lint suggestions to per_file --- src/per_file.bzl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/per_file.bzl b/src/per_file.bzl index 8a9be0fa..32f11801 100644 --- a/src/per_file.bzl +++ b/src/per_file.bzl @@ -17,16 +17,12 @@ Rulesets for running codechecker in a different Bazel action for each translation unit. """ -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load("codechecker_config.bzl", "get_config_file") -load("common.bzl", "SOURCE_ATTR") load( "compile_commands.bzl", "SourceFilesInfo", "compile_commands_aspect", "compile_commands_impl", - "platforms_transition", ) def _run_code_checker( @@ -84,8 +80,14 @@ def _run_code_checker( def check_valid_file_type(src): """ + Checks if the file is a cpp related file. + Returns True if the file type matches one of the permitted srcs file types for C and C++ source files. + Args: + src: Path of a single source file. + Returns: + Boolean value. """ permitted_file_types = [ ".c", From 978b426886b667e1d2beb0974058d4e3857320a6 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 23 Feb 2026 10:03:17 +0100 Subject: [PATCH 7/8] Apply buildifier lint suggestions to clang_ctu --- src/clang_ctu.bzl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/clang_ctu.bzl b/src/clang_ctu.bzl index 6c7b80d1..0b756fab 100644 --- a/src/clang_ctu.bzl +++ b/src/clang_ctu.bzl @@ -18,7 +18,7 @@ Ruleset for running the clang static analyzer with CTU analysis. load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") -load("common.bzl", "SOURCE_ATTR", "version_specific_attributes") +load("common.bzl", "SOURCE_ATTR") CLANG_CTU_WRAPPER_SCRIPT = """#!/usr/bin/env bash #set -x @@ -132,8 +132,14 @@ def _run_clang_ctu( def check_valid_file_type(src): """ + Checks if the file is a cpp related file. + Returns True if the file type matches one of the permitted srcs file types for C and C++ header/source files. + Args: + src: Path of a single source file. + Returns: + Boolean value. """ permitted_file_types = [ ".c", @@ -158,8 +164,8 @@ def check_valid_file_type(src): def _rule_sources(ctx): srcs = [] if hasattr(ctx.rule.attr, "srcs"): - for src in ctx.rule.attr.srcs: - srcs += [src for src in src.files.to_list() if src.is_source and check_valid_file_type(src)] + for src_outer in ctx.rule.attr.srcs: + srcs += [src for src in src_outer.files.to_list() if src.is_source and check_valid_file_type(src)] return srcs def _toolchain_flags(ctx, action_name, with_compiler = False): @@ -324,7 +330,7 @@ def _generate_ast_and_def_files(ctx, target, all_sources): def _collect_all_sources_and_headers(ctx): all_files = [] - headers = depset() + headers_list = [] for target in ctx.attr.targets: if not CcInfo in target: continue @@ -333,10 +339,8 @@ def _collect_all_sources_and_headers(ctx): srcs = target[CompileInfo].arguments.keys() all_files += srcs compilation_context = target[CcInfo].compilation_context - headers = depset( - transitive = [headers, compilation_context.headers], - ) - sources_and_headers = all_files + headers.to_list() + headers_list.extend(compilation_context.headers.to_list()) + sources_and_headers = all_files + headers_list return sources_and_headers def _clang_ctu_impl(ctx): From a59b65bea47b39cb78c46d053d5841653223e2d2 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 23 Feb 2026 10:03:27 +0100 Subject: [PATCH 8/8] Apply buildifier list suggestions to clang --- src/clang.bzl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/clang.bzl b/src/clang.bzl index 06b1c562..44c48e94 100644 --- a/src/clang.bzl +++ b/src/clang.bzl @@ -215,8 +215,14 @@ def _run_analyzer( def check_valid_file_type(src): """ + Checks if the file is a cpp related file. + Returns True if the file type matches one of the permitted srcs file types for C and C++ header/source files. + Args: + src: Path of a single source file. + Returns: + Boolean value. """ permitted_file_types = [ ".c", @@ -326,6 +332,8 @@ CompileInfo = provider( }, ) +# buildifier: disable=unused-variable +# The headers variable is used: headers += dep[CompileInfo].headers.to_list() def _process_all_deps(ctx, arguments, headers): for attr in SOURCE_ATTR: if hasattr(ctx.rule.attr, attr): @@ -391,7 +399,7 @@ compile_info_aspect = aspect( def _clang_test(ctx, tool): all_files = [] - all_headers = depset() + all_headers_list = [] for target in ctx.attr.targets: if CompileInfo in target: if hasattr(target[CompileInfo], "arguments"): @@ -411,8 +419,9 @@ def _clang_test(ctx, tool): ctx.attr.name, ) all_files.append(report) - all_headers = depset(transitive = [all_headers, headers]) + all_headers_list.extend(headers.to_list()) + all_headers = depset(all_headers_list) ctx.actions.write( output = ctx.outputs.test_script, is_executable = True,