Skip to content
Merged
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
9 changes: 8 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ jobs:
with:
python-version: "3.10"

- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.15.0

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
echo "6.5.0" > .bazelversion

- name: Analysing the code with pylint
run: pylint .

- name: Analyzing the code with Buildifier
run: |
pylint .
bazel test //:format_test --test_output=errors

# TODO: Add more linters here
31 changes: 31 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@aspect_rules_lint//format:defs.bzl", "format_test")
load("@buildifier_prebuilt//:rules.bzl", "buildifier_test")

buildifier_test(
name = "buildifier_native",
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.

I wonder why it is named "_native"?
Any reasons for that?

diff_command = "diff -u",
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.

May I ask why do we need this?

exclude_patterns = [
"./.git/*",
],
lint_mode = "warn",
mode = "diff",
no_sandbox = True,
workspace = "//:WORKSPACE",
)

format_test(
name = "format_test",
# Temporary workaround for not being able to use -diff_command
env = ["BUILDIFIER_DIFF='diff -u'"],
no_sandbox = True,
# TODO: extend with pylint
starlark = "@buildifier_prebuilt//:buildifier",
starlark_check_args = [
"-lint=warn",
"-warnings=all",
"-mode=diff",
# -u will always get passed to buildifier not diff_command
#"-diff_command=\"diff -u\"",
],
workspace = "//:WORKSPACE",
)
Comment on lines +16 to +31
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.

Seems like not needed

7 changes: 7 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ module(name = "rules_codechecker")
bazel_dep(name = "rules_python", version = "0.32.0")
bazel_dep(name = "rules_cc", version = "0.2.3")

bazel_dep(
name = "buildifier_prebuilt",
version = "6.4.0",
dev_dependency = True,
)
bazel_dep(name = "aspect_rules_lint", version = "1.11.0", dev_dependency = True)
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.

I think we do not need this. This is actually duplication of buildifier_prebuilt


codechecker_extension = use_extension(
"//src:tools.bzl",
"module_register_default_codechecker",
Expand Down
51 changes: 51 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,54 @@ register_default_python_toolchain()
register_toolchains("@default_python_tools//:python_toolchain")

register_default_codechecker()

# Dev dependencies

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "buildifier_prebuilt",
sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e",
strip_prefix = "buildifier-prebuilt-6.4.0",
urls = [
"http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz",
],
)

load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()

http_archive(
name = "aspect_rules_lint",
sha256 = "329cf5ba776a75b70049a5695e9ca29a25113230f4f447aff7102b62afe7c24a",
strip_prefix = "rules_lint-1.11.0",
url = "https://github.com/aspect-build/rules_lint/releases/download/v1.11.0/rules_lint-v1.11.0.tar.gz",
)

http_archive(
name = "bazel_lib",
sha256 = "0758ace949a93f709230a8e08ef35c5f0aacae2ff5d219b27da1d21d8233a709",
strip_prefix = "bazel-lib-3.0.0-rc.0",
url = "https://github.com/bazel-contrib/bazel-lib/releases/download/v3.0.0-rc.0/bazel-lib-v3.0.0-rc.0.tar.gz",
)

load("@bazel_lib//lib:repositories.bzl", "bazel_lib_dependencies")

bazel_lib_dependencies()

load(
"@aspect_rules_lint//format:repositories.bzl",
# Fetch additional formatter binaries you need:
"rules_lint_dependencies",
)

rules_lint_dependencies()
3 changes: 3 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# limitations under the License.

