cc_tools_test.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Tests that the C++ toolchain tools can be executed.
  2. This script reads a file containing paths to C++ tools (like clang++, llvm-ar)
  3. and attempts to run each with `--version` to verify they are functional.
  4. """
  5. __copyright__ = """
  6. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  7. Exceptions. See /LICENSE for license information.
  8. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  9. """
  10. import os
  11. import subprocess
  12. import sys
  13. from bazel_tools.tools.python.runfiles import runfiles
  14. def test_tools() -> None:
  15. """Reads paths from file and runs each tool with --version."""
  16. if len(sys.argv) < 2:
  17. print("Usage: cc_tools_test.py <paths_file>")
  18. sys.exit(1)
  19. paths_file = sys.argv[1]
  20. print(f"Reading tools from: {paths_file}")
  21. with open(paths_file, "r") as f:
  22. tools = [line.strip() for line in f if line.strip()]
  23. print(f"Testing tools: {tools}")
  24. r = runfiles.Create()
  25. repo_name = os.environ.get("TEST_WORKSPACE") or "_main"
  26. for tool in tools:
  27. if "bazel-out/" in tool:
  28. _, _, rest = tool.partition("bazel-out/")
  29. _, sep, after = rest.partition("bin/")
  30. if sep:
  31. tool = after
  32. rlocation_path = os.path.join(repo_name, tool)
  33. tool = r.Rlocation(rlocation_path)
  34. print(f"Running {tool} --version")
  35. try:
  36. res = subprocess.run(
  37. [tool, "--version"],
  38. capture_output=True,
  39. text=True,
  40. check=True,
  41. )
  42. print(res.stdout)
  43. except Exception as e:
  44. print(f"Failed to run {tool}: {e}")
  45. sys.exit(1)
  46. if __name__ == "__main__":
  47. test_tools()