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
18 changes: 12 additions & 6 deletions .ci/mise/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ experimental = true

[tools]
# Environment tools:
"bazel" = "6.5"
"bazel" = "7"
"python" = "3.11"
"pipx" = "latest"
"pipx:codechecker" = "6.26"
"pipx:codechecker" = "6.27"

# Clang tools:
"conda:clang" = "latest"
Expand Down Expand Up @@ -70,11 +70,17 @@ run = "# Installing tools"
quiet = true


[tasks."test"]
depends = ["install:bazel-7", "install:codechecker-26", "install:codechecker-27"]
[tasks."legacy"]
depends = [
"install:bazel-8",
"install:bazel-7",
"install:bazel-6",
"install:codechecker-27",
]
run = [
{ task = "test:7-26" },
{ task = "test:7-27" },
{ task = "test:8-27 test/unit/legacy" },
{ task = "test:7-27 test/unit/legacy" },
{ task = "test:6-27 test/unit/legacy" },
]

[tasks."test:all"]
Expand Down
17 changes: 10 additions & 7 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ limitations under the License.

module(name = "rules_codechecker")

# C/C++ rules: cc_library, cc_binary
bazel_dep(name = "rules_cc", version = "0.2.14")

# Python rules and toolchain
bazel_dep(name = "rules_python", version = "1.9.0")
python_extension = use_extension(
"//src:tools.bzl",
"module_register_default_python_toolchain",
"@rules_python//python/extensions:python.bzl",
"default_python_tools",
)
python_extension.toolchain(python_version = "3.11", is_default = True)
use_repo(python_extension, "default_python_tools")

# CodeChecker support
codechecker_extension = use_extension(
"//src:tools.bzl",
"module_register_default_codechecker",
)

use_repo(python_extension, "default_python_tools")

use_repo(codechecker_extension, "default_codechecker_tools")

