|
@@ -24,7 +24,6 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
import argparse
|
|
|
-import json
|
|
|
|
|
import subprocess
|
|
import subprocess
|
|
|
import sys
|
|
import sys
|
|
|
from typing import Any, Dict
|
|
from typing import Any, Dict
|
|
@@ -78,6 +77,9 @@ def _build_generated_files(
|
|
|
# We also need the Bazel C++ runfiles that aren't "generated", but are
|
|
# We also need the Bazel C++ runfiles that aren't "generated", but are
|
|
|
# not linked into place until built.
|
|
# not linked into place until built.
|
|
|
+ ["@bazel_tools//tools/cpp/runfiles:runfiles"]
|
|
+ ["@bazel_tools//tools/cpp/runfiles:runfiles"]
|
|
|
|
|
+ # Also include any deps that require `_virtual_includes` to be fully
|
|
|
|
|
+ # populated through a special C++ rule.
|
|
|
|
|
+ + ["//scripts:deps_for_clangd_tidy"],
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -97,44 +99,6 @@ def _get_config_for_entry(entry: Dict[str, Any]) -> str:
|
|
|
return str(obj_file.split("/")[1])
|
|
return str(obj_file.split("/")[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _filter_compilation_database(file_path: str) -> None:
|
|
|
|
|
- """Filters out duplicate exec-config entries from the database."""
|
|
|
|
|
- print("Filtering out duplicate exec-configuration entries...")
|
|
|
|
|
- try:
|
|
|
|
|
- with open(file_path, "r") as f:
|
|
|
|
|
- commands = json.load(f)
|
|
|
|
|
- except FileNotFoundError:
|
|
|
|
|
- print(f"Error: The file '{file_path}' was not found.")
|
|
|
|
|
- sys.exit(1)
|
|
|
|
|
- except json.JSONDecodeError:
|
|
|
|
|
- print(f"Error: The file '{file_path}' is not a valid JSON file.")
|
|
|
|
|
- sys.exit(1)
|
|
|
|
|
-
|
|
|
|
|
- # We want to skip compiles that were in the "exec" configuration for tools.
|
|
|
|
|
- # Because we generate compile commands for every bazel cc_* target in the
|
|
|
|
|
- # main configuration, even if only used by tools, their sources should be
|
|
|
|
|
- # covered and the exec configuration would simply be a duplicate.
|
|
|
|
|
- #
|
|
|
|
|
- # Detecting this based on the `-exec-` string in the configuration name of
|
|
|
|
|
- # the directory is a bit of a hack, but even using the `--notool_deps`
|
|
|
|
|
- # argument, Bazel seems to sometimes include this configuration in the query
|
|
|
|
|
- # that produces the compilation database.
|
|
|
|
|
- filtered_commands = [
|
|
|
|
|
- entry
|
|
|
|
|
- for entry in commands
|
|
|
|
|
- if "-exec-" not in _get_config_for_entry(entry)
|
|
|
|
|
- ]
|
|
|
|
|
-
|
|
|
|
|
- with open(file_path, "w") as f:
|
|
|
|
|
- # Use indent=4 for a human-readable, pretty-printed output file
|
|
|
|
|
- json.dump(filtered_commands, f, indent=4)
|
|
|
|
|
- print(
|
|
|
|
|
- "Filtered out "
|
|
|
|
|
- f"{len(commands) - len(filtered_commands)} "
|
|
|
|
|
- "duplicate entries..."
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
def main() -> None:
|
|
def main() -> None:
|
|
|
parser = argparse.ArgumentParser(
|
|
parser = argparse.ArgumentParser(
|
|
|
description=__doc__,
|
|
description=__doc__,
|
|
@@ -179,17 +143,12 @@ def main() -> None:
|
|
|
]
|
|
]
|
|
|
+ args.extra_bazel_flag
|
|
+ args.extra_bazel_flag
|
|
|
+ [
|
|
+ [
|
|
|
- "@hedron_compile_commands//:refresh_all",
|
|
|
|
|
|
|
+ "//:generate_compile_commands",
|
|
|
"--",
|
|
"--",
|
|
|
]
|
|
]
|
|
|
- + args.extra_bazel_flag
|
|
|
|
|
- + [
|
|
|
|
|
- "--notool_deps",
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ + [f"--extra_aquery_arg={arg}" for arg in args.extra_bazel_flag]
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- _filter_compilation_database("compile_commands.json")
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
main()
|
|
main()
|