2019-12-28 13:35:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-09-30 15:51:00 +00:00
|
|
|
# AOSPA build helper script
|
2015-01-27 19:53:08 +00:00
|
|
|
|
|
|
|
# red = errors, cyan = warnings, green = confirmations, blue = informational
|
|
|
|
# plain for generic text, bold for titles, reset flag at each end of line
|
|
|
|
# plain blue should not be used for readability reasons - use plain cyan instead
|
|
|
|
CLR_RST=$(tput sgr0) ## reset flag
|
|
|
|
CLR_RED=$CLR_RST$(tput setaf 1) # red, plain
|
|
|
|
CLR_GRN=$CLR_RST$(tput setaf 2) # green, plain
|
|
|
|
CLR_BLU=$CLR_RST$(tput setaf 4) # blue, plain
|
|
|
|
CLR_CYA=$CLR_RST$(tput setaf 6) # cyan, plain
|
|
|
|
CLR_BLD=$(tput bold) ## bold flag
|
|
|
|
CLR_BLD_RED=$CLR_RST$CLR_BLD$(tput setaf 1) # red, bold
|
|
|
|
CLR_BLD_GRN=$CLR_RST$CLR_BLD$(tput setaf 2) # green, bold
|
|
|
|
CLR_BLD_BLU=$CLR_RST$CLR_BLD$(tput setaf 4) # blue, bold
|
|
|
|
CLR_BLD_CYA=$CLR_RST$CLR_BLD$(tput setaf 6) # cyan, bold
|
|
|
|
|
2020-01-07 10:20:56 +00:00
|
|
|
# Set defaults
|
|
|
|
BUILD_TYPE="userdebug"
|
2013-11-09 21:10:23 +00:00
|
|
|
|
2020-12-18 02:31:59 +00:00
|
|
|
function checkExit () {
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
EXIT_CODE=$?
|
|
|
|
echo "${CLR_BLD_RED}Build failed!${CLR_RST}"
|
|
|
|
echo -e ""
|
|
|
|
exit $EXIT_CODE
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-06-25 18:13:37 +00:00
|
|
|
# Output usage help
|
|
|
|
function showHelpAndExit {
|
2020-01-07 10:20:56 +00:00
|
|
|
echo -e "${CLR_BLD_BLU}Usage: $0 <device> [options]${CLR_RST}"
|
2015-06-25 18:13:37 +00:00
|
|
|
echo -e ""
|
2020-01-07 10:20:56 +00:00
|
|
|
echo -e "${CLR_BLD_BLU}Options:${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -h, --help Display this help message${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -c, --clean Wipe the tree before building${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -i, --installclean Dirty build - Use 'installclean'${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -r, --repo-sync Sync before building${CLR_RST}"
|
2021-09-30 15:51:00 +00:00
|
|
|
echo -e "${CLR_BLD_BLU} -v, --variant AOSPA variant - Can be dev, alpha, beta or release${CLR_RST}"
|
2020-01-07 10:20:56 +00:00
|
|
|
echo -e "${CLR_BLD_BLU} -t, --build-type Specify build type${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -j, --jobs Specify jobs/threads to use${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -m, --module Build a specific module${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -s, --sign-keys Specify path to sign key mappings${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -p, --pwfile Specify path to sign key password file${CLR_RST}"
|
|
|
|
echo -e "${CLR_BLD_BLU} -b, --backup-unsigned Store a copy of unsignied package along with signed${CLR_RST}"
|
2020-04-23 04:32:02 +00:00
|
|
|
echo -e "${CLR_BLD_BLU} -d, --delta Generate a delta ota from the specified target_files zip${CLR_RST}"
|
2020-12-18 02:31:59 +00:00
|
|
|
echo -e "${CLR_BLD_BLU} -z, --imgzip Generate fastboot flashable image zip from signed target_files${CLR_RST}"
|
2015-06-25 18:13:37 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2020-01-07 10:20:56 +00:00
|
|
|
# Setup getopt.
|
2020-12-18 02:31:59 +00:00
|
|
|
long_opts="help,clean,installclean,repo-sync,variant:,build-type:,jobs:,module:,sign-keys:,pwfile:,backup-unsigned,delta:,imgzip"
|
|
|
|
getopt_cmd=$(getopt -o hcirv:t:j:m:s:p:bd:z --long "$long_opts" \
|
2020-01-07 10:20:56 +00:00
|
|
|
-n $(basename $0) -- "$@") || \
|
|
|
|
{ echo -e "${CLR_BLD_RED}\nError: Getopt failed. Extra args\n${CLR_RST}"; showHelpAndExit; exit 1;}
|
|
|
|
|
|
|
|
eval set -- "$getopt_cmd"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help|h|help) showHelpAndExit;;
|
|
|
|
-c|--clean|c|clean) FLAG_CLEAN_BUILD=y;;
|
|
|
|
-i|--installclean|i|installclean) FLAG_INSTALLCLEAN_BUILD=y;;
|
|
|
|
-r|--repo-sync|r|repo-sync) FLAG_SYNC=y;;
|
2021-09-30 15:51:00 +00:00
|
|
|
-v|--variant|v|variant) AOSPA_VARIANT="$2"; shift;;
|
2020-01-07 10:20:56 +00:00
|
|
|
-t|--build-type|t|build-type) BUILD_TYPE="$2"; shift;;
|
|
|
|
-j|--jobs|j|jobs) JOBS="$2"; shift;;
|
|
|
|
-m|--module|m|module) MODULE="$2"; shift;;
|
|
|
|
-s|--sign-keys|s|sign-keys) KEY_MAPPINGS="$2"; shift;;
|
|
|
|
-p|--pwfile|p|pwfile) PWFILE="$2"; shift;;
|
|
|
|
-b|--backup-unsigned|b|backup-unsigned) FLAG_BACKUP_UNSIGNED=y;;
|
2020-04-23 04:32:02 +00:00
|
|
|
-d|--delta|d|delta) DELTA_TARGET_FILES="$2"; shift;;
|
2020-12-18 02:31:59 +00:00
|
|
|
-z|--imgzip|img|imgzip) FLAG_IMG_ZIP=y;;
|
2020-01-07 10:20:56 +00:00
|
|
|
--) shift; break;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
# Mandatory argument
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo -e "${CLR_BLD_RED}Error: No device specified${CLR_RST}"
|
|
|
|
showHelpAndExit
|
|
|
|
fi
|
|
|
|
export DEVICE="$1"; shift
|
|
|
|
|
2014-11-06 08:35:02 +00:00
|
|
|
# Make sure we are running on 64-bit before carrying on with anything
|
|
|
|
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
|
|
|
|
if [ "$ARCH" != "64" ]; then
|
|
|
|
echo -e "${CLR_BLD_RED}error: unsupported arch (expected: 64, found: $ARCH)${CLR_RST}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-01-27 19:53:08 +00:00
|
|
|
# Set up paths
|
|
|
|
cd $(dirname $0)
|
|
|
|
DIR_ROOT=$(pwd)
|
|
|
|
|
|
|
|
# Make sure everything looks sane so far
|
2021-09-30 15:51:00 +00:00
|
|
|
if [ ! -d "$DIR_ROOT/vendor/aospa" ]; then
|
2015-01-27 19:53:08 +00:00
|
|
|
echo -e "${CLR_BLD_RED}error: insane root directory ($DIR_ROOT)${CLR_RST}"
|
|
|
|
exit 1
|
2014-09-30 13:10:05 +00:00
|
|
|
fi
|
2013-11-09 21:10:23 +00:00
|
|
|
|
2021-09-30 15:51:00 +00:00
|
|
|
# Setup AOSPA variant if specified
|
|
|
|
if [ $AOSPA_VARIANT ]; then
|
|
|
|
AOSPA_VARIANT=`echo $AOSPA_VARIANT | tr "[:upper:]" "[:lower:]"`
|
|
|
|
if [ "${AOSPA_VARIANT}" = "release" ]; then
|
|
|
|
export AOSPA_BUILDTYPE=RELEASE
|
|
|
|
elif [ "${AOSPA_VARIANT}" = "alpha" ]; then
|
|
|
|
export AOSPA_BUILDTYPE=ALPHA
|
|
|
|
elif [ "${AOSPA_VARIANT}" = "beta" ]; then
|
|
|
|
export AOSPA_BUILDTYPE=BETA
|
2020-01-07 10:20:56 +00:00
|
|
|
else
|
2021-09-30 15:51:00 +00:00
|
|
|
echo -e "${CLR_BLD_RED} Unknown AOSPA variant - use alpha, beta or release${CLR_RST}"
|
2020-01-07 10:20:56 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Initializationizing!
|
|
|
|
echo -e "${CLR_BLD_BLU}Setting up the environment${CLR_RST}"
|
|
|
|
echo -e ""
|
|
|
|
. build/envsetup.sh
|
|
|
|
echo -e ""
|
|
|
|
|
|
|
|
# Use the thread count specified by user
|
|
|
|
CMD=""
|
|
|
|
if [ $JOBS ]; then
|
2022-02-01 12:52:23 +00:00
|
|
|
CMD+="-j$JOBS"
|
2020-01-07 10:20:56 +00:00
|
|
|
fi
|
|
|
|
|
2015-01-27 19:53:08 +00:00
|
|
|
# Pick the default thread count (allow overrides from the environment)
|
2020-01-07 10:20:56 +00:00
|
|
|
if [ -z "$JOBS" ]; then
|
2015-01-27 19:53:08 +00:00
|
|
|
if [ "$(uname -s)" = 'Darwin' ]; then
|
2020-01-07 10:20:56 +00:00
|
|
|
JOBS=$(sysctl -n machdep.cpu.core_count)
|
2015-01-27 19:53:08 +00:00
|
|
|
else
|
2020-01-07 10:20:56 +00:00
|
|
|
JOBS=$(cat /proc/cpuinfo | grep '^processor' | wc -l)
|
2015-01-27 19:53:08 +00:00
|
|
|
fi
|
2013-11-09 21:10:23 +00:00
|
|
|
fi
|
|
|
|
|
2015-01-27 19:53:08 +00:00
|
|
|
# Grab the build version
|
2021-09-30 15:51:00 +00:00
|
|
|
AOSPA_DISPLAY_VERSION="$(cat $DIR_ROOT/vendor/aospa/target/product/version.mk | grep 'AOSPA_MAJOR_VERSION := *' | sed 's/.*= //') \
|
|
|
|
$(cat $DIR_ROOT/vendor/aospa/target/product/version.mk | grep 'AOSPA_MINOR_VERSION := *' | sed 's/.*= //')"
|
2015-01-27 19:53:08 +00:00
|
|
|
|
|
|
|
# Prep for a clean build, if requested so
|
|
|
|
if [ "$FLAG_CLEAN_BUILD" = 'y' ]; then
|
|
|
|
echo -e "${CLR_BLD_BLU}Cleaning output files left from old builds${CLR_RST}"
|
|
|
|
echo -e ""
|
2022-02-01 12:52:23 +00:00
|
|
|
m clobber "$CMD"
|
2015-01-27 19:53:08 +00:00
|
|
|
fi
|
2013-11-09 21:10:23 +00:00
|
|
|
|
2020-01-07 10:20:56 +00:00
|
|
|
# Prep for a installclean build, if requested so
|
|
|
|
if [ "$FLAG_INSTALLCLEAN_BUILD" = 'y' ]; then
|
|
|
|
echo -e "${CLR_BLD_BLU}Cleaning compiled image files left from old builds${CLR_RST}"
|
2015-01-27 19:53:08 +00:00
|
|
|
echo -e ""
|
2022-02-01 12:52:23 +00:00
|
|
|
m installclean "$CMD"
|
2015-01-27 19:53:08 +00:00
|
|
|
fi
|
2014-01-14 09:23:30 +00:00
|
|
|
|
2020-01-07 10:20:56 +00:00
|
|
|
# Sync up, if asked to
|
|
|
|
if [ "$FLAG_SYNC" = 'y' ]; then
|
|
|
|
echo -e "${CLR_BLD_BLU}Downloading the latest source files${CLR_RST}"
|
2013-11-09 21:10:23 +00:00
|
|
|
echo -e ""
|
2020-01-07 10:20:56 +00:00
|
|
|
repo sync -j"$JOBS" -c --no-clone-bundle --current-branch --no-tags
|
2013-11-09 21:10:23 +00:00
|
|
|
fi
|
|
|
|
|
2015-01-27 19:53:08 +00:00
|
|
|
# Check the starting time (of the real build process)
|
|
|
|
TIME_START=$(date +%s.%N)
|
2013-11-09 21:10:23 +00:00
|
|
|
|
2015-01-27 19:53:08 +00:00
|
|
|
# Friendly logging to tell the user everything is working fine is always nice
|
2021-09-30 15:51:00 +00:00
|
|
|
echo -e "${CLR_BLD_GRN}Building AOSPA $AOSPA_DISPLAY_VERSION for $DEVICE${CLR_RST}"
|
2015-01-27 19:53:08 +00:00
|
|
|
echo -e "${CLR_GRN}Start time: $(date)${CLR_RST}"
|
|
|
|
echo -e ""
|
2013-11-09 21:10:23 +00:00
|
|
|
|
2015-01-27 19:53:08 +00:00
|
|
|
# Lunch-time!
|
|
|
|
echo -e "${CLR_BLD_BLU}Lunching $DEVICE${CLR_RST} ${CLR_CYA}(Including dependencies sync)${CLR_RST}"
|
|
|
|
echo -e ""
|
2021-09-30 15:51:00 +00:00
|
|
|
AOSPA_VERSION=$(lunch "aospa_$DEVICE-$BUILD_TYPE" | grep 'AOSPA_VERSION=*' | sed 's/.*=//')
|
|
|
|
lunch "aospa_$DEVICE-$BUILD_TYPE"
|
2015-01-27 19:53:08 +00:00
|
|
|
echo -e ""
|
|
|
|
|
|
|
|
# Build away!
|
|
|
|
echo -e "${CLR_BLD_BLU}Starting compilation${CLR_RST}"
|
|
|
|
echo -e ""
|
2020-12-22 01:14:25 +00:00
|
|
|
|
|
|
|
# If we aren't in Jenkins, use the engineering tag
|
|
|
|
if [ -z "${BUILD_NUMBER}" ]; then
|
|
|
|
export FILE_NAME_TAG=eng.$USER
|
|
|
|
else
|
|
|
|
export FILE_NAME_TAG=$BUILD_NUMBER
|
|
|
|
fi
|
|
|
|
|
2020-01-07 10:20:56 +00:00
|
|
|
# Build a specific module
|
|
|
|
if [ "${MODULE}" ]; then
|
2022-02-01 12:52:23 +00:00
|
|
|
m $MODULE "$CMD"
|
2020-12-18 02:31:59 +00:00
|
|
|
checkExit
|
|
|
|
|
2020-01-07 10:20:56 +00:00
|
|
|
# Build signed rom package if specified
|
|
|
|
elif [ "${KEY_MAPPINGS}" ]; then
|
|
|
|
# Set sign key password file if specified
|
|
|
|
if [ "${PWFILE}" ]; then
|
|
|
|
export ANDROID_PW_FILE=$PWFILE
|
|
|
|
fi
|
2020-12-18 02:31:59 +00:00
|
|
|
|
|
|
|
# Make package for distribution
|
2022-02-01 12:52:23 +00:00
|
|
|
m dist "$CMD"
|
2020-12-18 02:31:59 +00:00
|
|
|
|
|
|
|
checkExit
|
|
|
|
|
2020-01-07 10:20:56 +00:00
|
|
|
echo -e "${CLR_BLD_BLU}Signing target files apks${CLR_RST}"
|
2020-12-18 02:31:59 +00:00
|
|
|
sign_target_files_apks -o -d $KEY_MAPPINGS \
|
2021-09-30 15:51:00 +00:00
|
|
|
out/dist/aospa_$DEVICE-target_files-$FILE_NAME_TAG.zip \
|
|
|
|
aospa-$AOSPA_VERSION-signed-target_files-$FILE_NAME_TAG.zip
|
2020-12-18 02:31:59 +00:00
|
|
|
|
|
|
|
checkExit
|
|
|
|
|
2020-01-07 10:20:56 +00:00
|
|
|
echo -e "${CLR_BLD_BLU}Generating signed install package${CLR_RST}"
|
2020-12-18 02:31:59 +00:00
|
|
|
ota_from_target_files -k $KEY_MAPPINGS/releasekey \
|
2021-01-06 06:00:29 +00:00
|
|
|
--block ${INCREMENTAL} \
|
2021-09-30 15:51:00 +00:00
|
|
|
aospa-$AOSPA_VERSION-signed-target_files-$FILE_NAME_TAG.zip \
|
|
|
|
aospa-$AOSPA_VERSION.zip
|
2020-12-18 02:31:59 +00:00
|
|
|
|
|
|
|
checkExit
|
|
|
|
|
2020-04-23 04:32:02 +00:00
|
|
|
if [ "$DELTA_TARGET_FILES" ]; then
|
|
|
|
# die if base target doesn't exist
|
|
|
|
if [ ! -f "$DELTA_TARGET_FILES" ]; then
|
|
|
|
echo -e "${CLR_BLD_RED}Delta error: base target files don't exist ($DELTA_TARGET_FILES)${CLR_RST}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-12-18 02:31:59 +00:00
|
|
|
ota_from_target_files -k $KEY_MAPPINGS/releasekey \
|
2021-01-06 06:00:29 +00:00
|
|
|
--block --incremental_from $DELTA_TARGET_FILES \
|
2021-09-30 15:51:00 +00:00
|
|
|
aospa-$AOSPA_VERSION-signed-target_files-$FILE_NAME_TAG.zip \
|
|
|
|
aospa-$AOSPA_VERSION-delta.zip
|
2020-12-18 02:31:59 +00:00
|
|
|
checkExit
|
2020-04-23 04:32:02 +00:00
|
|
|
fi
|
2020-12-22 01:14:25 +00:00
|
|
|
|
2020-04-23 04:32:02 +00:00
|
|
|
if [ "$FLAG_IMG_ZIP" = 'y' ]; then
|
2022-02-01 12:53:05 +00:00
|
|
|
echo -e "${CLR_BLD_BLU}Generating signed fastboot package${CLR_RST}"
|
2020-12-18 02:31:59 +00:00
|
|
|
img_from_target_files \
|
2021-09-30 15:51:00 +00:00
|
|
|
aospa-$AOSPA_VERSION-signed-target_files-$FILE_NAME_TAG.zip \
|
|
|
|
aospa-$AOSPA_VERSION-signed-image.zip
|
2020-12-18 02:31:59 +00:00
|
|
|
checkExit
|
2020-04-23 04:32:02 +00:00
|
|
|
fi
|
2020-01-07 10:20:56 +00:00
|
|
|
# Build rom package
|
2020-12-22 01:14:25 +00:00
|
|
|
elif [ "$FLAG_IMG_ZIP" = 'y' ]; then
|
2022-02-01 12:52:23 +00:00
|
|
|
m updatepackage otapackage "$CMD"
|
2020-12-22 01:14:25 +00:00
|
|
|
|
|
|
|
checkExit
|
|
|
|
|
2021-09-30 15:51:00 +00:00
|
|
|
cp -f $OUT/aospa_$DEVICE-ota-$FILE_NAME_TAG.zip $OUT/aospa-$AOSPA_VERSION.zip
|
|
|
|
cp -f $OUT/aospa_$DEVICE-img-$FILE_NAME_TAG.zip $OUT/aospa-$AOSPA_VERSION-image.zip
|
2020-12-22 01:14:25 +00:00
|
|
|
|
2015-01-27 19:53:08 +00:00
|
|
|
else
|
2022-02-01 12:52:23 +00:00
|
|
|
m otapackage "$CMD"
|
2020-12-18 02:31:59 +00:00
|
|
|
|
|
|
|
checkExit
|
|
|
|
|
2021-09-30 15:51:00 +00:00
|
|
|
cp -f $OUT/aospa_$DEVICE-ota-$FILE_NAME_TAG.zip $OUT/aospa-$AOSPA_VERSION.zip
|
2013-11-09 21:10:23 +00:00
|
|
|
fi
|
|
|
|
echo -e ""
|
|
|
|
|
2015-01-27 19:53:08 +00:00
|
|
|
# Check the finishing time
|
|
|
|
TIME_END=$(date +%s.%N)
|
|
|
|
|
|
|
|
# Log those times at the end as a fun fact of the day
|
|
|
|
echo -e "${CLR_BLD_GRN}Total time elapsed:${CLR_RST} ${CLR_GRN}$(echo "($TIME_END - $TIME_START) / 60" | bc) minutes ($(echo "$TIME_END - $TIME_START" | bc) seconds)${CLR_RST}"
|
|
|
|
echo -e ""
|
2017-08-10 01:39:26 +00:00
|
|
|
|
2020-12-18 02:31:59 +00:00
|
|
|
exit 0
|