Skip to content

Commit 0197fc6

Browse files
committed
Defend external logic against potential breaking bazel change
bazelbuild/bazel#17069
1 parent ad4380b commit 0197fc6

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

refresh.template.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -786,17 +786,11 @@ def _convert_compile_commands(aquery_output):
786786
# Tag actions as external if we're going to need to know that later.
787787
if {exclude_headers} == "external" and not {exclude_external_sources}:
788788
targets_by_id = {target.id : target.label for target in aquery_output.targets}
789-
790-
def _amend_action_as_external(action):
791-
"""Tag action as external if it's created by an external target"""
789+
for action in aquery_output.actions:
790+
# Tag action as external if it's created by an external target
792791
target = targets_by_id[action.targetId] # Should always be present. KeyError as implicit assert.
793-
assert not target.startswith("@//"), f"Expecting local targets to start with // in aquery output. Found @// for action {action}, target {target}"
794-
assert not target.startswith("//external"), f"Expecting external targets will start with @. Found //external for action {action}, target {target}"
795-
796-
action.is_external = target.startswith("@")
797-
return action
798-
799-
aquery_output.actions = (_amend_action_as_external(action) for action in aquery_output.actions)
792+
assert not target.startswith('//external'), f"Expecting external targets will start with @. Found //external for action {action}, target {target}"
793+
action.is_external = target.startswith('@') and not target.startswith('@//')
800794

801795
# Process each action from Bazelisms -> file paths and their clang commands
802796
# Threads instead of processes because most of the execution time is farmed out to subprocesses. No need to sidestep the GIL. Might change after https://github.com/clangd/clangd/issues/123 resolved
@@ -856,7 +850,7 @@ def _get_commands(target: str, flags: str):
856850
target_statment = f'deps({target})'
857851
if {exclude_external_sources}:
858852
# For efficiency, have bazel filter out external targets (and therefore actions) before they even get turned into actions or serialized and sent to us. Note: this is a different mechanism than is used for excluding just external headers.
859-
target_statment = f"filter('^//',{target_statment})"
853+
target_statment = f"filter('^(//|@//)',{target_statment})"
860854
aquery_args = [
861855
'bazel',
862856
'aquery',

0 commit comments

Comments
 (0)