1#!/usr/bin/env bash 2 3# Copyright (C) 2022 The Android Open Source Project 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# http://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 17# A simple script for running the Atest workspace generation script in a 18# contained environment. 19 20function check_env_var() 21{ 22 if [ ! -n "${!1}" ] ; then 23 echo "Necessary environment variable ${1} missing, did you forget to lunch?" 24 exit 1 25 fi 26} 27 28# Save the location of this script for later. 29SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) 30 31# Check for necessary environment variables. 32check_env_var "ANDROID_BUILD_TOP" 33check_env_var "TARGET_PRODUCT" 34check_env_var "TARGET_BUILD_VARIANT" 35 36OUT_DIR=$(mktemp -d) 37trap "rm -rf $OUT_DIR" EXIT 38 39# The dist directory is not usually present on clean local machines so create it 40# here. 41mkdir $OUT_DIR/dist 42 43${ANDROID_BUILD_TOP}/prebuilts/build-tools/linux-x86/bin/nsjail \ 44 -H android-build \ 45 -E TARGET_PRODUCT=${TARGET_PRODUCT} \ 46 -E DIST_DIR=${OUT_DIR}/dist \ 47 -E TARGET_BUILD_VARIANT=${TARGET_BUILD_VARIANT} \ 48 -E OUT_DIR=${OUT_DIR} \ 49 -E ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP} \ 50 -E HOME=${HOME} \ 51 -u nobody \ 52 -g $(id -g) \ 53 -R / \ 54 -B /tmp \ 55 -B $OUT_DIR \ 56 -B $PWD \ 57 --disable_clone_newcgroup \ 58 --cwd $ANDROID_BUILD_TOP \ 59 -t 0 \ 60 --proc_rw \ 61 --rlimit_as soft \ 62 --rlimit_core soft \ 63 --rlimit_cpu soft \ 64 --rlimit_fsize soft \ 65 --rlimit_nofile soft \ 66 -q \ 67 -- \ 68 ${SCRIPT_DIR}/gen_workspace_archive.sh 69