1#!/bin/bash 2 3# Copyright 2020 Google LLC 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# https://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17readonly ANDROID_TARGET=$1 18readonly BUILD_DIR=$2 19shift 20shift 21readonly BUILD_COMMAND="$@" 22 23if [[ -z "${ANDROID_TARGET}" ]]; then 24 echo "error: Android target not set" 25 exit 1 26fi 27 28if [[ -z "${BUILD_DIR}" ]]; then 29 echo "error: Build directory not set" 30 exit 1 31fi 32 33if [[ -z "${BUILD_COMMAND}" ]]; then 34 echo "error: Build command not set" 35 exit 1 36fi 37 38# If there is an error, exit right away instead of continuing. For example, 39# lunch could fail. If so, there is no point in continuing the build. 40 41set -e 42 43echo "build_android_target.sh: source build/envsetup.sh" 44source build/envsetup.sh 45echo "build_android_target.sh: lunch $ANDROID_TARGET" 46lunch "$ANDROID_TARGET" 47echo "build_android_target.sh: cd $BUILD_DIR" 48cd "$BUILD_DIR" 49 50# However, the build command itself cannot use set -e. I haven't figured this 51# out yet, but something in the build command causes early exit for some 52# targets. 53 54set +e 55 56echo "build_android_target.sh: $BUILD_COMMAND" 57$BUILD_COMMAND 58BUILD_COMMAND_EXIT_VALUE=$? 59 60# Collect RBE metrics if enabled 61if [[ -n "${USE_RBE}" && -n "${RBE_DIR}" ]]; then 62 echo "build_android_target.sh: $RBE_DIR/dumpstats" 63 $RBE_DIR/dumpstats 64fi 65 66exit $BUILD_COMMAND_EXIT_VALUE 67