Skip to content

Instantly share code, notes, and snippets.

@khoa-io
Created May 5, 2021 16:22
Show Gist options
  • Save khoa-io/a006346fc5a1738701c48902a640af3d to your computer and use it in GitHub Desktop.
Save khoa-io/a006346fc5a1738701c48902a640af3d to your computer and use it in GitHub Desktop.
Set up AOSP build environment for zsh
#compdef aosp
# Basic completion
complete -W "cd customize-sbox build env log reload tree unset xcode" aosp
# # Advanced completion from _aosp
# compdef _aosp aosp
# autoload -U compinit
# compinit
local sub_command=$1
if test -z "$sub_command"; then
aosp reload
echo ${AOSP}
return
fi
case $sub_command in
env)
local previous_dir=$(pwd)
# set the number of open files to be 1024
ulimit -S -n 1024
cd ${AOSP}
source build/envsetup.sh
if test -z "$AOSP_BUILD"; then
export AOSP_BUILD=sdk_phone_x86
fi
if test -z "$AOSP_BUILD_TYPE"; then
export AOSP_BUILD_TYPE=userdebug
fi
export AOSP_BUILD_TARGET="${AOSP_BUILD}-${AOSP_BUILD_TYPE}"
echo "lunch ${AOSP_BUILD_TARGET}"
lunch ${AOSP_BUILD_TARGET}
cd $previous_dir
;;
build)
aosp env
m droid | aosp log
;;
log)
local timestamp=$(date "+%Y%m%d%H%M%S")
local logfile=${AOSP}/build_${timestamp}.log
tee ${logfile}
echo ${logfile}
export AOSP_BUILD_LOG=${logfile}
;;
cd)
cd ${AOSP}
;;
reload)
unfunction aosp
autoload -Uz aosp
;;
customize-sbox)
if [[ -f "${AOSP}/out/soong/host/darwin-x86/bin/sbox.elf" ]]; then
echo "${AOSP}/out/soong/host/darwin-x86/bin/sbox.elf exists. Skip."
else
echo "${AOSP}/out/soong/host/darwin-x86/bin/sbox.elf does not exist. Processing ..."
echo "#\!/bin/sh\nexport _JAVA_OPTIONS="-Xmx8g"\nexport JAVA_OPTIONS="-Xmx8g"\n\necho "_JAVA_OPTIONS='-Xmx8g' ${AOSP}/out/soong/host/darwin-x86/bin/sbox.elf $@"\n_JAVA_OPTIONS="-Xmx8g" ${AOSP}/out/soong/host/darwin-x86/bin/sbox.elf $@\n" >${AOSP}/out/soong/host/darwin-x86/bin/sbox
echo "mv ${AOSP}/out/soong/host/darwin-x86/bin/sbox ${AOSP}/out/soong/host/darwin-x86/bin/sbox.elf"
mv ${AOSP}/out/soong/host/darwin-x86/bin/sbox ${AOSP}/out/soong/host/darwin-x86/bin/sbox.elf
echo "ln -s ${AOSP}/sbox ${AOSP}/out/soong/host/darwin-x86/bin/sbox"
ln -s ${AOSP}/sbox ${AOSP}/out/soong/host/darwin-x86/bin/sbox
fi
;;
unset)
unset AOSP_BUILD
unset AOSP_BUILD_TYPE
unset AOSP_BUILD_TARGET
;;
tree)
echo 'tree -Q -I ".repo" -I ".git" -fa ${AOSP} -o ${AOSP}/aosp_tree.log'
tree -Q -I ".repo|.git" -fa ${AOSP} -o ${AOSP}/aosp_tree.log
;;
sample)
echo "Sample sub-command"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment