• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2022 The Bazel 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
16set -e
17set -x
18
19source "${KOKORO_GFILE_DIR}/download_bazel.sh"
20echo "== installing bazel ========================================="
21bazel_install_dir=$(mktemp -d)
22BAZEL_VERSION="latest-with-prereleases"
23DownloadBazel "$BAZEL_VERSION" linux x86_64 "$bazel_install_dir"
24bazel="$bazel_install_dir/install/bin/bazel"
25chmod +x "$bazel"
26bazel_detected_version=$("$bazel" version | grep "Build label" | awk -F": " '{print $2}')
27echo "============================================================="
28
29function Cleanup() {
30  # Clean up all temporary directories: bazel install, sandbox, and
31  # android_tools.
32  rm -rf "$bazel_install_dir"
33}
34trap Cleanup EXIT
35
36# Kokoro is no longer updating toolchains in their images, so install newer
37# android build tools, because the latest one installed (26.0.2) has some bug
38# in APPT2 which causes the magic number to be incorrect for some files it
39# outputs.
40#
41# Use "yes" to accept sdk licenses.
42cd "$ANDROID_HOME"
43yes | tools/bin/sdkmanager --install "build-tools;30.0.3" &>/dev/null
44yes | tools/bin/sdkmanager --licenses &>/dev/null
45
46# ANDROID_HOME is already in the environment.
47export ANDROID_NDK_HOME="/opt/android-ndk-r16b"
48
49# Create a tmpfs in the sandbox at "/tmp/hsperfdata_$USERNAME" to avoid the
50# problems described in https://github.com/bazelbuild/bazel/issues/3236
51# Basically, the JVM creates a file at /tmp/hsperfdata_$USERNAME/$PID, but
52# processes all get a PID of 2 in the sandbox, so concurrent Java build actions
53# could crash because they're trying to modify the same file. So, tell the
54# sandbox to mount a tmpfs at /tmp/hsperfdata_$(whoami) so that each JVM gets
55# its own version of that directory.
56hsperfdata_dir="/tmp/hsperfdata_$(whoami)_rules_android"
57mkdir "$hsperfdata_dir"
58
59COMMON_ARGS=(
60  "--sandbox_tmpfs_path=$hsperfdata_dir"
61  "--verbose_failures"
62  "--experimental_google_legacy_api"
63  "--experimental_enable_android_migration_apis"
64)
65
66# Go to rules_android workspace and run relevant tests.
67cd "${KOKORO_ARTIFACTS_DIR}/git/rules_android"
68"$bazel" test "${COMMON_ARGS[@]}" //src/common/golang/... \
69  //src/tools/ak/{bucketize,compile,dex,extractaar,finalrjar,generatemanifest,link,liteparse,manifest,mindex,nativelib,res,rjar}/...
70
71# Go to basic app workspace in the source tree
72cd "${KOKORO_ARTIFACTS_DIR}/git/rules_android/examples/basicapp"
73"$bazel" build "${COMMON_ARGS[@]}" //java/com/basicapp:basic_app
74
75