• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright {year}, The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# WARNING: This BUILD file was generated by a tool.
16# It should not be manually modified.
17"""java_test implementation for the Android environment."""
18
19
20def _java_test_impl(ctx):
21    # Emit the launcher script.
22    script = ctx.actions.declare_file("%s.sh" % ctx.label.name)
23    ctx.actions.expand_template(
24        template=ctx.file._template,
25        output=script,
26        substitutions={{
27            "{{module_name}}":
28            ctx.label.name,
29            "{{module_path}}":
30            ctx.label.package,
31            "{{tradefed_launcher_module_path}}":
32            ctx.attr._tradefed_launcher.label.package,
33            "{{tradefed_jars_module_path}}":
34            ctx.attr._tradefed_jars.label.package,
35            "{{path_additions}}":
36            ctx.attr._adb.label.package,
37            "{{launcher_path}}":
38            "{{}}/{{}}".format(
39                ctx.attr._launcher.label.package,
40                ctx.attr._launcher.label.name,
41            ),
42        }},
43        is_executable=True,
44    )
45
46    # Pass the deps on as runfiles as Tradefed will scan the resulting
47    # directory for tests.
48    runfiles = ctx.runfiles(
49        files=ctx.files._launcher,
50        transitive_files=depset(transitive=[
51            depset(ctx.files.deps),
52            depset(ctx.files._adb),
53            depset(ctx.files._tradefed_launcher),
54            depset(ctx.files._tradefed_script_help),
55            depset(ctx.files._tradefed_jars),
56        ], ),
57    )
58
59    return [DefaultInfo(executable=script, runfiles=runfiles)]
60
61
62java_test = rule(
63    _java_test_impl,
64    attrs={{
65        "_adb":
66        attr.label(
67            default=Label("//packages/modules/adb"),
68            allow_single_file=True,
69        ),
70        "_tradefed_launcher":
71        attr.label(
72            default=Label("//tools/tradefederation/core:atest_tradefed"),
73            allow_single_file=True,
74        ),
75        "_tradefed_script_help":
76        attr.label(
77            default=Label("//tools/tradefederation/core:atest_script_help"), ),
78        "_tradefed_jars":
79        attr.label(
80            default=Label("//tools/tradefederation/core:tradefed_lib"), ),
81        "_template":
82        attr.label(
83            default=Label(
84                "//build/bazel/rules:tf_test_executable.sh.template", ),
85            allow_single_file=True,
86        ),
87        "_launcher":
88        attr.label(default=Label("//build/bazel/rules:java_tf_test_launcher")),
89        "deps":
90        attr.label_list(allow_files=True),
91    }},
92    executable=True,
93    test=True,
94)
95