xref: /aosp_15_r20/external/tensorflow/tensorflow/tools/ci_build/presubmit/ubuntu_16/android/build.sh (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1#!/bin/bash
2# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15# ==============================================================================
16
17set -e
18
19# Error if we somehow forget to set the path to bazel_wrapper.py
20set -u
21BAZEL_WRAPPER_PATH=$1
22set +u
23
24# From this point on, logs can be publicly available
25set -x
26
27function run_build () {
28  export ANDROID_NDK_HOME="/opt/android-ndk-r19c"
29  export NDK_HOME=$ANDROID_NDK_HOME
30  export ANDROID_SDK_HOME="/opt/android-sdk/current"
31  export ANDROID_API_LEVEL="23"
32  export ANDROID_BUILD_TOOLS_VERSION="30.0.0"
33
34  ANDROID_OUT=android.out
35  ANDROID_OUT_TARGET=gen_android_out
36
37  # Run the presubmit android build.
38  tensorflow/tools/ci_build/builds/android.sh 2>&1 | tee tensorflow/tools/ci_build/builds/${ANDROID_OUT}
39  RC=${PIPESTATUS[0]}
40
41  # Since we are running the build remotely (rbe), we need to build a bazel
42  # target that would output the log generated above and return the expected
43  # error code.
44  cat << EOF > tensorflow/tools/ci_build/builds/BUILD
45package(default_visibility = ["//tensorflow:internal"])
46
47sh_test(
48    name = "${ANDROID_OUT_TARGET}",
49    srcs = ["${ANDROID_OUT_TARGET}.sh"],
50    data = ["${ANDROID_OUT}"],
51    tags = ["local"],
52)
53EOF
54
55  cat << EOF > tensorflow/tools/ci_build/builds/${ANDROID_OUT_TARGET}.sh
56#!/bin/bash
57cat tensorflow/tools/ci_build/builds/${ANDROID_OUT}
58exit ${RC}
59EOF
60
61  # Now trigger the rbe build that outputs the log
62  chmod +x tensorflow/tools/ci_build/builds/${ANDROID_OUT_TARGET}.sh
63
64  # Run bazel test command. Double test timeouts to avoid flakes.
65  # //tensorflow/core/platform:setround_test is not supported. See b/64264700
66  "${BAZEL_WRAPPER_PATH}" \
67    --host_jvm_args=-Dbazel.DigestFunction=SHA256 \
68    test \
69    --test_output=all \
70    tensorflow/tools/ci_build/builds:${ANDROID_OUT_TARGET}
71
72  # Copy log to output to be available to GitHub
73  ls -la "$(bazel info output_base)/java.log"
74  cp "$(bazel info output_base)/java.log" "${KOKORO_ARTIFACTS_DIR}/"
75}
76
77source tensorflow/tools/ci_build/release/common.sh
78install_bazelisk
79which bazel
80
81run_build
82