Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .ci/buildifier/BUILD

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
60 changes: 46 additions & 14 deletions BUILD
Original file line number Diff line number Diff line change
@@ -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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name does not communicate that this toolchain cannot be used with remote executors!

This toolchain is specific to a user's local environment.

We could rename it to something like this.

Suggested change
name = "default_tools",
name = "default_local_tools",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... "local" is actually kinda misleading and wrong here.
Local to what? Besides, should this be default forever?
Default tools are being taken from the environment currently, which is totally wrong!
Later default_tools should became real default, not local.

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",
)
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand All @@ -40,5 +40,5 @@ codechecker_extension = use_extension(
use_repo(codechecker_extension, "default_codechecker_tools")

register_toolchains(
"//src:codechecker_local_toolchain",
"//:default_toolchain",
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"],
)
Expand Down
4 changes: 4 additions & 0 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
21 changes: 0 additions & 21 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
)
8 changes: 4 additions & 4 deletions src/codechecker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -208,7 +208,7 @@ codechecker = rule(
"compile_commands": "%{name}/compile_commands.json",
},
toolchains = [
"//src:toolchain_type",
"//:toolchain_type",
],
)

Expand All @@ -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(
Expand Down Expand Up @@ -314,7 +314,7 @@ _codechecker_test = rule(
"compile_commands": "%{name}/compile_commands.json",
},
toolchains = [
"//src:toolchain_type",
"//:toolchain_type",
],
test = True,
)
Expand Down
4 changes: 2 additions & 2 deletions src/per_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to preserve this comment if this PR lands.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

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
Expand Down Expand Up @@ -284,5 +284,5 @@ per_file_test = rule(
"test_script": "%{name}/test_script.sh",
},
test = True,
toolchains = ["//src:toolchain_type"],
toolchains = ["//:toolchain_type"],
)
39 changes: 39 additions & 0 deletions test/buildifier/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2026 Ericsson AB

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving Buildifier into testing is outside the scope of a Public API patch.

@nettle nettle Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I've created a separate PR: #289

#
# 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",
)
File renamed without changes.
File renamed without changes.
Loading