# Tool filter compile_commands.json file
# In bazel 6 we use our own python toolchain,
# therefore we cannot load from rules_python.
# buildifier: disable=native-py
py_binary(
name = "compile_commands_filter",
srcs = ["compile_commands_filter.py"],
Expand Down
78 changes: 39 additions & 39 deletions src/clang.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -446,21 +446,10 @@ def _clang_tidy_test_impl(ctx):
clang_tidy_test = rule(
implementation = _clang_tidy_test_impl,
attrs = {
"platform": attr.string(
default = "", #"@platforms//os:linux",
doc = "Platform to build for",
),
"targets": attr.label_list(
aspects = [
compile_info_aspect,
],
cfg = platforms_transition,
doc = "List of compilable targets which should be checked.",
),
"options": attr.string_list(
# Since clang-tidy-22 clang-tidy fails if no checkers are enabled
default = ["--checks=bugprone-*"],
doc = "List of clang-tidy options, e.g.: --checks=",
"config_file": attr.label(
default = None,
allow_single_file = True,
doc = "Clang-tidy config file (usually .clang-tidy)",
),
"default_options": attr.string_list(
default = [
Expand All @@ -472,18 +461,29 @@ clang_tidy_test = rule(
],
doc = "List of default clang-tidy options",
),
"config_file": attr.label(
default = None,
allow_single_file = True,
doc = "Clang-tidy config file (usually .clang-tidy)",
),
"executable": attr.label(
default = None,
allow_single_file = True,
executable = True,
cfg = "exec",
doc = "Clang-tidy executable",
),
"options": attr.string_list(
# Since clang-tidy-22 clang-tidy fails if no checkers are enabled
default = ["--checks=bugprone-*"],
doc = "List of clang-tidy options, e.g.: --checks=",
),
"platform": attr.string(
default = "", #"@platforms//os:linux",
doc = "Platform to build for",
),
"targets": attr.label_list(
aspects = [
compile_info_aspect,
],
cfg = platforms_transition,
doc = "List of compilable targets which should be checked.",
),
} | version_specific_attributes(),
outputs = {
"test_script": "%{name}.test_script.sh",
Expand All @@ -497,20 +497,10 @@ def _clang_analyze_test_impl(ctx):
clang_analyze_test = rule(
implementation = _clang_analyze_test_impl,
attrs = {
"platform": attr.string(
default = "", #"@platforms//os:linux",
doc = "Platform to build for",
),
"targets": attr.label_list(
aspects = [
compile_info_aspect,
],
cfg = platforms_transition,
doc = "List of compilable targets which should be checked.",
),
"options": attr.string_list(
default = [],
doc = "List of clang options, e.g.: -fcolor-diagnostics",
"config_file": attr.label(
default = None,
allow_single_file = True,
doc = "?", # FIXME: configuration file for clang -analyze?
),
"default_options": attr.string_list(
default = [
Expand All @@ -527,18 +517,28 @@ clang_analyze_test = rule(
],
doc = "List of default clang options",
),
"config_file": attr.label(
default = None,
allow_single_file = True,
doc = "?", # FIXME: configuration file for clang -analyze?
),
"executable": attr.label(
default = None,
allow_single_file = True,
executable = True,
cfg = "exec",
doc = "Clang executable",
),
"options": attr.string_list(
default = [],
doc = "List of clang options, e.g.: -fcolor-diagnostics",
),
"platform": attr.string(
default = "", #"@platforms//os:linux",
doc = "Platform to build for",
),
"targets": attr.label_list(
aspects = [
compile_info_aspect,
],
cfg = platforms_transition,
doc = "List of compilable targets which should be checked.",
),
} | version_specific_attributes(),
outputs = {
"test_script": "%{name}.test_script.sh",
Expand Down
8 changes: 4 additions & 4 deletions src/clang_ctu.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,6 @@ def _clang_ctu_impl(ctx):
clang_ctu_test = rule(
implementation = _clang_ctu_impl,
attrs = {
"options": attr.string_list(
default = [],
doc = "List of clang --analyze options",
),
"default_options": attr.string_list(
default = [
"-fcolor-diagnostics",
Expand All @@ -425,6 +421,10 @@ clang_ctu_test = rule(
# Use: clang -cc1 -analyzer-config-help
doc = "List of default analyze options",
),
"options": attr.string_list(
default = [],
doc = "List of clang --analyze options",
),
"targets": attr.label_list(
aspects = [
compile_info_aspect,
Expand Down
Loading
Loading