Skip to content

Commit ee8a622

Browse files
committed
Fetch cppcheck
1 parent e770500 commit ee8a622

File tree

7 files changed

+84
-5
lines changed

7 files changed

+84
-5
lines changed

example/.aspect/cli/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ lint:
1010
- //tools/lint:linters.bzl%vale
1111
- //tools/lint:linters.bzl%checkstyle
1212
- //tools/lint:linters.bzl%clang_tidy
13+
- //tools/lint:linters.bzl%cppcheck
1314
- //tools/lint:linters.bzl%spotbugs
1415
- //tools/lint:linters.bzl%keep_sorted

example/MODULE.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,22 @@ ruby.bundle_fetch(
173173
use_repo(ruby, "bundle", "ruby", "ruby_toolchains")
174174

175175
register_toolchains("@ruby_toolchains//:all")
176+
177+
# Download cppcheck premium tar files for different platforms
178+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
179+
180+
http_archive(
181+
name = "cppcheck_linux",
182+
build_file = "//tools/lint:cppcheck.BUILD",
183+
integrity = "sha256-IqQ3Iofw6LoHh4YcdbN0m3tjg6utCiey7nGaOaPMv/I=",
184+
strip_prefix = "cppcheckpremium-25.8.3",
185+
urls = ["https://files.cppchecksolutions.com/25.8.3/ubuntu-22.04/cppcheckpremium-25.8.3-amd64.tar.gz"],
186+
)
187+
188+
http_archive(
189+
name = "cppcheck_macos",
190+
build_file = "//tools/lint:cppcheck.BUILD",
191+
integrity = "sha256-PEtm/DxKNZNJJuZE+56AZ80R22sZjZoziekAmR7FhNk=",
192+
strip_prefix = "cppcheckpremium",
193+
urls = ["https://files.cppchecksolutions.com/25.8.3/cppcheckpremium-25.8.3-macos-15.tar.gz"],
194+
)

example/WORKSPACE.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,19 @@ multitool(
423423
"@aspect_rules_lint//lint:multitool.lock.json",
424424
],
425425
)
426+
427+
http_archive(
428+
name = "cppcheck_linux",
429+
build_file = "//tools/lint:cppcheck.BUILD",
430+
integrity = "sha256-IqQ3Iofw6LoHh4YcdbN0m3tjg6utCiey7nGaOaPMv/I=",
431+
strip_prefix = "cppcheckpremium-25.8.3",
432+
urls = ["https://files.cppchecksolutions.com/25.8.3/ubuntu-22.04/cppcheckpremium-25.8.3-amd64.tar.gz"],
433+
)
434+
435+
http_archive(
436+
name = "cppcheck_macos",
437+
build_file = "//tools/lint:cppcheck.BUILD",
438+
integrity = "sha256-PEtm/DxKNZNJJuZE+56AZ80R22sZjZoziekAmR7FhNk=",
439+
strip_prefix = "cppcheckpremium",
440+
urls = ["https://files.cppchecksolutions.com/25.8.3/cppcheckpremium-25.8.3-macos-15.tar.gz"],
441+
)

example/tools/lint/BUILD.bazel

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
1111
load("@npm//:stylelint/package_json.bzl", stylelint_bin = "bin")
1212
load("@rules_java//java:defs.bzl", "java_binary")
1313
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
14+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
1415

1516
package(default_visibility = ["//:__subpackages__"])
1617

@@ -120,7 +121,19 @@ alias(
120121
actual = "@bundle//bin:rubocop",
121122
)
122123

124+
# cppcheck
125+
genrule(
126+
name = "cppcheck_wrapper",
127+
srcs = ["cppcheck_wrapper.sh.tpl"],
128+
outs = ["cppcheck_wrapper.sh"],
129+
cmd = "cp $(location cppcheck_wrapper.sh.tpl) $@",
130+
)
131+
123132
sh_binary(
124133
name = "cppcheck",
125-
srcs = ["cppcheck_wrapper.sh"],
134+
srcs = [":cppcheck_wrapper"],
135+
data = select({
136+
"@platforms//os:linux": ["@cppcheck_linux//:files"],
137+
"@platforms//os:macos": ["@cppcheck_macos//:files"],
138+
}),
126139
)

example/tools/lint/cppcheck.BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# BUILD file for cppcheck premium external repository
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
filegroup(
6+
name = "files",
7+
srcs = glob(
8+
["**"],
9+
exclude = ["cppcheck.cfg"],
10+
),
11+
)

example/tools/lint/cppcheck_wrapper.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -o errexit -o nounset -o pipefail
4+
5+
SCRIPT_DIR="$(dirname "$0")"
6+
RUNFILES_DIR="$SCRIPT_DIR/cppcheck.runfiles"
7+
8+
# Find the cppcheck binary in the runfiles directory
9+
# It will be under one of the cppcheck_premium_* directories
10+
# Note: cppcheck may be a symlink, so don't use -type f
11+
CPPCHECK_BINARY=$(find "$RUNFILES_DIR" -name "cppcheck" \( -type f -o -type l \) 2>/dev/null | head -n1)
12+
13+
if [[ -z "$CPPCHECK_BINARY" ]]; then
14+
echo "Error: Could not find cppcheck binary in runfiles" >&2
15+
exit 1
16+
fi
17+
18+
# cppcheck does not support config files.
19+
# Instead options like --check-level can be added here:
20+
"$CPPCHECK_BINARY" \
21+
--check-level=exhaustive \
22+
--enable=warning,style,performance,portability,information \
23+
"$@"

0 commit comments

Comments
 (0)