xref: /aosp_15_r20/external/bazelbuild-rules_android/kokoro/presubmit/kokoro_presubmit.sh (revision 9e965d6fece27a77de5377433c2f7e6999b8cc0b)
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
19# Set up the SDK as root to avoid having to deal with user file permissions
20
21# Kokoro is no longer updating toolchains in their images, so install newer
22# android build tools, because the latest one installed (26.0.2) has some bug
23# in APPT2 which causes the magic number to be incorrect for some files it
24# outputs.
25#
26cd "$ANDROID_HOME"
27
28# Use "yes" to accept sdk licenses.
29yes | cmdline-tools/latest/bin/sdkmanager --install "build-tools;30.0.3" "extras;android;m2repository" &>/dev/null
30yes | cmdline-tools/latest/bin/sdkmanager --licenses &>/dev/null
31chmod -R o=rx "$ANDROID_HOME"
32
33# Remainder of this file deals with setting up a non-root build account,
34# and using it to run presubmit
35# User account needs to be able to read $ANDROID_HOME (+r) and traverse directories (+x)
36chmod -R o=rx "$ANDROID_HOME"
37
38# Make the non-root account
39export KOKORO_USER="bazel-builder"
40useradd -m -s /bin/bash "$KOKORO_USER"
41
42# Run presubmit as bazel-builder, and pass ANDROID_HOME and KOKORO_ARTIFACTS_DIR
43# from root user's environment to bazel-builder's environment
44runuser -w ANDROID_HOME,KOKORO_ARTIFACTS_DIR -l "$KOKORO_USER" \
45  -c "bash ${KOKORO_ARTIFACTS_DIR}/git/rules_android/kokoro/presubmit/presubmit_main.sh"