Adds help and alsologtostderr flags to comp database generation script (#4869)

Adds `--help` and `--alsologtostderr`, latter as a boolean switch. Error
message was being sent to `/dev/null` by default, this allows it to
print to stderr. Helps in debugging why the script may be failing.

Tested by running
1. `./scripts/create_compdb.py`. This is the baseline (trunk). Can fail
or succeed. Not evaluated.
2. `./scripts/create_compdb.py --help`. Prints help. Expected.
3. `./scripts/create_compdb.py --also`. Fails. Expected because of
disabled abbreviations.
4. `./scripts/create_compdb.py --alsologtostderr`. Correctly printed
error logs. Expected.
This commit is contained in:
Samiur Khan
2025-02-05 01:28:14 +00:00
committed by GitHub
parent c94d40748f
commit a7de3b81c3
+18 -3
View File
@@ -23,12 +23,13 @@ Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import argparse
import subprocess
import scripts_utils
def _build_generated_files(bazel: str) -> None:
def _build_generated_files(bazel: str, logtostderr: bool) -> None:
print("Building the generated files so that tools can find them...")
# Collect the generated file labels. Include some rules which generate
@@ -41,9 +42,12 @@ def _build_generated_files(bazel: str) -> None:
' kind("generated file", deps(//... except //utils/tree_sitter/...))'
")"
)
log_to = None
if not logtostderr:
log_to = subprocess.DEVNULL
generated_file_labels = subprocess.check_output(
[bazel, "query", "--keep_going", "--output=label", kinds_query],
stderr=subprocess.DEVNULL,
stderr=log_to,
encoding="utf-8",
).splitlines()
print(f"Found {len(generated_file_labels)} generated files...")
@@ -57,10 +61,21 @@ def _build_generated_files(bazel: str) -> None:
def main() -> None:
parser = argparse.ArgumentParser(
description=__doc__,
allow_abbrev=False,
)
parser.add_argument(
"--alsologtostderr",
action="store_true",
help="Prints subcommand errors to stderr (default: False)",
)
args = parser.parse_args()
scripts_utils.chdir_repo_root()
bazel = scripts_utils.locate_bazel()
_build_generated_files(bazel)
_build_generated_files(bazel, args.alsologtostderr)
print("Generating compile_commands.json (may take a few minutes)...")
subprocess.run([bazel, "run", "@hedron_compile_commands//:refresh_all"])