Skip to content

Commit 2e6eb8a

Browse files
committed
Fetch cppcheck
1 parent 18a989a commit 2e6eb8a

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

example/MODULE.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,22 @@ rust.toolchain(
128128
edition = "2021",
129129
versions = ["1.75.0"],
130130
)
131+
132+
# Download cppcheck premium tar files for different platforms
133+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
134+
135+
http_archive(
136+
name = "cppcheck_premium_linux",
137+
build_file = "//tools/lint:cppcheck.BUILD",
138+
integrity = "sha256-kacV5Qvy8pHqYoejdDCId4yS3VJDaqTqSJ9JgEIfQd0=",
139+
strip_prefix = "cppcheckpremium-25.8.4",
140+
urls = ["https://files.cppchecksolutions.com/25.8.4/ubuntu-22.04/cppcheckpremium-25.8.4-amd64.tar.gz"],
141+
)
142+
143+
http_archive(
144+
name = "cppcheck_premium_macos",
145+
build_file = "//tools/lint:cppcheck.BUILD",
146+
integrity = "sha256-bsxXTXw2YPcClRfTXzsLtgDNTYDmHpNapu12la93tAs=",
147+
strip_prefix = "cppcheckpremium",
148+
urls = ["https://files.cppchecksolutions.com/25.8.4/cppcheckpremium-25.8.4-macos-15.tar.gz"],
149+
)

example/tools/lint/BUILD.bazel

Lines changed: 27 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

@@ -115,7 +116,32 @@ native_binary(
115116
out = "clang_tidy",
116117
)
117118

119+
genrule(
120+
name = "cppcheck_wrapper",
121+
srcs = ["cppcheck_wrapper.sh.tpl"] + select({
122+
"@platforms//os:linux": [
123+
"@cppcheck_premium_linux//:cppcheck_binary",
124+
],
125+
"@platforms//os:macos": [
126+
"@cppcheck_premium_macos//:cppcheck_binary",
127+
],
128+
}),
129+
outs = ["cppcheck_wrapper.sh"],
130+
cmd = select({
131+
"@platforms//os:linux": """
132+
sed 's|@@CPPCHECK_BINARY@@|$(rlocationpath @cppcheck_premium_linux//:cppcheck_binary)|g' $(location cppcheck_wrapper.sh.tpl) > $@
133+
""",
134+
"@platforms//os:macos": """
135+
sed 's|@@CPPCHECK_BINARY@@|$(rlocationpath @cppcheck_premium_macos//:cppcheck_binary)|g' $(location cppcheck_wrapper.sh.tpl) > $@
136+
""",
137+
}),
138+
)
139+
118140
sh_binary(
119141
name = "cppcheck",
120-
srcs = ["cppcheck_wrapper.sh"],
142+
srcs = [":cppcheck_wrapper"],
143+
data = select({
144+
"@platforms//os:linux": ["@cppcheck_premium_linux//:runtime_files"],
145+
"@platforms//os:macos": ["@cppcheck_premium_macos//:runtime_files"],
146+
}),
121147
)

example/tools/lint/cppcheck.BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# BUILD file for cppcheck premium external repository
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
# Main cppcheck binary as a specific target
6+
filegroup(
7+
name = "cppcheck_binary",
8+
srcs = ["cppcheck"],
9+
)
10+
11+
filegroup(
12+
name = "runtime_files",
13+
srcs = glob(["**"]),
14+
)

example/tools/lint/cppcheck_wrapper.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$(dirname "$0")"
4+
CPPCHECK_BINARY="$SCRIPT_DIR/cppcheck.runfiles/@@CPPCHECK_BINARY@@"
5+
6+
"$CPPCHECK_BINARY" \
7+
--check-level=exhaustive \
8+
--enable=warning,style,performance,portability,information \
9+
"$@"

0 commit comments

Comments
 (0)