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
Try adding them as flags in your refresh_compile_commands rather than targets.
856
856
In a moment, Bazel will likely fail to parse.""")
857
857
858
-
# First, query Bazel's C-family compile actions for that configured target
859
-
target_statment=f'deps({target})'
860
-
if {exclude_external_sources}:
861
-
# 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)"
872
-
aquery_args= [
873
-
'bazel',
874
-
'aquery',
875
-
# Aquery docs if you need em: https://docs.bazel.build/versions/master/aquery.html
876
-
# Aquery output proto reference: https://github.com/bazelbuild/bazel/blob/master/src/main/protobuf/analysis_v2.proto
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.
880
-
'--output=jsonproto',
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.
882
-
'--include_artifacts=false',
883
-
# Shush logging. Just for readability.
884
-
'--ui_event_filters=-info',
885
-
'--noshow_progress',
886
-
# Disable param files, which would obscure compile actions
887
-
# Mostly, people enable param files on Windows to avoid the relatively short command length limit.
888
-
# For more, see compiler_param_file in https://bazel.build/docs/windows
889
-
# They are, however, technically supported on other platforms/compilers.
890
-
# That's all well and good, but param files would prevent us from seeing compile actions before the param files had been generated by compilation.
891
-
# Since clangd has no such length limit, we'll disable param files for our aquery run.
892
-
'--features=-compiler_param_file',
893
-
# Disable layering_check during, because it causes large-scale dependence on generated module map files that prevent header extraction before their generation
894
-
# For more context, see https://github.com/hedronvision/bazel-compile-commands-extractor/issues/83
895
-
# If https://github.com/clangd/clangd/issues/123 is resolved and we're not doing header extraction, we could try removing this, checking that there aren't erroneous red squigglies squigglies before the module maps are generated.
896
-
# If Bazel starts supporting modules (https://github.com/bazelbuild/bazel/issues/4005), we'll probably need to make changes that subsume this.
897
-
'--features=-layering_check',
898
-
] +additional_flags
899
-
900
-
aquery_process=subprocess.run(
901
-
aquery_args,
902
-
capture_output=True,
903
-
encoding=locale.getpreferredencoding(),
904
-
check=False, # We explicitly ignore errors from `bazel aquery` and carry on.
905
-
)
858
+
@enum.unique
859
+
classStage(enum.Enum):
860
+
INIT=0
861
+
FINDED=1
862
+
# For header files we try to find from hdrs and srcs to get the targets
863
+
# Since attr function can't query with full path, get the file name to query
864
+
FIND_HEADER_FROM_ATTRS=2
865
+
# If the header can not found from attrs then we processing query from all inputs which includes
866
+
FIND_HEADER_FROM_INPUTS=3
867
+
# if still not found the query the whole tree
868
+
FIND_HEADER_FROM_WHO_DEPS=4
869
+
870
+
defget_next_stage(self):
871
+
ifself==Stage.FIND_HEADER_FROM_ATTRS:
872
+
returnStage.FIND_HEADER_FROM_INPUTS
873
+
elifself==Stage.FIND_HEADER_FROM_INPUTS:
874
+
returnStage.FIND_HEADER_FROM_WHO_DEPS
875
+
else:
876
+
returnStage.FINDED
877
+
compile_commands= []
878
+
stage=Stage.INIT
879
+
whilestage!=Stage.FINDED:
880
+
# First, query Bazel's C-family compile actions for that configured target
881
+
target_statment=f'deps({target})'
882
+
if {exclude_external_sources}:
883
+
# 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.
# Aquery docs if you need em: https://docs.bazel.build/versions/master/aquery.html
904
+
# Aquery output proto reference: https://github.com/bazelbuild/bazel/blob/master/src/main/protobuf/analysis_v2.proto
905
+
# 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.
908
+
'--output=jsonproto',
909
+
# 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.
910
+
'--include_artifacts=false',
911
+
# Shush logging. Just for readability.
912
+
'--ui_event_filters=-info',
913
+
'--noshow_progress',
914
+
# Disable param files, which would obscure compile actions
915
+
# Mostly, people enable param files on Windows to avoid the relatively short command length limit.
916
+
# For more, see compiler_param_file in https://bazel.build/docs/windows
917
+
# They are, however, technically supported on other platforms/compilers.
918
+
# That's all well and good, but param files would prevent us from seeing compile actions before the param files had been generated by compilation.
919
+
# Since clangd has no such length limit, we'll disable param files for our aquery run.
920
+
'--features=-compiler_param_file',
921
+
# Disable layering_check during, because it causes large-scale dependence on generated module map files that prevent header extraction before their generation
922
+
# For more context, see https://github.com/hedronvision/bazel-compile-commands-extractor/issues/83
923
+
# If https://github.com/clangd/clangd/issues/123 is resolved and we're not doing header extraction, we could try removing this, checking that there aren't erroneous red squigglies squigglies before the module maps are generated.
924
+
# If Bazel starts supporting modules (https://github.com/bazelbuild/bazel/issues/4005), we'll probably need to make changes that subsume this.
925
+
'--features=-layering_check',
926
+
] +additional_flags
927
+
928
+
aquery_process=subprocess.run(
929
+
aquery_args,
930
+
capture_output=True,
931
+
encoding=locale.getpreferredencoding(),
932
+
check=False, # We explicitly ignore errors from `bazel aquery` and carry on.
933
+
)
906
934
907
935
908
-
# Filter aquery error messages to just those the user should care about.
909
-
missing_targets_warning: typing.Pattern[str] =re.compile(r'(\(\d+:\d+:\d+\) )?(\033\[[\d;]+m)?WARNING: (\033\[[\d;]+m)?Targets were missing from graph:') # Regex handles --show_timestamps and --color=yes. Could use "in" if we ever need more flexibility.
910
-
forlineinaquery_process.stderr.splitlines():
911
-
# Shush known warnings about missing graph targets.
912
-
# The missing graph targets are not things we want to introspect anyway.
# Filter aquery error messages to just those the user should care about.
937
+
missing_targets_warning: typing.Pattern[str] =re.compile(r'(\(\d+:\d+:\d+\) )?(\033\[[\d;]+m)?WARNING: (\033\[[\d;]+m)?Targets were missing from graph:') # Regex handles --show_timestamps and --color=yes. Could use "in" if we ever need more flexibility.
938
+
forlineinaquery_process.stderr.splitlines():
939
+
# Shush known warnings about missing graph targets.
940
+
# The missing graph targets are not things we want to introspect anyway.
0 commit comments