lit_test.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Runs `lit` for testing."""
  2. __copyright__ = """
  3. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  4. Exceptions. See /LICENSE for license information.
  5. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. """
  7. import argparse
  8. import os
  9. from pathlib import Path
  10. import shutil
  11. import subprocess
  12. def _parse_args():
  13. """Parses command line arguments, returning the result."""
  14. arg_parser = argparse.ArgumentParser(description=__doc__)
  15. arg_parser.add_argument(
  16. "--package_name", help="The directory containing tests to run."
  17. )
  18. arg_parser.add_argument(
  19. "lit_args", nargs="*", help="Arguments to pass through to lit."
  20. )
  21. return arg_parser.parse_args()
  22. def main():
  23. parsed_args = _parse_args()
  24. args = [
  25. str(Path(os.environ["TEST_SRCDIR"]).joinpath("llvm-project/llvm/lit")),
  26. str(Path.cwd().joinpath(parsed_args.package_name)),
  27. "-v",
  28. ]
  29. # Force tests to be explicit about command paths. Some tools are required by
  30. # bazel's py_binary output in order to find python3, so we add these. The
  31. # list of tools may prove to be fragile: if so, we may need to change or
  32. # remove the PATH hiding.
  33. system_tools = Path(os.environ["TEST_TMPDIR"]).joinpath("system_tools")
  34. system_tools.mkdir()
  35. for tool in ("env", "grep", "python3", "sh", "which"):
  36. system_tools.joinpath(tool).symlink_to(shutil.which(tool))
  37. env = os.environ.copy()
  38. env["PATH"] = str(system_tools)
  39. # Run lit.
  40. try:
  41. subprocess.check_call(args=args + parsed_args.lit_args, env=env)
  42. except subprocess.CalledProcessError as e:
  43. # Print without the stack trace.
  44. exit(e)
  45. if __name__ == "__main__":
  46. exit(main())