diff options
Diffstat (limited to 'experiments/prepare_bazel_test_env/data/templates')
5 files changed, 249 insertions, 0 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 new file mode 100644 index 0000000..6d4ffe3 --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/BUILD.bazel.template @@ -0,0 +1,21 @@ +# 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. + +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 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 new file mode 100644 index 0000000..588f881 --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/cc_test.bzl.template @@ -0,0 +1,84 @@ +# 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. +"""cc_test implementation for the Android environment.""" + +def _cc_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, + "{{adb_path}}": 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)] + +cc_test = rule( + _cc_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:cc_tf_test_launcher")), + "deps": attr.label_list(allow_files = True), + }}, + executable = True, + test = True, +) diff --git a/experiments/prepare_bazel_test_env/data/templates/packages/modules/adb/BUILD.bazel.template b/experiments/prepare_bazel_test_env/data/templates/packages/modules/adb/BUILD.bazel.template new file mode 100644 index 0000000..8952caa --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/packages/modules/adb/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:adb + +package(default_visibility=["//visibility:public"]) + +genrule(name="adb", + srcs=["{prebuilts_dir_name}/host/bin/adb"], + outs=[ + "adb", + ], + cmd="cp -t $(RULEDIR) $<") diff --git a/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/native/BUILD.bazel.template b/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/native/BUILD.bazel.template new file mode 100644 index 0000000..4c7e3e0 --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/native/BUILD.bazel.template @@ -0,0 +1,52 @@ +# 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:hello_world_test + +package(default_visibility=["//visibility:public"]) + +load("//build/bazel/rules:cc_test.bzl", "cc_test") + +_LIB_SRCS = glob([ + "{prebuilts_dir_name}/host/lib/**/*", + "{prebuilts_dir_name}/host/lib64/**/*" +]) +_TESTCASE_SRCS = glob( + ["{prebuilts_dir_name}/host/testcases/hello_world_test/**/*"]) + +_LIB_OUTS = [f.replace("{prebuilts_dir_name}/host/", "") for f in _LIB_SRCS] +_TESTCASE_OUTS = [ + f.replace("{prebuilts_dir_name}/host/testcases/hello_world_test/", "") + for f in _TESTCASE_SRCS +] + +genrule(name="hello_world_test_prebuilt", + srcs=_LIB_SRCS + _TESTCASE_SRCS, + outs=_LIB_OUTS + _TESTCASE_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 + """) + +cc_test(name="hello_world_test", deps=[":hello_world_test_prebuilt"]) diff --git a/experiments/prepare_bazel_test_env/data/templates/tools/tradefederation/core/BUILD.bazel.template b/experiments/prepare_bazel_test_env/data/templates/tools/tradefederation/core/BUILD.bazel.template new file mode 100644 index 0000000..3493ba6 --- /dev/null +++ b/experiments/prepare_bazel_test_env/data/templates/tools/tradefederation/core/BUILD.bazel.template @@ -0,0 +1,65 @@ +# 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:tradefed-core +# SOONG_TARGET:atest-tradefed + +package(default_visibility=["//visibility:public"]) + +_TF_JARS = glob(["{prebuilts_dir_name}/host/tradefed/*.jar"]) +_TF_JARNAMES = [ + f.replace("{prebuilts_dir_name}/host/tradefed/", "") for f in _TF_JARS +] + +genrule(name="tradefed_lib_soong_import", + srcs=_TF_JARS, + outs=_TF_JARNAMES, + cmd="cp -t $(RULEDIR) $(SRCS)") + +java_import(name="tradefed_lib", jars=[":tradefed_lib_soong_import"]) + +genrule(name="script_help", + srcs=[ + "{prebuilts_dir_name}/host/bin/script_help.sh", + ], + outs=["script_help.sh"], + cmd="cp -t $(RULEDIR) $<") + +genrule( + name="tradefed", + srcs=[ + ":script_help", + ":tradefed_lib", + "{prebuilts_dir_name}/host/bin/tradefed.sh", + ], + outs=["tradefed.sh"], + cmd= + "cp -t $(RULEDIR) $(location {prebuilts_dir_name}/host/bin/tradefed.sh)", + executable=True, +) + +genrule( + name="atest_tradefed", + srcs=[ + ":script_help", ":tradefed_lib", + "{prebuilts_dir_name}/host/bin/atest_tradefed.sh" + ], + outs=["atest_tradefed.sh"], + cmd= + "cp -t $(RULEDIR) $(location {prebuilts_dir_name}/host/bin/atest_tradefed.sh)", + executable=True, +) |