Debian Codegraph @

llvm-project/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 **kwargs):
14 """Runs a single test file with LLVM's lit tool.
15
16 Args:
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.
24
25 See https://llvm.org/docs/CommandGuide/lit.html for details on lit.
26 """
27
28 args = args or []
29 data = data or []
30
31 native.py_test(
32 name = name,
33 srcs = [Label("//llvm:lit")],
34 main = Label("//llvm:utils/lit/lit.py"),
35 args = args + ["-v"] + ["$(execpath %s)" % src for src in srcs],
36 data = data + srcs,
37 legacy_create_init = False,
38 **kwargs
39 )
40
41 def package_path(label):
42 """Returns the path to the package of 'label'.
43
44 Args:
45 label: label. The label to return the package path of.
46
47 For example, package_path("@foo//bar:BUILD") returns 'external/foo/bar'.
48 """
49 return paths.join(Label(label).workspace_root, Label(label).package)