Skip to content

Commit 1f154d0

Browse files
committed
Warn about header only libraries.
...and defend against crash when external files are excluded. Fixes #92
1 parent a69b071 commit 1f154d0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

refresh.template.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -909,15 +909,17 @@ def _get_commands(target: str, flags: str):
909909
try:
910910
# object_hook -> SimpleNamespace allows object.member syntax, like a proto, while avoiding the protobuf dependency
911911
parsed_aquery_output = json.loads(aquery_process.stdout, object_hook=lambda d: types.SimpleNamespace(**d))
912-
# Further mimic a proto by protecting against the case where there are no actions found.
913-
# Otherwise, SimpleNamespace, unlike a real proto, won't create an actions attribute, leading to an AttributeError on access.
914-
if not hasattr(parsed_aquery_output, 'actions'):
915-
parsed_aquery_output.actions = []
916912
except json.JSONDecodeError:
917913
print("Bazel aquery failed. Command:", aquery_args, file=sys.stderr)
918914
log_warning(f">>> Failed extracting commands for {target}\n Continuing gracefully...")
919915
return
920916

917+
if not getattr(parsed_aquery_output, 'actions', None): # Unifies cases: No actions (or actions list is empty)
918+
log_warning(f""">>> Bazel lists no applicable compile commands for {target}
919+
If this is a header-only library, please instead specify a test or binary target that compiles it (search "header-only" in README.md).
920+
Continuing gracefully...""")
921+
return
922+
921923
yield from _convert_compile_commands(parsed_aquery_output)
922924

923925

0 commit comments

Comments
 (0)