lit.bzl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. """Rule for a lit test."""
  5. def glob_lit_tests(driver, data, test_file_exts, **kwargs):
  6. """Runs `lit` on test_dir.
  7. `lit` reference:
  8. https://llvm.org/docs/CommandGuide/lit.html
  9. Args:
  10. driver: The path to the lit config.
  11. data: A list of tools to provide to the tests. These will be aliased for
  12. execution.
  13. test_file_exts: A list of extensions to use for tests.
  14. **kwargs: Any additional parameters for the generated py_test.
  15. """
  16. test_files = native.glob(
  17. ["**"],
  18. exclude_directories = 1,
  19. )
  20. data.append("@llvm-project//llvm:lit")
  21. for f in test_files:
  22. if f.split(".")[-1] not in test_file_exts:
  23. continue
  24. native.py_test(
  25. name = "%s.test" % f,
  26. srcs = ["//bazel/testing:lit_test.py"],
  27. main = "//bazel/testing:lit_test.py",
  28. data = data + [driver, f],
  29. args = ["--package_name=%s" % native.package_name(), "--"],
  30. **kwargs
  31. )