You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assertsource_file.endswith(_get_files.source_extensions), f"Source file candidate, {source_file}, seems to be wrong.\nSelected from {compile_action.arguments}.\nPlease file an issue with this information!"
578
595
579
596
# Warn gently about missing files
580
-
ifnotos.path.isfile(source_file):
581
-
ifnot_get_files.has_logged_missing_file_error: # Just log once; subsequent messages wouldn't add anything.
582
-
_get_files.has_logged_missing_file_error=True
583
-
log_warning(f""">>> A source file you compile doesn't (yet) exist: {source_file}
584
-
It's probably a generated file, and you haven't yet run a build to generate it.
585
-
That's OK; your code doesn't even have to compile for this tool to work.
586
-
If you can, though, you might want to run a build of your code.
587
-
That way everything is generated, browsable and indexed for autocomplete.
588
-
However, if you have *already* built your code, and generated the missing file...
589
-
Please make sure you're supplying this tool with the same flags you use to build.
590
-
You can either use a refresh_compile_commands rule or the special -- syntax. Please see the README.
591
-
[Supplying flags normally won't work. That just causes this tool to be built with those flags.]
592
-
Continuing gracefully...""")
597
+
ifnot_warn_if_file_doesnt_exist(source_file):
593
598
return {source_file}, set()
594
599
595
600
# Note: We need to apply commands to headers and sources.
"""De-Bazel the command into something clangd can parse.
690
723
691
724
This function has fixes specific to Apple platforms, but you should call it on all platforms. It'll determine whether the fixes should be applied or not.
# Bazel wraps the compiler as `external/local_config_cc/wrapped_clang` and exports that wrapped compiler in the proto. However, we need a clang call that clangd can introspect. (See notes in "how clangd uses compile_commands.json" in ImplementationReadme.md for more.)
731
+
# Bazel wrapps the swiftc as `external/build_bazel_rules_swift/tools/worker/worker swiftc ` and worker has been removed in apple_swift_patch
698
732
# Removing the wrapper is also important because Bazel's Xcode (but not CommandLineTools) wrapper crashes if you don't specify particular environment variables (replaced below). We'd need the wrapper to be invokable by clangd's --query-driver if we didn't remove the wrapper.
699
-
compile_args[0] ='clang'
733
+
734
+
ifcompile_args[0].endswith('swiftc'):
735
+
compile_args[0] ='swiftc'
736
+
else:
737
+
compile_args[0] ='clang'
700
738
701
739
# We have to manually substitute out Bazel's macros so clang can parse the command
702
740
# Code this mirrors is in https://github.com/bazelbuild/bazel/blob/master/tools/osx/crosstool/wrapped_clang.cc
assertcompile_action.mnemonicincompile_action.mnemonic, f"Expecting mnemonic is one of (Objc|Cpp|Swift)Compile. Found mnemonic {compile_action.mnemonic}, target {compile_action}"
max_workers=min(32, (os.cpu_count() or1) +4) # Backport. Default in MIN_PY=3.8. See "using very large resources implicitly on many-core machines" in https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor
Try adding them as flags in your refresh_compile_commands rather than targets.
846
918
In a moment, Bazel will likely fail to parse.""")
847
919
920
+
support_mnemonics= ["Objc", "Cpp"]
921
+
if {enable_swift}:
922
+
support_mnemonics+= ["Swift"]
923
+
mnemonics_string='|'.join(support_mnemonics)
924
+
848
925
# First, query Bazel's C-family compile actions for that configured target
849
926
aquery_args= [
850
927
'bazel',
851
928
'aquery',
852
929
# Aquery docs if you need em: https://docs.bazel.build/versions/master/aquery.html
853
930
# Aquery output proto reference: https://github.com/bazelbuild/bazel/blob/master/src/main/protobuf/analysis_v2.proto
854
931
# 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.
# 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.
857
934
'--output=jsonproto',
858
935
# 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.
Copy file name to clipboardExpand all lines: refresh_compile_commands.bzl
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,7 @@ def refresh_compile_commands(
63
63
targets=None,
64
64
exclude_headers=None,
65
65
exclude_external_sources=False,
66
+
enable_swift=False,
66
67
**kwargs): # For the other common attributes. Tags, compatible_with, etc. https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes.
67
68
# Convert the various, acceptable target shorthands into the dictionary format
68
69
# 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.
" {windows_default_include_paths}": "\n".join([" %r,"%pathforpathinfind_cpp_toolchain(ctx).built_in_include_directories]), # find_cpp_toolchain is from https://docs.bazel.build/versions/main/integrating-with-rules-cc.html
"_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
0 commit comments