diff --git a/utils/bazel/llvm-project-overlay/llvm/lit.bzl b/utils/bazel/llvm-project-overlay/llvm/lit.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/llvm/lit.bzl @@ -0,0 +1,76 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Lit runner macros""" + +def glob_lit_tests( + test_file_exts = [], + exclude = [], + data = [], + per_test_extra_data = {}, + default_size = "small", + size_override = {}, + default_tags = [], + tags_override = {}, + **kwargs): + """Creates all plausible Lit tests (and their inputs) in this package. + + Args: + test_file_exts: [str], extensions for files that are tests. + exclude: [str], paths to exclude (for tests and inputs). + data: [str], additional input data to the test. + per_test_extra_data: {str: [str]}, extra data to attach to a given file. + default_size: str, the test size for targets not in "size_override". + size_override: {str: str}, sizes to use for specific tests. + default_tags: [str], additional tags to attach to the test. + tags_override: {str: str}, tags to add to specific tests. + **kwargs: arguments to pass on to lit_test() + """ + + include = ["**/*." + ext for ext in test_file_exts] + for test in native.glob(include, exclude): + lit_test( + name = test, + data = data + per_test_extra_data.get(test, []), + size = size_override.get(test, default_size), + tags = default_tags + tags_override.get(test, []), + **kwargs + ) + +def lit_test( + name, + data = [], + size = "small", + features = [], + driver = None, + **kwargs): + """Runs test files under lit. + + Args: + name: str, the relative path to the file to test. + data: [label], labels that should be provided as data inputs. + size: str, the size of the test. + features: [str], list of extra arguments to pass to lit. + driver: unsupported, must be None. + **kwargs: arguments to pass on to py_test. + """ + if driver: + fail("lit_test() does not currently support a custom driver.") + + native.py_test( + name = name + ".test", + srcs = [Label("//llvm:lit")], + args = [ + "$(location " + name + ")", + ] + features, + data = [ + name, + Label("//llvm:FileCheck"), + Label("//llvm:count"), + Label("//llvm:not"), + ] + data, + size = size, + main = "lit.py", + **kwargs + )