Debian Codegraph @

utils/bazel/llvm-project-overlay/llvm/lit_test.bzl

raw
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."""
5
6 load("@bazel_skylib//lib:paths.bzl", "paths")
7
8 def lit_test(
9 name,
10 srcs,
11 args = None,
12 data = None,
13 deps = None,
14 **kwargs):
15 """Runs a single test file with LLVM's lit tool.
16
17 Args:
18 name: string. the name of the generated test target.
19 srcs: label list. The files on which to run lit.
20 args: string list. Additional arguments to pass to lit.
21 Note that `-v` and the 'srcs' paths are added automatically.
22 data: label list. Additional data dependencies of the test.
23 Note that 'srcs' targets are added automatically.
24 **kwargs: additional keyword arguments.
25
26 See https://llvm.org/docs/CommandGuide/lit.html for details on lit.
27 """
28
29 args = args or []
30 data = data or []
31 deps = deps or []
32
33 native.py_test(
34 name = name,
35 srcs = [Label("//llvm:lit")],
36 main = Label("//llvm:utils/lit/lit.py"),
37 args = args + ["-v"] + ["$(execpath %s)" % src for src in srcs],
38 data = data + srcs,
39 legacy_create_init = False,
40 deps = deps + [Label("//llvm:lit")],
41 **kwargs
42 )
43
44 def package_path(label):
45 """Returns the path to the package of 'label'.
46
47 Args:
48 label: label. The label to return the package path of.
49
50 For example, package_path("@foo//bar:BUILD") returns 'external/foo/bar'.
51 """
52 return paths.join(Label(label).workspace_root, Label(label).package)