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"""cc_test implementation for the Android environment.""" 18 19def _cc_test_impl(ctx): 20 # Emit the launcher script. 21 script = ctx.actions.declare_file("%s.sh" % ctx.label.name) 22 ctx.actions.expand_template( 23 template = ctx.file._template, 24 output = script, 25 substitutions = {{ 26 "{{module_name}}": ctx.label.name, 27 "{{module_path}}": ctx.label.package, 28 "{{tradefed_launcher_module_path}}": ctx.attr._tradefed_launcher.label.package, 29 "{{tradefed_jars_module_path}}": ctx.attr._tradefed_jars.label.package, 30 "{{adb_path}}": ctx.attr._adb.label.package, 31 "{{launcher_path}}": "{{}}/{{}}".format( 32 ctx.attr._launcher.label.package, 33 ctx.attr._launcher.label.name, 34 ), 35 }}, 36 is_executable = True, 37 ) 38 39 # Pass the deps on as runfiles as Tradefed will scan the resulting 40 # directory for tests. 41 runfiles = ctx.runfiles( 42 files = ctx.files._launcher, 43 transitive_files = depset( 44 transitive = [ 45 depset(ctx.files.deps), 46 depset(ctx.files._adb), 47 depset(ctx.files._tradefed_launcher), 48 depset(ctx.files._tradefed_script_help), 49 depset(ctx.files._tradefed_jars), 50 ], 51 ), 52 ) 53 54 return [DefaultInfo(executable = script, runfiles = runfiles)] 55 56cc_test = rule( 57 _cc_test_impl, 58 attrs = {{ 59 "_adb": attr.label( 60 default = Label("//packages/modules/adb"), 61 allow_single_file = True, 62 ), 63 "_tradefed_launcher": attr.label( 64 default = Label("//tools/tradefederation/core:atest_tradefed"), 65 allow_single_file = True, 66 ), 67 "_tradefed_script_help": attr.label( 68 default = Label("//tools/tradefederation/core:script_help"), 69 ), 70 "_tradefed_jars": attr.label( 71 default = Label("//tools/tradefederation/core:tradefed_lib"), 72 ), 73 "_template": attr.label( 74 default = Label( 75 "//build/bazel/rules:tf_test_executable.sh.template", 76 ), 77 allow_single_file = True, 78 ), 79 "_launcher": attr.label(default = Label("//build/bazel/rules:cc_tf_test_launcher")), 80 "deps": attr.label_list(allow_files = True), 81 }}, 82 executable = True, 83 test = True, 84) 85