Skip to content

Commit 047daf9

Browse files
committed
Change enable_swift to exclude_swift and default to False
1 parent 968686b commit 047daf9

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

refresh.template.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -917,19 +917,14 @@ def _get_commands(target: str, flags: str):
917917
Try adding them as flags in your refresh_compile_commands rather than targets.
918918
In a moment, Bazel will likely fail to parse.""")
919919

920-
support_mnemonics = ["Objc", "Cpp"]
921-
if {enable_swift}:
922-
support_mnemonics += ["Swift"]
923-
mnemonics_string = '|'.join(support_mnemonics)
924-
925920
# First, query Bazel's C-family compile actions for that configured target
926921
aquery_args = [
927922
'bazel',
928923
'aquery',
929924
# Aquery docs if you need em: https://docs.bazel.build/versions/master/aquery.html
930925
# Aquery output proto reference: https://github.com/bazelbuild/bazel/blob/master/src/main/protobuf/analysis_v2.proto
931926
# One bummer, not described in the docs, is that aquery filters over *all* actions for a given target, rather than just those that would be run by a build to produce a given output. This mostly isn't a problem, but can sometimes surface extra, unnecessary, misconfigured actions. Chris has emailed the authors to discuss and filed an issue so anyone reading this could track it: https://github.com/bazelbuild/bazel/issues/14156.
932-
f"mnemonic('({mnemonics_string})Compile',deps({target}))",
927+
f"mnemonic('(Objc|Cpp{swift_mnemonic_string})Compile',deps({target}))",
933928
# We switched to jsonproto instead of proto because of https://github.com/bazelbuild/bazel/issues/13404. We could change back when fixed--reverting most of the commit that added this line and tweaking the build file to depend on the target in that issue. That said, it's kinda nice to be free of the dependency, unless (OPTIMNOTE) jsonproto becomes a performance bottleneck compated to binary protos.
934929
'--output=jsonproto',
935930
# We'll disable artifact output for efficiency, since it's large and we don't use them. Small win timewise, but dramatically less json output from aquery.

refresh_compile_commands.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def refresh_compile_commands(
6363
targets = None,
6464
exclude_headers = None,
6565
exclude_external_sources = False,
66-
enable_swift = False,
66+
exclude_swift = False,
6767
**kwargs): # For the other common attributes. Tags, compatible_with, etc. https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes.
6868
# Convert the various, acceptable target shorthands into the dictionary format
6969
# In Python, `type(x) == y` is an antipattern, but [Starlark doesn't support inheritance](https://bazel.build/rules/language), so `isinstance` doesn't exist, and this is the correct way to switch on type.
@@ -80,7 +80,7 @@ def refresh_compile_commands(
8080

8181
# Generate runnable python script from template
8282
script_name = name + ".py"
83-
_expand_template(name = script_name, labels_to_flags = targets, exclude_headers = exclude_headers, exclude_external_sources = exclude_external_sources, enable_swift = enable_swift, **kwargs)
83+
_expand_template(name = script_name, labels_to_flags = targets, exclude_headers = exclude_headers, exclude_external_sources = exclude_external_sources, exclude_swift = exclude_swift, **kwargs)
8484
native.py_binary(name = name, srcs = [script_name], **kwargs)
8585

8686
def _expand_template_impl(ctx):
@@ -96,7 +96,7 @@ def _expand_template_impl(ctx):
9696
" {windows_default_include_paths}": "\n".join([" %r," % path for path in find_cpp_toolchain(ctx).built_in_include_directories]), # find_cpp_toolchain is from https://docs.bazel.build/versions/main/integrating-with-rules-cc.html
9797
"{exclude_headers}": '"' + str(ctx.attr.exclude_headers) + '"',
9898
"{exclude_external_sources}": str(ctx.attr.exclude_external_sources),
99-
"{enable_swift}": str(ctx.attr.enable_swift),
99+
"{swift_mnemonic_string}": ("" if ctx.attr.exclude_swift else "|Swift") # Note there is a '|' before Swift
100100
},
101101
)
102102
return DefaultInfo(files = depset([script]))
@@ -106,7 +106,7 @@ _expand_template = rule(
106106
"labels_to_flags": attr.string_dict(mandatory = True), # string keys instead of label_keyed because Bazel doesn't support parsing wildcard target patterns (..., *, :all) in BUILD attributes.
107107
"exclude_external_sources": attr.bool(default = False),
108108
"exclude_headers": attr.string(values = ["all", "external", ""]), # "" needed only for compatibility with Bazel < 3.6.0
109-
"enable_swift": attr.bool(default = False),
109+
"exclude_swift": attr.bool(default = False),
110110
"_script_template": attr.label(allow_single_file = True, default = "refresh.template.py"),
111111
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"), # For Windows INCLUDE. If this were eliminated, for example by the resolution of https://github.com/clangd/clangd/issues/123, we'd be able to just use a macro and skylib's expand_template rule: https://github.com/bazelbuild/bazel-skylib/pull/330
112112
},

0 commit comments

Comments
 (0)