register_toolchains("@default_python_tools//:python_toolchain")
2 changes: 0 additions & 2 deletions src/codechecker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def _codechecker_impl(ctx):
substitutions = {
"{Mode}": "Run",
"{Verbosity}": "DEBUG",
"{PythonPath}": python_path(ctx), # "/usr/bin/env python3",
"{codechecker_bin}": CODECHECKER_BIN_PATH,
"{compile_commands}": ctx.outputs.codechecker_commands.path,
"{codechecker_skipfile}": ctx.outputs.codechecker_skipfile.path,
Expand Down Expand Up @@ -233,7 +232,6 @@ def _codechecker_test_impl(ctx):
substitutions = {
"{Mode}": "Test",
"{Verbosity}": "INFO",
"{PythonPath}": python_path(ctx), # "/usr/bin/env python3",
"{codechecker_bin}": CODECHECKER_BIN_PATH,
"{codechecker_files}": codechecker_files.short_path,
"{Severities}": " ".join(ctx.attr.severities),
Expand Down
2 changes: 1 addition & 1 deletion src/codechecker_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!{PythonPath}
#!/usr/bin/env python3

# Copyright 2023 Ericsson AB
#
Expand Down
3 changes: 3 additions & 0 deletions src/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def python_toolchain_type():
def python_path(ctx):
"""
Returns version specific Python path
NOTE: this function is not being used
"""
py_toolchain = ctx.toolchains[python_toolchain_type()]
if hasattr(py_toolchain, "py3_runtime_info"):
Expand All @@ -61,6 +62,8 @@ def python_path(ctx):
elif hasattr(py_toolchain, "py3_runtime"):
py_runtime = py_toolchain.py3_runtime
python_path = py_runtime.interpreter_path
if not python_path:
python_path = py_runtime.interpreter.path
else:
fail("The resolved Python toolchain does not provide a Python3 runtime.")
if not python_path:
Expand Down
7 changes: 2 additions & 5 deletions src/per_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ for each translation unit.
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("codechecker_config.bzl", "get_config_file")
load("common.bzl", "SOURCE_ATTR")
load("common.bzl", "python_toolchain_type", "SOURCE_ATTR")
load(
"compile_commands.bzl",
"SourceFilesInfo",
Expand Down Expand Up @@ -126,7 +126,6 @@ def _create_wrapper_script(ctx, options, compile_commands_json, config_file):
output = ctx.outputs.per_file_script,
is_executable = True,
substitutions = {
"{PythonPath}": ctx.attr._python_runtime[PyRuntimeInfo].interpreter_path,
"{compile_commands_json}": compile_commands_json.path,
"{codechecker_args}": options_str,
"{config_file}": config_file.path,
Expand Down Expand Up @@ -225,14 +224,12 @@ per_file_test = rule(
default = ":per_file_script.py",
allow_single_file = True,
),
"_python_runtime": attr.label(
default = "@default_python_tools//:py3_runtime",
),
},
outputs = {
"compile_commands": "%{name}/compile_commands.json",
"test_script": "%{name}/test_script.sh",
"per_file_script": "%{name}/per_file_script.py",
},
toolchains = [python_toolchain_type()],
test = True,
)
2 changes: 1 addition & 1 deletion src/per_file_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!{PythonPath}
#!/usr/bin/env python3

# Copyright 2023 Ericsson AB
#
Expand Down
9 changes: 7 additions & 2 deletions test/foss/yaml-cpp/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ codechecker_test(
],
)

# per_file fails with the following error:
# ERROR: BUILD.bazel:31:17: output 'per_file_test/data/src-emitter.cpp_clangsa.plist' was not created
# ERROR: BUILD.bazel:31:17: CodeChecker analyze src/emitter.cpp failed: not all outputs were created or valid
codechecker_test(
name = "per_file_test",
targets = [
":yaml-cpp",
],
per_file = True,
#<<< per_file = True,
)

#-------------------------------------------------------
EOF

# Add rules_codechecker repo to WORKSPACE
# Add rules_codechecker repo to WORKSPACE for Bazel 6
cat ../templates/WORKSPACE.template >> "$1/WORKSPACE"
# And to MODULE.bazel for Bazel 7, 8 and higher
cat ../templates/MODULE.template >> "$1/MODULE.bazel"
9 changes: 3 additions & 6 deletions test/foss/zlib-module/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ codechecker_test(
#-------------------------------------------------------
EOF

# Enable MODULE.bazel (in Bazel 6)
echo "common --enable_bzlmod" > "$1/.bazelrc"
# Add rules_codechecker repo MODULE.bazel
# Add rules_codechecker repo to WORKSPACE for Bazel 6
cat ../templates/WORKSPACE.template >> "$1/WORKSPACE"
# And to MODULE.bazel for Bazel 7, 8 and higher
cat ../templates/MODULE.template >> "$1/MODULE.bazel"
# An empty workspace file is required to keep Bazel versions older than 6.5.0
# in the project directory
touch "$1/WORKSPACE"
4 changes: 3 additions & 1 deletion test/foss/zlib/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ codechecker_test(
#-------------------------------------------------------
EOF

# Add rules_codechecker repo to WORKSPACE
# Add rules_codechecker repo to WORKSPACE for Bazel 6
cat ../templates/WORKSPACE.template >> "$1/WORKSPACE"
# And to MODULE.bazel for Bazel 7, 8 and higher
cat ../templates/MODULE.template >> "$1/MODULE.bazel"
33 changes: 14 additions & 19 deletions test/unit/external_repository/test_external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def setUpClass(cls):
logging.debug("No bazel version set, using system default")
_, stdout, _ = cls.run_command("bazel --version")
cls.BAZEL_VERSION = stdout.split(" ")[2].strip()
logging.debug("Using Bazel %s", cls.BAZEL_VERSION)
logging.debug("Bazel version: %s", cls.BAZEL_VERSION)
major_version = int(cls.BAZEL_VERSION.split(".")[0])
if major_version < 7:
raise unittest.SkipTest("Skip tests for Bazel older than 7")

@final
@classmethod
Expand All @@ -84,11 +87,11 @@ def tearDownClass(cls):
def test_compile_commands_external_lib(self):
"""
Test: bazel build :compile_commands_isystem "
"--experimental_cc_implementation_deps --enable_bzlmod
"--experimental_cc_implementation_deps
"""
ret, _, stderr = self.run_command(
"bazel build :compile_commands_isystem "
"--experimental_cc_implementation_deps --enable_bzlmod"
"--experimental_cc_implementation_deps"
)
self.assertEqual(ret, 0, stderr)
comp_json_file = os.path.join(
Expand All @@ -97,31 +100,23 @@ def test_compile_commands_external_lib(self):
"compile_commands.json",
)

# The ~override part is a consquence of using Bzlmod.
if self.BAZEL_VERSION.startswith("6"): # type: ignore
pattern1 = "-isystem external/external_lib~override/include"
pattern2 = (
"-isystem bazel-out/k8-fastbuild/bin/external/"
"external_lib~override/include"
)
else:
pattern1 = "-isystem external/external_lib~/include"
pattern2 = (
"-isystem bazel-out/k8-fastbuild/bin/external/"
"external_lib~/include"
)
pattern1 = r"-isystem external/external_lib./include"
pattern2 = (
r"-isystem bazel-out/k8-fastbuild/bin/external/"
"external_lib./include"
)

self.assertTrue(self.contains_regex_in_file(comp_json_file, pattern1))
self.assertTrue(self.contains_regex_in_file(comp_json_file, pattern2))

def test_codechecker_external_lib(self):
"""
Test: bazel build :codechecker_external_deps
--experimental_cc_implementation_deps --enable_bzlmod
--experimental_cc_implementation_deps
"""
ret, _, stderr = self.run_command(
"bazel build :codechecker_external_deps "
"--experimental_cc_implementation_deps --enable_bzlmod"
"--experimental_cc_implementation_deps"
)
self.assertEqual(ret, 0, stderr)

Expand All @@ -130,7 +125,7 @@ def test_per_file_external_lib(self):
"--experimental_cc_implementation_deps"""
ret, _, stderr = self.run_command(
"bazel build :per_file_external_deps "
"--experimental_cc_implementation_deps --enable_bzlmod"
"--experimental_cc_implementation_deps"
)
self.assertEqual(ret, 0, stderr)

Expand Down
5 changes: 5 additions & 0 deletions test/unit/legacy/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
load("@rules_cc//cc:defs.bzl",
"cc_binary",
"cc_library",
)

# clang-tidy and clang -analyze rules
load(
"//src:clang.bzl",
Expand Down