Skip to content

Commit 00ee693

Browse files
chandlercdanakj
andauthored
Teach create_compdb.py to propagate Bazel flags (#6406)
For example, when developing against a checkout of LLVM, it is useful to be able to consistently pass an override flag to Bazel for that repository. This lets: ```console bazel test --override_repository=+_repo_rules+llvm-raw=$HOME/src/llvm/llvm-project //toolchain/... ``` and ```console ./scripts/create_compdb.py --extra-bazel-flag=--override_repository=+_repo_rules+llvm-raw=$HOME/src/llvm/llvm-project ``` Share the same Bazel cache and use the same flags. --------- Co-authored-by: Dana Jansens <[email protected]>
1 parent 844c136 commit 00ee693

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

scripts/create_compdb.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333

3434

3535
def _build_generated_files(
36-
bazel: str, logtostderr: bool, dump_files: bool
36+
bazel: str,
37+
logtostderr: bool,
38+
dump_files: bool,
39+
extra_bazel_flags: list[str] = [],
3740
) -> None:
3841
print("Building the generated files so that tools can find them...")
3942

@@ -52,7 +55,9 @@ def _build_generated_files(
5255
if not logtostderr:
5356
log_to = subprocess.DEVNULL
5457
generated_file_labels = subprocess.check_output(
55-
[bazel, "query", "--keep_going", "--output=label", kinds_query],
58+
[bazel, "query"]
59+
+ extra_bazel_flags
60+
+ ["--keep_going", "--output=label", kinds_query],
5661
stderr=log_to,
5762
encoding="utf-8",
5863
).splitlines()
@@ -66,7 +71,9 @@ def _build_generated_files(
6671
# fail in case there are build errors in the client, and just warn the user
6772
# that they may be missing generated files.
6873
subprocess.check_call(
69-
[bazel, "build", "--keep_going", "--remote_download_outputs=toplevel"]
74+
[bazel, "build"]
75+
+ extra_bazel_flags
76+
+ ["--keep_going", "--remote_download_outputs=toplevel"]
7077
+ generated_file_labels
7178
# We also need the Bazel C++ runfiles that aren't "generated", but are
7279
# not linked into place until built.
@@ -143,12 +150,23 @@ def main() -> None:
143150
action="store_true",
144151
help="Dumps the full list of generated files (default: False)",
145152
)
153+
parser.add_argument(
154+
"--extra-bazel-flag",
155+
action="append",
156+
default=[],
157+
help=(
158+
"Extra flag to pass to Bazel invocations, may be specified more "
159+
"than once"
160+
),
161+
)
146162

147163
args = parser.parse_args()
148164
scripts_utils.chdir_repo_root()
149165
bazel = scripts_utils.locate_bazel()
150166

151-
_build_generated_files(bazel, args.alsologtostderr, args.dump_files)
167+
_build_generated_files(
168+
bazel, args.alsologtostderr, args.dump_files, args.extra_bazel_flag
169+
)
152170

153171
print(
154172
"Generating compile_commands.json (may take a few minutes)...",
@@ -158,8 +176,14 @@ def main() -> None:
158176
[
159177
bazel,
160178
"run",
179+
]
180+
+ args.extra_bazel_flag
181+
+ [
161182
"@hedron_compile_commands//:refresh_all",
162183
"--",
184+
]
185+
+ args.extra_bazel_flag
186+
+ [
163187
"--notool_deps",
164188
]
165189
)

0 commit comments

Comments
 (0)