From 9dd454b3ac30e8bf111f21152b30850bec04c76d Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Thu, 30 Jan 2020 18:17:52 -0800 Subject: [PATCH] Script to set up android build directory Test: manual Change-Id: I93aa3aa9745330ec21385ce12cc586aeaa803e12 --- scripts/setup-android-build.sh | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 scripts/setup-android-build.sh diff --git a/scripts/setup-android-build.sh b/scripts/setup-android-build.sh new file mode 100755 index 000000000..dbb66c3d9 --- /dev/null +++ b/scripts/setup-android-build.sh @@ -0,0 +1,93 @@ +#! /bin/bash +# +# Sets the current directory as Android build output directory for a +# given target by writing the "prefix script" to it. Commands prefixed +# by this script are executed in the Android build environment. E.g., +# running +# ./run +# runs as if we issued +# cd +# mount --bind out +# . build/envsetup.sh +# lunch +# +# exit +# +# This arrangement eliminates the need to issue envsetup/lunch commands +# manually, and allows to run multiple builds from the same shell. +# Thus, if your source tree is in ~/aosp and you are building for +# 'blueline' and 'cuttlefish', issuing +# cd /sdx/blueline && \ +# ~/aosp/build/soong/scripts/setup-android-build.sh aosp_blueline-userdebug +# cd /sdx/cuttlefish && \ +# ~/aosp/build/soong/scripts/setup-android-build.sh aosp_cf_arm64_phone-userdebug +# sets up build directories in /sdx/blueline and /sdx/cuttlefish respectively. +# After that, issue +# /sdx/blueline/run m +# to build blueline image, and issue +# /sdx/cuttlefish atest CtsSecurityBulletinHostTestCases +# to run CTS tests. Notice there is no need to change to a specific directory for that. +# +# Argument: +# * configuration (one of those shown by `lunch` command). +# +set -e +function die() { printf "$@"; exit 1; } + +# Find out where the source tree using the fact that we are in its +# build/ subdirectory. +[[ "$(uname)" == Linux ]] || die "This setup runs only on Linux\n" +declare -r mydir="${0%/*}" +declare -r source="${mydir%/build/soong/scripts}" +[[ "/${mydir}/" =~ '/build/soong/scripts/' ]] || \ + die "$0 should be in build/soong/scripts/ subdirectory of the source tree\n" +[[ ! -e .repo && ! -e .git ]] || \ + die "Current directory looks like source. You should be in the _target_ directory.\n" +# Do not override old run script. +if [[ -x ./run ]]; then + # Set variables from config=xxx and source=xxx comments in the existing script. + . <(sed -nr 's/^# *source=(.*)/oldsource=\1/p;s/^# *config=(.*)/oldconfig=\1/p' run) + die "This directory has been already set up to build Android for %s from %s.\n\ +Remove 'run' file if you want to set it up afresh\n" "$oldconfig" "$oldsource" +fi + +(($#<2)) || die "usage: %s []\n" $0 + +if (($#==1)); then + # Configuration is provided, emit run script. + declare -r config="$1" + declare -r target="$PWD" + cat >./run <