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
Promote multiple --file assert to log_error
Why? It's a usage error we're communicating to the user, not a code invariant we're checking in debug mode.
We could recover, but we don't, because we expect only automated usage and want to give clear feedback.
More pythonic if
Improve my --file flag messaging consistency
Call library to escape regex
Helps avoid edge cases! Also handles the most common special character, '.'
Add an error to catch unsupported --file <file> form
Tweak -- logic now that --file arguments could be after
--file docs
Make aquery spacing consistent
Flip the if statement in constructor target_statment
Use let to combine attr query
Merge compile_commands.json if --file
Small simplification: endswith already can take a tuple of possibilities (as elsewhere)
Small simplification of header path for file flag.
(This code section likely to be replaced later, though.)
Fix my typo on --file= discoverable docs
Some tweaks to merge
Adds note about behavior, some edge case handling around other flags that might start with --file, permissions issues, etc.
Copy file name to clipboardExpand all lines: refresh.template.py
+33-17
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,9 @@
3
3
4
4
Interface (after template expansion):
5
5
- `bazel run` to regenerate compile_commands.json, so autocomplete (and any other clang tooling!) reflect the latest Bazel build files.
6
-
- No arguments are needed; info from the rule baked into the template expansion.
6
+
- No arguments are needed; info from the rule is baked into the template expansion.
7
7
- Any arguments passed are interpreted as arguments needed for the builds being analyzed.
8
+
- The one exception is --file=<file_target>, which can be used to update commands for just one file. This is intended for programmatic use from editor plugins.
8
9
- Requires being run under Bazel so we can access the workspace root environment variable.
9
10
- Output: a compile_commands.json in the workspace root that clang tooling (or you!) can look at to figure out how files are being compiled by Bazel
10
11
- Crucially, this output is de-Bazeled; The result is a command that could be run from the workspace root directly, with no Bazel-specific requirements, environment variables, etc.
# 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.
# For header files we try to find from hdrs and srcs to get the targets
869
+
# Since attr function can't query with full path, get the file name to query
870
+
fname=os.path.basename(file_path)
871
+
target_statment=f"let v = {target_statment} in attr(hdrs, '{fname}', $v) + attr(srcs, '{fname}', $v)"
868
872
aquery_args= [
869
873
'bazel',
870
874
'aquery',
871
875
# Aquery docs if you need em: https://docs.bazel.build/versions/master/aquery.html
872
876
# Aquery output proto reference: https://github.com/bazelbuild/bazel/blob/master/src/main/protobuf/analysis_v2.proto
873
877
# 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.
876
880
'--output=jsonproto',
877
881
# 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
+2
Original file line number
Diff line number
Diff line change
@@ -49,6 +49,8 @@ refresh_compile_commands(
49
49
# exclude_headers = "external",
50
50
# Still not fast enough?
51
51
# Make sure you're specifying just the targets you care about by setting `targets`, above.
52
+
# That's still not enough; I'm working on a huge codebase!
53
+
# This tool supports a fast, incremental mode that can be used to add/update commands as individual files are opened. If you'd be willing to collaborate on writing a simple editor plugin invokes this tool on file open, please write in! (And see --file flag in refresh.template.py)
0 commit comments