summaryrefslogtreecommitdiff
path: root/experiments
diff options
context:
space:
mode:
authorKarl Shaffer <karlshaffer@google.com>2021-04-15 14:29:03 -0400
committerKarl Shaffer <karlshaffer@google.com>2021-04-29 18:43:54 -0400
commit08adae0bf524c5680a56c7dde07f83b039247408 (patch)
treeebb97a420a6d6fed04fcb00a1ff358f8db00be78 /experiments
parent52534a27035d579346b05f2a42a18d940a640494 (diff)
downloadpesto-08adae0bf524c5680a56c7dde07f83b039247408.tar.gz
Add the script data files
The data/ directory includes the `static` and `templates` directories which is used as the source for the generated Bazel environment. Files placed in the template directory are formatted and staged, and eventually synced to the source tree. Thus, they are stored in the same directory hierarchy as the source tree. Files placed in the static directory are copied into the source tree. Test: N/A Change-Id: I5adb3cd95e3142030287132b6ebc88d21da4f15c
Diffstat (limited to 'experiments')
-rw-r--r--experiments/prepare_bazel_test_env/data/static/build/bazel/rules/cc_tf_test_launcher.sh33
-rw-r--r--experiments/prepare_bazel_test_env/data/static/build/bazel/rules/tf_test_executable.sh.template36
-rw-r--r--experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/BUILD.bazel.template21
-rw-r--r--experiments/prepare_bazel_test_env/data/templates/build/bazel/rules/cc_test.bzl.template84
-rw-r--r--experiments/prepare_bazel_test_env/data/templates/packages/modules/adb/BUILD.bazel.template27
-rw-r--r--experiments/prepare_bazel_test_env/data/templates/platform_testing/tests/example/native/BUILD.bazel.template52
-rw-r--r--experiments/prepare_bazel_test_env/data/templates/tools/tradefederation/core/BUILD.bazel.template65
7 files changed, 318 insertions, 0 deletions
diff --git a/experiments/prepare_bazel_test_env/data/static/build/bazel/rules/cc_tf_test_launcher.sh b/experiments/prepare_bazel_test_env/data/static/build/bazel/rules/cc_tf_test_launcher.sh
new file mode 100644
index 0000000..ffe2850
--- /dev/null
+++ b/experiments/prepare_bazel_test_env/data/static/build/bazel/rules/cc_tf_test_launcher.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+# Launches a native CC test with Tradefed. The script expects the following:
+# 1. adb is present on the path.
+# 2. LD_LIBRARY_PATH is set for any libraries that need to be referenced.
+# 3. script_help.sh is included in the runfiles.
+# 4. TF_JAR_DIR and TF_PATH are set corresponding to the location of the
+# Tradefed JARs and any associated libraries.
+# 5. The Tradefed launch script, test_module (i.e. hello_world_tests),
+# and test_path (i.e. platform_testing/tests/example/native) are provided
+# as the first and second positional arguments respectively.
+
+TRADEFED_LAUNCHER=$1
+shift
+TEST_MODULE=$1
+shift
+TEST_PATH=$1
+shift
+
+exec $TRADEFED_LAUNCHER template/atest_local_min \
+ --template:map test=atest \
+ --tests-dir "$TEST_PATH" \
+ --logcat-on-failure \
+ --no-enable-granular-attempts \
+ --no-early-device-release \
+ --include-filter "$TEST_MODULE" \
+ --skip-loading-config-jar \
+ --log-level-display VERBOSE \
+ --log-level VERBOSE \
+ -n \
+ --prioritize-host-config \
+ --skip-host-arch-check \
+ "$@" \ No newline at end of file
diff --git a/experiments/prepare_bazel_test_env/data/static/build/bazel/rules/tf_test_executable.sh.template b/experiments/prepare_bazel_test_env/data/static/build/bazel/rules/tf_test_executable.sh.template
new file mode 100644
index 0000000..f48e4fa
--- /dev/null
+++ b/experiments/prepare_bazel_test_env/data/static/build/bazel/rules/tf_test_executable.sh.template
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Script that handles set up for test execution in a Bazel environment.
+# This script sets the PATH, LD_LIBRARY_PATH, TF_PATH, and TF_JAR_DIR
+# that the called launcher script uses to execute the test.
+
+BAZEL_BIN_WORK_DIR="$(dirname $0)/$0.runfiles/__main__/"
+
+# Use the directory corresponding to the current module for running, this
+# ensures that when Tradefed scans for tests, only the tests
+# that were included as a dependency to the rule are referenced.
+TESTCASE_RELPATH="{module_path}"
+
+# Ensure that the test is executing from the top of the runfiles dir.
+if [[ -d $BAZEL_BIN_WORK_DIR/$TESTCASE_RELPATH ]]
+then
+ cd $BAZEL_BIN_WORK_DIR || exit 1
+fi
+
+# Verify we can find the Tradefed launch script.
+ATEST_TRADEFED_LAUNCHER="{tradefed_launcher_module_path}/atest_tradefed.sh"
+if ! [[ -f $ATEST_TRADEFED_LAUNCHER ]]
+then
+ echo "ERROR: Cannot find Tradefed launch script" >&2
+ exit 1
+fi
+
+# Set the required variables for the environment.
+export PATH={adb_path}:$PATH
+export LD_LIBRARY_PATH="$TESTCASE_RELPATH/lib:$TESTCASE_RELPATH/lib64:"
+export TF_PATH="{tradefed_deps_module_path}/*"
+export TF_JAR_DIR="{tradefed_deps_module_path}/"
+
+# Call the test launcher, passing the module name and testcase directory
+# and any additional arguments.
+exec {launcher_path} $ATEST_TRADEFED_LAUNCHER "{module_name}" "$TESTCASE_RELPATH" "$@" \ No newline at end of file
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,
+)