autoupdate_testdata.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. """Autoupdates testdata in toolchain."""
  3. __copyright__ = """
  4. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  5. Exceptions. See /LICENSE for license information.
  6. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. """
  8. import argparse
  9. import subprocess
  10. TARGETS = {
  11. "codegen": "//toolchain/codegen:codegen_file_test",
  12. "driver": "//toolchain/driver:driver_file_test",
  13. "lexer": "//toolchain/lexer:lexer_file_test",
  14. "lowering": "//toolchain/lowering:lowering_file_test",
  15. "parser": "//toolchain/parser:parse_tree_file_test",
  16. "semantics": "//toolchain/semantics:semantics_file_test",
  17. }
  18. def main() -> None:
  19. parser = argparse.ArgumentParser()
  20. parser.add_argument(
  21. "dirs",
  22. # We don't use `choices` because it seems to conflict with "*".
  23. nargs="*",
  24. default=TARGETS.keys(),
  25. help="Optionally restrict directories to update. Defaults to all.",
  26. )
  27. parsed_args = parser.parse_args()
  28. # Deduplicate and validate arguments.
  29. dirs = set(parsed_args.dirs)
  30. invalid_dirs = dirs.difference(TARGETS.keys())
  31. if invalid_dirs:
  32. exit(
  33. f"Invalid dirs: {', '.join(invalid_dirs)}; "
  34. f"allowed dirs are {', '.join(TARGETS.keys())}."
  35. )
  36. # Build the targets together if there's more than one. Otherwise, we may as
  37. # well build and run together.
  38. if len(dirs) > 1:
  39. subprocess.check_call(
  40. ["bazel", "build", "-c", "opt"] + [TARGETS[d] for d in dirs]
  41. )
  42. for d in dirs:
  43. subprocess.check_call(
  44. ["bazel", "run", "-c", "opt", TARGETS[d], "--", "--autoupdate"]
  45. )
  46. if __name__ == "__main__":
  47. main()