Files
carbon-lang/toolchain/autoupdate_testdata.py
T
Jon Ross-Perkins b5167b2d69 Implement autoupdate for file_test. (#3043)
I've migrated the toolchain autoupdate scripts here, I just need a
little more time to do the explorer side (which I need to check
performance, that may require multithreading as we do in the current
script). However, this felt substantial enough to share and it means I
can handle autoupdate in more of the toolchain, including preparatory
work for autoupdate on multi-file tests.

Once explorer is done I'll remove the old script.
2023-08-02 21:32:21 +00:00

58 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""Autoupdates testdata in toolchain."""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import argparse
import subprocess
TARGETS = {
"codegen": "//toolchain/codegen:codegen_file_test",
"driver": "//toolchain/driver:driver_file_test",
"lexer": "//toolchain/lexer:lexer_file_test",
"lowering": "//toolchain/lowering:lowering_file_test",
"parser": "//toolchain/parser:parse_tree_file_test",
"semantics": "//toolchain/semantics:semantics_file_test",
}
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"dirs",
# We don't use `choices` because it seems to conflict with "*".
nargs="*",
default=TARGETS.keys(),
help="Optionally restrict directories to update. Defaults to all.",
)
parsed_args = parser.parse_args()
# Deduplicate and validate arguments.
dirs = set(parsed_args.dirs)
invalid_dirs = dirs.difference(TARGETS.keys())
if invalid_dirs:
exit(
f"Invalid dirs: {', '.join(invalid_dirs)}; "
f"allowed dirs are {', '.join(TARGETS.keys())}."
)
# Build the targets together if there's more than one. Otherwise, we may as
# well build and run together.
if len(dirs) > 1:
subprocess.check_call(
["bazel", "build", "-c", "opt"] + [TARGETS[d] for d in dirs]
)
for d in dirs:
subprocess.check_call(
["bazel", "run", "-c", "opt", TARGETS[d], "--", "--autoupdate"]
)
if __name__ == "__main__":
main()