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
Copy file name to clipboardExpand all lines: refresh_compile_commands.bzl
+121-43
Original file line number
Diff line number
Diff line change
@@ -37,12 +37,27 @@ refresh_compile_commands(
37
37
# However, if you use clangd and are looking for speed, we strongly recommend you follow the instructions below instead, since clangd is going to regularly infer the wrong commands for headers and give you lots of annoyingly unnecessary red squigglies.
38
38
39
39
# Need to create separate files for specific targets? Give those targets a name and their compile commands file will be written into a subdirectory with that name.
40
-
# target_file_names = {
41
-
# "//:host_build": "host",
42
-
# "//:target_build": "target",
40
+
# target_collections = {
41
+
# "host": "//:host_build",
42
+
# "target": "//:target_build",
43
43
# }
44
44
45
-
# Need to write compile commands to some directory other than the workspace root? Provide a path relative to the workspace root.
45
+
# You can define target collections, sort of like "meta-targets" that contain combination of compile commands from the specified targets.
46
+
# This is useful for multi-architecture projects, where you might be building the same files in multiple different ways depending on what architecture or device the code will run on.
47
+
# It only makes sense to get code intelligence for a consistent build, so you can produce consistent compile commands with target collections.
48
+
# Targets only need to be specified in either `targets` or `target_collections`; there's no need to add them to both.
# Need to write compile commands to some directory other than the workspace root? Provide a path relative to the workspace root. This is useful if you use target collections.
46
61
# out_dir = ".compile_commands"
47
62
48
63
# Need things to run faster? [Either for compile_commands.json generation or clangd indexing.]
**kwargs): # For the other common attributes. Tags, compatible_with, etc. https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes.
# ... we want to produce a `string_dict_list` that we can pass into the Python script template to assemble the `target_flag_pairs`.
137
+
# A simple dict with target name keys isn't adequate, because we can specify a target more than once with different build flags (see the last example above).
138
+
# So we assemble a dict where the keys are unique to each target+flag combination, and the values are a list of strings in this format: [<target>, <flags>]
139
+
#
140
+
# That takes care of the `target_flag_pairs`, which determines which targets to generate compile commands for.
141
+
#
142
+
# Associating compile commands with target collections is easier; we pass `target_collections`, but with the target names and flags concatenated in the same way
143
+
# as described above. This lets us associate each target+flag combination we generate compile commands for with its membership(s) in target collections.
144
+
145
+
target_collection_targets_list= []
146
+
serialized_target_collections= {}
99
147
148
+
iftarget_collections:
149
+
# Convert the targets specified in `target_collections` into the format we'll use with `targets`, so we can combine them into one list of targets to generate compile commands for.
# Targets may appear in multiple collections. We don't want duplicates in the final list, but Starlark doesn't have Python's set class. So we de-duplicate manually.
# Convert the various, acceptable target shorthands into the dictionary format
103
185
# 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.
104
-
ifnottargetsandlen(target_collection_targets) ==0: # Default to all targets in main workspace
105
-
targets= {"@//...": ""}
106
-
ifnottargets: # In this case, targets were defined only in `target_collections`
# Pass select() to _expand_template to make it work
110
192
# see https://bazel.build/docs/configurable-attributes#faq-select-macro
111
193
pass
112
194
eliftype(targets) =="list": # Allow specifying a list of targets w/o arguments
113
-
# The reason we want the list of target collection targets is that if you specify a target in `target_collections`, you don't have to redundantly specify it in `targets`, *unless* you want to specify build flags too.
114
-
# So we want to cull the list of target collection targets down to only those that *aren't* specified in `targets`.
" {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
0 commit comments