Skip to content
Draft
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
21 changes: 21 additions & 0 deletions src/compile_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,27 @@ def compile_commands_impl(ctx):
),
]

def get_compile_commands(ctx, check=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see, the only meaningful difference here and #141 is the check parameter. Why would ever want to skip these checks though?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting files from DefaultInfo provider is a kind of common operation. Theoretically we can also get empty list or no list, and none of these is necessary a fail. That actually may apply to compile_commands.json file as well. We add checks only to handle our specific scenario. To be honest , generalizing this as a function does not look much useful to me.

""" Returns the compilation database file

Returns:
compile_commands.json File object
"""
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()
# FIXME: there should be just one file
if check and not compile_commands:
fail("Failed to generate compile_commands.json file!")
if check and not source_files:
fail("Failed to collect source files!")
if check and compile_commands != ctx.outputs.compile_commands:
fail("Seems compile_commands.json file is incorrect!")
return compile_commands

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