summaryrefslogtreecommitdiff
path: root/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/java_test.bzl.template
blob: dbfb2e3d9322c74dd4f1079ee7df0a6a43df9d9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Copyright {year}, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# WARNING: This BUILD file was generated by a tool.
# It should not be manually modified.
"""java_test implementation for the Android environment."""


def _java_test_impl(ctx):
    # Emit the launcher script.
    script = ctx.actions.declare_file("%s.sh" % ctx.label.name)
    ctx.actions.expand_template(
        template=ctx.file._template,
        output=script,
        substitutions={{
            "{{module_name}}":
            ctx.label.name,
            "{{module_path}}":
            ctx.label.package,
            "{{tradefed_launcher_module_path}}":
            ctx.attr._tradefed_launcher.label.package,
            "{{tradefed_jars_module_path}}":
            ctx.attr._tradefed_jars.label.package,
            "{{path_additions}}":
            ctx.attr._adb.label.package,
            "{{launcher_path}}":
            "{{}}/{{}}".format(
                ctx.attr._launcher.label.package,
                ctx.attr._launcher.label.name,
            ),
        }},
        is_executable=True,
    )

    # Pass the deps on as runfiles as Tradefed will scan the resulting
    # directory for tests.
    runfiles = ctx.runfiles(
        files=ctx.files._launcher,
        transitive_files=depset(transitive=[
            depset(ctx.files.deps),
            depset(ctx.files._adb),
            depset(ctx.files._tradefed_launcher),
            depset(ctx.files._tradefed_script_help),
            depset(ctx.files._tradefed_jars),
        ], ),
    )

    return [DefaultInfo(executable=script, runfiles=runfiles)]


java_test = rule(
    _java_test_impl,
    attrs={{
        "_adb":
        attr.label(
            default=Label("//packages/modules/adb"),
            allow_single_file=True,
        ),
        "_tradefed_launcher":
        attr.label(
            default=Label("//tools/tradefederation/core:atest_tradefed"),
            allow_single_file=True,
        ),
        "_tradefed_script_help":
        attr.label(
            default=Label("//tools/tradefederation/core:script_help"), ),
        "_tradefed_jars":
        attr.label(
            default=Label("//tools/tradefederation/core:tradefed_lib"), ),
        "_template":
        attr.label(
            default=Label(
                "//build/bazel/rules:tf_test_executable.sh.template", ),
            allow_single_file=True,
        ),
        "_launcher":
        attr.label(default=Label("//build/bazel/rules:java_tf_test_launcher")),
        "deps":
        attr.label_list(allow_files=True),
    }},
    executable=True,
    test=True,
)