diff options
author | Karl Shaffer <karlshaffer@google.com> | 2021-05-25 23:24:13 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-05-25 23:24:13 +0000 |
commit | 9f9687d14fb5605f74e0177a1061159374cd4000 (patch) | |
tree | c19ad6e0c9a6700b324f9ee7b2298d3550e7a2be /experiments/prepare_bazel_test_env/data/templates | |
parent | b0a10d13e478f3f6becfe745bec5639927b40811 (diff) | |
parent | 6d5488f48432fc212c2a5b52a27afba7fe7fc7c0 (diff) | |
download | pesto-9f9687d14fb5605f74e0177a1061159374cd4000.tar.gz |
Enables two additonal test targets in Bazel env am: 096df7d42a am: 6d5488f484
Original change: https://android-review.googlesource.com/c/platform/build/pesto/+/1697845
Change-Id: Ifc0c655b78e6246dfc5b4c5afba743114a4d804f
Diffstat (limited to 'experiments/prepare_bazel_test_env/data/templates')
7 files changed, 332 insertions, 2 deletions
diff --git a/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/BUILD.bazel.template b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/BUILD.bazel.template index 6d4ffe3..78de3b9 100644 --- a/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/BUILD.bazel.template +++ b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/BUILD.bazel.template @@ -18,4 +18,6 @@ package(default_visibility=["//visibility:public"]) exports_files(["lunch.bzl", "tf_test_executable.sh.template"]) -sh_binary(name="cc_tf_test_launcher", srcs=["cc_tf_test_launcher.sh"])
\ No newline at end of file +sh_binary(name="android_tf_test_launcher", srcs=["android_tf_test_launcher.sh"]) +sh_binary(name="cc_tf_test_launcher", srcs=["cc_tf_test_launcher.sh"]) +sh_binary(name="java_tf_test_launcher", srcs=["java_tf_test_launcher.sh"])
\ No newline at end of file diff --git a/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/android_test.bzl.template b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/android_test.bzl.template new file mode 100644 index 0000000..458f886 --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/android_test.bzl.template @@ -0,0 +1,105 @@ +# 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. +"""android_test implementation for the Android environment.""" + + +def _android_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}}": + ":".join([ + ctx.attr._adb.label.package, + ctx.attr._aapt.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._aapt), + depset(ctx.files._tradefed_launcher), + depset(ctx.files._tradefed_script_help), + depset(ctx.files._tradefed_jars), + ], ), + ) + + return [DefaultInfo(executable=script, runfiles=runfiles)] + + +android_test = rule( + _android_test_impl, + attrs={{ + "_adb": + attr.label( + default=Label("//packages/modules/adb"), + allow_single_file=True, + ), + "_aapt": + attr.label( + default=Label("//frameworks/base/tools/aapt"), + 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:android_tf_test_launcher")), + "deps": + attr.label_list(allow_files=True), + }}, + executable=True, + test=True, +) diff --git a/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/cc_test.bzl.template b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/cc_test.bzl.template index 588f881..c6f5c46 100644 --- a/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/cc_test.bzl.template +++ b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/cc_test.bzl.template @@ -27,7 +27,7 @@ def _cc_test_impl(ctx): "{{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, - "{{adb_path}}": ctx.attr._adb.label.package, + "{{path_additions}}": ctx.attr._adb.label.package, "{{launcher_path}}": "{{}}/{{}}".format( ctx.attr._launcher.label.package, ctx.attr._launcher.label.name, diff --git a/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/java_test.bzl.template b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/java_test.bzl.template new file mode 100644 index 0000000..dbfb2e3 --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/java_test.bzl.template @@ -0,0 +1,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, +) diff --git a/experiments/prepare_bazel_test_env/data/templates/frameworks/base/tools/aapt/BUILD.bazel.template b/experiments/prepare_bazel_test_env/data/templates/frameworks/base/tools/aapt/BUILD.bazel.template new file mode 100644 index 0000000..70a14fa --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/frameworks/base/tools/aapt/BUILD.bazel.template @@ -0,0 +1,27 @@ +# 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. + +# SOONG_TARGET:aapt + +package(default_visibility=["//visibility:public"]) + +genrule(name="aapt", + srcs=["{prebuilts_dir_name}/host/bin/aapt"], + outs=[ + "aapt", + ], + cmd="cp -t $(RULEDIR) $<") diff --git a/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/instrumentation/BUILD.bazel.template b/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/instrumentation/BUILD.bazel.template new file mode 100644 index 0000000..f5d0064 --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/instrumentation/BUILD.bazel.template @@ -0,0 +1,51 @@ +# 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. + +# SOONG_TARGET:HelloWorldTests + +package(default_visibility=["//visibility:public"]) + +load("//build/bazel/rules:android_test.bzl", "android_test") + +_LIB_SRCS = glob([ + "{prebuilts_dir_name}/host/lib/**/*", + "{prebuilts_dir_name}/host/lib64/**/*" +]) +_TESTCASE_DEVICE_SRCS = glob(["{prebuilts_dir_name}/target_testcases/HelloWorldTests/**/*"]) + +_LIB_OUTS = [f.replace("{prebuilts_dir_name}/host/", "") for f in _LIB_SRCS] +_TESTCASE_DEVICE_OUTS = [ + f.replace("{prebuilts_dir_name}/target_testcases/HelloWorldTests/", "device/") + for f in _TESTCASE_DEVICE_SRCS +] + +genrule(name="HelloWorldTests_prebuilt", + srcs=_LIB_SRCS + _TESTCASE_DEVICE_SRCS, + outs=_LIB_OUTS + _TESTCASE_DEVICE_OUTS, + cmd=""" + src_files=($(SRCS)) + out_files=($(OUTS)) + for i in "$${{!src_files[@]}}" + do + src_file=$${{src_files[$$i]}} + out_file=$${{out_files[$$i]}} + mkdir -p $$(dirname $$src_file) + cp $$src_file $$out_file + done + """) + +android_test(name="HelloWorldTests", deps=[":HelloWorldTests_prebuilt"])
\ No newline at end of file diff --git a/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/jarhosttest/BUILD.bazel.template b/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/jarhosttest/BUILD.bazel.template new file mode 100644 index 0000000..c27e0d5 --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/jarhosttest/BUILD.bazel.template @@ -0,0 +1,51 @@ +# 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. + +# SOONG_TARGET:HelloWorldHostTest + +package(default_visibility=["//visibility:public"]) + +load("//build/bazel/rules:java_test.bzl", "java_test") + +_LIB_SRCS = glob([ + "{prebuilts_dir_name}/host/lib/**/*", + "{prebuilts_dir_name}/host/lib64/**/*" +]) +_TESTCASE_HOST_SRCS = glob(["{prebuilts_dir_name}/host_testcases/HelloWorldHostTest/**/*"]) + +_LIB_OUTS = [f.replace("{prebuilts_dir_name}/host/", "") for f in _LIB_SRCS] +_TESTCASE_HOST_OUTS = [ + f.replace("{prebuilts_dir_name}/host_testcases/HelloWorldHostTest/", "host/") + for f in _TESTCASE_HOST_SRCS +] + +genrule(name="HelloWorldHostTest_prebuilt", + srcs=_LIB_SRCS + _TESTCASE_HOST_SRCS, + outs=_LIB_OUTS + _TESTCASE_HOST_OUTS, + cmd=""" + src_files=($(SRCS)) + out_files=($(OUTS)) + for i in "$${{!src_files[@]}}" + do + src_file=$${{src_files[$$i]}} + out_file=$${{out_files[$$i]}} + mkdir -p $$(dirname $$src_file) + cp $$src_file $$out_file + done + """) + +java_test(name="HelloWorldHostTest", deps=[":HelloWorldHostTest_prebuilt"])
\ No newline at end of file |