1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4 """Rules for running lit tests."""
6 load("@bazel_skylib//lib:paths.bzl", "paths")
14 """Runs a single test file with LLVM's lit tool.
17 name: string. the name of the generated test target.
18 srcs: label list. The files on which to run lit.
19 args: string list. Additional arguments to pass to lit.
20 Note that `-v` and the 'srcs' paths are added automatically.
21 data: label list. Additional data dependencies of the test.
22 Note that 'srcs' targets are added automatically.
23 **kwargs: additional keyword arguments.
25 See https://llvm.org/docs/CommandGuide/lit.html for details on lit.
33 srcs = [Label("//llvm:lit")],
34 main = Label("//llvm:utils/lit/lit.py"),
35 args = args + ["-v"] + ["$(execpath %s)" % src for src in srcs],
37 legacy_create_init = False,
41 def package_path(label):
42 """Returns the path to the package of 'label'.
45 label: label. The label to return the package path of.
47 For example, package_path("@foo//bar:BUILD") returns 'external/foo/bar'.
49 return paths.join(Label(label).workspace_root, Label(label).package)