Skip to content

Commit 4c0e4cc

Browse files
committed
Greate a convenience function for interacting with compile_commands_impl
1 parent d198b7d commit 4c0e4cc

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

src/codechecker.bzl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Rulesets for running codechecker in a single Bazel job.
1919
load(
2020
"compile_commands.bzl",
2121
"compile_commands_aspect",
22-
"compile_commands_impl",
22+
"get_compile_commands_json_and_srcs",
2323
"platforms_transition",
2424
)
2525
load(
@@ -58,19 +58,7 @@ def _codechecker_impl(ctx):
5858
py_runtime_info = ctx.attr._python_runtime[PyRuntimeInfo]
5959
python_path = py_runtime_info.interpreter_path
6060

61-
# Get compile_commands.json file and source files
62-
compile_commands = None
63-
source_files = None
64-
for output in compile_commands_impl(ctx):
65-
if type(output) == "DefaultInfo":
66-
compile_commands = output.files.to_list()[0]
67-
source_files = output.default_runfiles.files.to_list()
68-
if not compile_commands:
69-
fail("Failed to generate compile_commands.json file!")
70-
if not source_files:
71-
fail("Failed to collect source files!")
72-
if compile_commands != ctx.outputs.compile_commands:
73-
fail("Seems compile_commands.json file is incorrect!")
61+
compile_commands, source_files = get_compile_commands_json_and_srcs(ctx)
7462

7563
# Convert flacc calls to clang in compile_commands.json
7664
# and save to codechecker_commands.json

src/compile_commands.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,29 @@ def compile_commands_impl(ctx):
418418
),
419419
]
420420

421+
def get_compile_commands_json_and_srcs(ctx):
422+
""" Creates the compilation database for internal use.
423+
424+
Returns:
425+
compile_commands - location of the compilation database file
426+
source_files - files to analyze
427+
"""
428+
# Get compile_commands.json file and source files
429+
compile_commands = None
430+
source_files = None
431+
for output in compile_commands_impl(ctx):
432+
if type(output) == "DefaultInfo":
433+
compile_commands = output.files.to_list()[0]
434+
source_files = output.default_runfiles.files.to_list()
435+
if not compile_commands:
436+
fail("Failed to generate compile_commands.json file!")
437+
if not source_files:
438+
fail("Failed to collect source files!")
439+
if compile_commands != ctx.outputs.compile_commands:
440+
fail("Seems compile_commands.json file is incorrect!")
441+
442+
return compile_commands, source_files
443+
421444
_compile_commands = rule(
422445
implementation = compile_commands_impl,
423446
attrs = {

0 commit comments

Comments
 (0)