diff --git a/src/code_checker.bzl b/src/code_checker.bzl index 2d0c81b4..1f0d0424 100644 --- a/src/code_checker.bzl +++ b/src/code_checker.bzl @@ -62,7 +62,13 @@ def _run_code_checker( clangsa_plist = ctx.actions.declare_file(clangsa_plist_file_name) codechecker_log = ctx.actions.declare_file(codechecker_log_file_name) - inputs = [compile_commands_json] + sources_and_headers + if "--ctu" in options: + inputs = [compile_commands_json] + sources_and_headers + else: + # NOTE: we collect only headers, so CTU may not work! + headers = depset([src], transitive = [compilation_context.headers]) + inputs = depset([compile_commands_json, src], transitive = [headers]) + outputs = [clang_tidy_plist, clangsa_plist, codechecker_log] # Create CodeChecker wrapper script @@ -274,6 +280,7 @@ def _compile_commands_impl(ctx): return compile_commands_json def _collect_all_sources_and_headers(ctx): + # NOTE: we are only using this function for CTU all_files = [] headers = depset() for target in ctx.attr.targets: diff --git a/test/unit/caching/test_caching.py b/test/unit/caching/test_caching.py index 4690f06b..de6e4b30 100644 --- a/test/unit/caching/test_caching.py +++ b/test/unit/caching/test_caching.py @@ -73,10 +73,8 @@ def test_bazel_test_code_checker_caching(self): self.fail(f"File not found!") ret, _, stderr = self.run_command(f"bazel build {target} --subcommands") self.assertEqual(ret, 0) - # FIXME: This should be 1; 2 means that both .cpp files were reanalyzed - # despite only one of them being changed. self.assertEqual( - stderr.count(f"SUBCOMMAND: # {target} [action 'CodeChecker"), 2 + stderr.count(f"SUBCOMMAND: # {target} [action 'CodeChecker"), 1 ) def test_bazel_test_code_checker_ctu_caching(self):