Skip to content
Draft
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
16 changes: 2 additions & 14 deletions src/codechecker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Rulesets for running codechecker in a single Bazel job.
load(
"compile_commands.bzl",
"compile_commands_aspect",
"compile_commands_impl",
"get_compile_commands_json_and_srcs",
"platforms_transition",
)
load(
Expand Down Expand Up @@ -58,19 +58,7 @@ def _codechecker_impl(ctx):
py_runtime_info = ctx.attr._python_runtime[PyRuntimeInfo]
python_path = py_runtime_info.interpreter_path

# Get compile_commands.json file and source files
compile_commands = None
source_files = None
for output in compile_commands_impl(ctx):
if type(output) == "DefaultInfo":
compile_commands = output.files.to_list()[0]
source_files = output.default_runfiles.files.to_list()
if not compile_commands:
fail("Failed to generate compile_commands.json file!")
if not source_files:
fail("Failed to collect source files!")
if compile_commands != ctx.outputs.compile_commands:
fail("Seems compile_commands.json file is incorrect!")
compile_commands, source_files = get_compile_commands_json_and_srcs(ctx)

# Convert flacc calls to clang in compile_commands.json
# and save to codechecker_commands.json
Expand Down
23 changes: 23 additions & 0 deletions src/compile_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,29 @@ def compile_commands_impl(ctx):
),
]

def get_compile_commands_json_and_srcs(ctx):
""" Creates the compilation database for internal use.

Returns:
compile_commands - location of the compilation database file
source_files - files to analyze
"""
# Get compile_commands.json file and source files
compile_commands = None
source_files = None
for output in compile_commands_impl(ctx):
if type(output) == "DefaultInfo":
compile_commands = output.files.to_list()[0]
source_files = output.default_runfiles.files.to_list()
if not compile_commands:
fail("Failed to generate compile_commands.json file!")
if not source_files:
fail("Failed to collect source files!")
if compile_commands != ctx.outputs.compile_commands:
fail("Seems compile_commands.json file is incorrect!")

return compile_commands, source_files

_compile_commands = rule(
implementation = compile_commands_impl,
attrs = {
Expand Down