diff --git a/.ci/buildifier/BUILD b/.ci/buildifier/BUILD deleted file mode 100644 index 7d97d56e..00000000 --- a/.ci/buildifier/BUILD +++ /dev/null @@ -1,4 +0,0 @@ -exports_files([ - "prune.patch", - "template.patch", -]) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 928b8423..48fbf7fc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -81,7 +81,7 @@ jobs: - name: Run lint tests run: | pylint . - bazel test //:buildifier --test_output=all + bazel test //test/buildifier --test_output=all shell: bash -el {0} # Splitting unit and FOSS tests, since unit tests fail faster. @@ -151,7 +151,7 @@ jobs: - name: Run lint tests run: | pylint . - runuser -u test -- bazel test //:buildifier --test_output=all + runuser -u test -- bazel test //test/buildifier --test_output=all shell: bash -el {0} # Splitting unit and FOSS tests, since unit tests fail faster. diff --git a/BUILD b/BUILD index 20f7c316..ca7fcde7 100644 --- a/BUILD +++ b/BUILD @@ -1,15 +1,47 @@ -load("@buildifier_prebuilt//:rules.bzl", "buildifier_test") - -buildifier_test( - name = "buildifier", - exclude_patterns = [ - "./.ci/*", - "./.git/*", - ], - lint_mode = "warn", - lint_warnings = ["all"], - mode = "diff", - no_sandbox = True, - verbose = True, - workspace = "//:MODULE.bazel", +# Copyright 2026 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. +load("//src:codechecker_toolchain.bzl", "codechecker_toolchain") + +# The public labels of rules_codechecker live here, +# the implementation is in //src +# +# NOTE: only load from packages visible to our consumers here, +# this package is loaded by everyone who resolves //:default_toolchain + +# Repository root marker, used by the buildifier test to find the workspace +exports_files( + ["MODULE.bazel"], + visibility = ["//test/buildifier:__pkg__"], +) + +# Named by convention +# https://bazel.build/extending/toolchains#writing-rules-toolchains +toolchain_type( + name = "toolchain_type", + visibility = ["//visibility:public"], +) + +# Tools found on PATH, provisioned by the default_codechecker_tools extension +codechecker_toolchain( + name = "default_tools", + clang_tidy = "@default_codechecker_tools//:clang_tidy", + clangsa = "@default_codechecker_tools//:clang", + codechecker = "@default_codechecker_tools//:CodeChecker", +) + +toolchain( + name = "default_toolchain", + toolchain = ":default_tools", + toolchain_type = ":toolchain_type", ) diff --git a/MODULE.bazel b/MODULE.bazel index e0659ac0..478e7188 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -28,8 +28,8 @@ single_version_override( module_name = "buildifier_prebuilt", patch_strip = 1, patches = [ - "//.ci/buildifier:prune.patch", - "//.ci/buildifier:template.patch", + "//test/buildifier:prune.patch", + "//test/buildifier:template.patch", ], ) @@ -40,5 +40,5 @@ codechecker_extension = use_extension( use_repo(codechecker_extension, "default_codechecker_tools") register_toolchains( - "//src:codechecker_local_toolchain", + "//:default_toolchain", ) diff --git a/README.md b/README.md index ed350b7c..1fc86282 100644 --- a/README.md +++ b/README.md @@ -454,7 +454,7 @@ codechecker_extension = use_extension( "module_register_default_codechecker_tools", ) use_repo(codechecker_extension, "default_codechecker_tools") -register_toolchains("@rules_codechecker//src:codechecker_local_toolchain") +register_toolchains("@rules_codechecker//:default_toolchain") ``` ### Providing your own tools @@ -491,7 +491,7 @@ codechecker_toolchain( toolchain( name = "codechecker_custom_toolchain", toolchain = ":codechecker_custom", - toolchain_type = "@rules_codechecker//src:toolchain_type", + toolchain_type = "@rules_codechecker//:toolchain_type", # Optionally constrain which execution platform this applies to: # exec_compatible_with = ["@platforms//os:linux"], ) diff --git a/defs.bzl b/defs.bzl index ed05b914..a2039a38 100644 --- a/defs.bzl +++ b/defs.bzl @@ -32,6 +32,7 @@ load( _codechecker_config = "codechecker_config", _codechecker_suite = "codechecker_suite", _codechecker_test = "codechecker_test", + _get_platform_alias = "get_platform_alias", ) # Toolchain rule, for providing custom tools @@ -53,3 +54,6 @@ codechecker_toolchain = _codechecker_toolchain compile_commands = _compile_commands clang_tidy_test = _clang_tidy_test clang_analyze_test = _clang_analyze_test + +# Helper for the platform suffix codechecker_suite() adds to its test names +get_platform_alias = _get_platform_alias diff --git a/src/BUILD b/src/BUILD index 22cc9a32..02e42b89 100644 --- a/src/BUILD +++ b/src/BUILD @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_python//python:py_binary.bzl", "py_binary") -load(":codechecker_toolchain.bzl", "codechecker_toolchain") # Tool filter compile_commands.json file py_binary( @@ -62,23 +61,3 @@ label_flag( build_setting_default = ":clang_tidy_additional_deps_default", visibility = ["//visibility:public"], ) - -# named this by convention -# https://bazel.build/extending/toolchains#:~:text=%23%20By%20convention%2C%20toolchain%5Ftype%20targets%20are%20named%20%22toolchain%5Ftype%22%20and -toolchain_type( - name = "toolchain_type", - visibility = ["//visibility:public"], -) - -codechecker_toolchain( - name = "codechecker_local", - clang_tidy = "@default_codechecker_tools//:clang_tidy", - clangsa = "@default_codechecker_tools//:clang", - codechecker = "@default_codechecker_tools//:CodeChecker", -) - -toolchain( - name = "codechecker_local_toolchain", - toolchain = "codechecker_local", - toolchain_type = ":toolchain_type", -) diff --git a/src/codechecker.bzl b/src/codechecker.bzl index 6580d5c3..ddd66a2e 100644 --- a/src/codechecker.bzl +++ b/src/codechecker.bzl @@ -92,7 +92,7 @@ def _codechecker_impl(ctx): config_file, codechecker_env = get_config_file(ctx) - info = ctx.toolchains["//src:toolchain_type"].codecheckerinfo + info = ctx.toolchains["//:toolchain_type"].codecheckerinfo codechecker_files = ctx.actions.declare_directory(ctx.label.name + "/codechecker-files") ctx.actions.expand_template( @@ -208,7 +208,7 @@ codechecker = rule( "compile_commands": "%{name}/compile_commands.json", }, toolchains = [ - "//src:toolchain_type", + "//:toolchain_type", ], ) @@ -229,7 +229,7 @@ def _codechecker_test_impl(ctx): if not codechecker_files: fail("Execution results required for codechecker test are not available") - info = ctx.toolchains["//src:toolchain_type"].codecheckerinfo + info = ctx.toolchains["//:toolchain_type"].codecheckerinfo # Create test script from template ctx.actions.expand_template( @@ -314,7 +314,7 @@ _codechecker_test = rule( "compile_commands": "%{name}/compile_commands.json", }, toolchains = [ - "//src:toolchain_type", + "//:toolchain_type", ], test = True, ) diff --git a/src/per_file.bzl b/src/per_file.bzl index 339a1623..b30d600d 100644 --- a/src/per_file.bzl +++ b/src/per_file.bzl @@ -192,7 +192,7 @@ def _per_file_impl(ctx): _create_wrapper_script(ctx, options, compile_commands, config_file) # TODO: Consider using aliases so we don't have to type //src: everywhere. - info = ctx.toolchains["//src:toolchain_type"].codecheckerinfo + info = ctx.toolchains["//:toolchain_type"].codecheckerinfo for target in ctx.attr.targets: if not CcInfo in target: continue @@ -284,5 +284,5 @@ per_file_test = rule( "test_script": "%{name}/test_script.sh", }, test = True, - toolchains = ["//src:toolchain_type"], + toolchains = ["//:toolchain_type"], ) diff --git a/test/buildifier/BUILD b/test/buildifier/BUILD new file mode 100644 index 00000000..94016fb1 --- /dev/null +++ b/test/buildifier/BUILD @@ -0,0 +1,39 @@ +# Copyright 2026 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. +load("@buildifier_prebuilt//:rules.bzl", "buildifier_test") + +# Patches applied to buildifier_prebuilt, see MODULE.bazel +exports_files([ + "prune.patch", + "template.patch", +]) + +# The linter is declared here, and not in the root package, because +# buildifier_prebuilt is a dev dependency and therefore not visible to our +# consumers, while the root package is loaded by everyone who resolves +# //:default_toolchain. The whole repository is still checked, no_sandbox +# and the workspace attribute make the test run from the repository root. +buildifier_test( + name = "buildifier", + exclude_patterns = [ + "./.ci/*", + "./.git/*", + ], + lint_mode = "warn", + lint_warnings = ["all"], + mode = "diff", + no_sandbox = True, + verbose = True, + workspace = "//:MODULE.bazel", +) diff --git a/.ci/buildifier/prune.patch b/test/buildifier/prune.patch similarity index 100% rename from .ci/buildifier/prune.patch rename to test/buildifier/prune.patch diff --git a/.ci/buildifier/template.patch b/test/buildifier/template.patch similarity index 100% rename from .ci/buildifier/template.patch rename to test/buildifier/template.patch