Skip to content

Commit

Permalink
update_symbol_list.sh: support more build parameters
Browse files Browse the repository at this point in the history
* BUILD_AOSP_KERNEL: to build aosp kernel
* BUILD_STAGING_KERNEL: to build staging kernel
* GKI_KERNEL_DIR: specify the folder name of aosp/staging kernel
* GKI_KERNEL_REMOTE: specify the gerrit remote of aosp/staging kernel
* GKI_KERNEL_BRANCH: specify the branch name of aosp/staging kernel
* BUILD_SCRIPT: specify the script name

Bug: 230573746
Signed-off-by: Robin Peng <[email protected]>
Change-Id: Ibc2185577d3afaaa1fbf64bd7c98caf5e6772953
  • Loading branch information
Robin Peng committed May 10, 2022
1 parent 5a087da commit 9a6a689
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 43 deletions.
12 changes: 10 additions & 2 deletions build_slider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ function exit_if_error {
fi
}

if [ "${BUILD_AOSP_KERNEL}" = "1" ]; then
BUILD_KERNEL=1
EXPERIMENTAL_BUILD=0
elif [ "${BUILD_STAGING_KERNEL}" = "1" ]; then
BUILD_KERNEL=1
EXPERIMENTAL_BUILD=1
fi

EXPERIMENTAL_BUILD=${EXPERIMENTAL_BUILD:-0}
TRIM_NONLISTED_KMI=${TRIM_NONLISTED_KMI:-1}
LTO=${LTO:-thin}
Expand All @@ -33,8 +41,8 @@ if [ "${BUILD_KERNEL}" = "0" ]; then
else
USING_PREBUILTS=
if [ "${EXPERIMENTAL_BUILD}" != "0" ]; then
GKI_KERNEL_OUT_DIR=android13-5.10-staging
GKI_KERNEL_BUILD_CONFIG=common/build.config.gki.aarch64
GKI_KERNEL_OUT_DIR=android13-5.10-pixel-staging
GKI_KERNEL_BUILD_CONFIG=aosp-staging/build.config.gki.aarch64
else
GKI_KERNEL_OUT_DIR=android13-5.10
GKI_KERNEL_BUILD_CONFIG=aosp/build.config.gki.aarch64
Expand Down
99 changes: 58 additions & 41 deletions update_symbol_list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
function usage {
echo "USAGE: $0 [-p|--prepare-aosp-abi BUG_NUMBER [-c|--continue] [--change-id CHANGE_ID]]"
echo
echo " -p | --prepare-aosp-abi BUG_NUMBER Update the AOSP ABI xml and symbol list in aosp/ and"
echo " create a commit with the provide BUG_NUMBER."
echo " -p | --prepare-aosp-abi BUG_NUMBER Update the AOSP ABI xml and symbol list in ${GKI_KERNEL_DIR}/ "
echo " and create a commit with the provide BUG_NUMBER."
echo " -c | --continue Continue after the rebase failure"
echo " --change-id CHANGE_ID Use this Change-Id when creating the AOSP commit"
}
Expand Down Expand Up @@ -52,15 +52,15 @@ function verify_aosp_tree {
return
fi

pushd aosp >/dev/null
pushd ${GKI_KERNEL_DIR} >/dev/null
if ! git diff --quiet HEAD; then
exit_if_error 1 \
"Found uncommitted changes in aosp/. Commit your changes before updating the ABI"
"Found uncommitted changes in ${GKI_KERNEL_DIR}/. Commit your changes before updating the ABI"
fi

if [ "${CONTINUE_AFTER_REBASE}" = "0" ]; then
if git branch | grep "\<${FOR_AOSP_PUSH_BRANCH}\>" 2>&1 >/dev/null; then
echo "The branch '${FOR_AOSP_PUSH_BRANCH}' already exists in aosp/. Please delete" >&2
echo "The branch '${FOR_AOSP_PUSH_BRANCH}' already exists in ${GKI_KERNEL_DIR}/. Please delete" >&2
echo "this branch (git branch -D ${FOR_AOSP_PUSH_BRANCH}) before continuing." >&2
exit 1
fi
Expand All @@ -84,22 +84,22 @@ function update_aosp_abi {
local out_dir="out_aosp_abi"
local pixel_symbol_list="android/abi_gki_aarch64_generic"

# Rebase to aosp/android13-5.10 ToT before updating the ABI
pushd aosp/ >/dev/null
# Rebase to ${GKI_KERNEL_REMOTE}/${GKI_KERNEL_BRANCH} ToT before updating the ABI
pushd ${GKI_KERNEL_DIR}/ >/dev/null
if [ "${CONTINUE_AFTER_REBASE}" = "0" ]; then
git checkout -b ${FOR_AOSP_PUSH_BRANCH}
fi
git fetch aosp android13-5.10 && git rebase FETCH_HEAD
git fetch ${GKI_KERNEL_REMOTE} ${GKI_KERNEL_BRANCH} && git rebase FETCH_HEAD
err=$?
if [ "${err}" != "0" ]; then
echo "ERROR: Failed to rebase your aosp/ change(s) to the AOSP ToT." >&2
echo "ERROR: Failed to rebase your ${GKI_KERNEL_DIR}/ change(s) to the ${GKI_KERNEL_REMOTE} ToT." >&2
echo "To resolve this, please manually resolve the rebase conflicts" >&2
echo "and run: git rebase --continue. Then resume this script" >&2
echo "using the command:" >&2
echo >&2
echo " $0 --prepare-aosp-abi ${BUG} --continue" >&2
echo >&2
echo "To return to your original tree in aosp/ after finishing the" >&2
echo "To return to your original tree in ${GKI_KERNEL_DIR}/ after finishing the" >&2
echo "ABI update, run this git command:" >&2
echo >&2
echo " git checkout ${AOSP_CUR_BRANCH_OR_SHA1}" >&2
Expand All @@ -108,20 +108,20 @@ function update_aosp_abi {
fi
popd >/dev/null

# First, rollback any symbol list changes in aosp/ and then regenerate the
# First, rollback any symbol list changes in ${GKI_KERNEL_DIR}/ and then regenerate the
# list based on AOSP ToT and the updated pixel symbol list. This ensures that
# we only add symbols needed based on the current pixel changes.
#
# Note: we are purposefully not using `--additions-only` in order to avoid
# adding symbols in the pixel tree during development that later get removed.
# To retain symbols in the same way as `--additions-only` does, we are
# cat'ing the private/gs-google/ and ToT aosp/ symbol lists together when
# cat'ing the private/gs-google/ and ToT ${GKI_KERNEL_DIR}/ symbol lists together when
# preparing for the AOSP ABI update. This retains all symbols in the aosp
# version of the pixel symbol list.
git -C aosp show aosp/android13-5.10:"${pixel_symbol_list}" \
> aosp/android/abi_gki_aarch64_generic
git -C ${GKI_KERNEL_DIR} show ${GKI_KERNEL_REMOTE}/${GKI_KERNEL_BRANCH}:"${pixel_symbol_list}" \
> ${GKI_KERNEL_DIR}/android/abi_gki_aarch64_generic
extract_pixel_symbols 0 "private/gs-google/${pixel_symbol_list}"
merge_and_sort_symbol_lists "aosp/${pixel_symbol_list}" \
merge_and_sort_symbol_lists "${GKI_KERNEL_DIR}/${pixel_symbol_list}" \
"private/gs-google/${pixel_symbol_list}"

# Create the symbol list commit and check if the ABI xml needs to be updated
Expand All @@ -134,7 +134,7 @@ function update_aosp_abi {
if [ -n "${CHANGE_ID}" ]; then
echo "Change-Id: ${CHANGE_ID}" >> ${COMMIT_TEXT}
fi
git -C aosp commit -s -F ${COMMIT_TEXT} -- android/
git -C ${GKI_KERNEL_DIR} commit -s -F ${COMMIT_TEXT} -- android/
commit_ret=$?
rm -f ${COMMIT_TEXT}

Expand All @@ -145,7 +145,7 @@ function update_aosp_abi {
# Update the AOSP ABI xml now
rm -rf ${out_dir}
OUT_DIR=${out_dir} \
BUILD_CONFIG=aosp/build.config.gki.aarch64 \
BUILD_CONFIG=${GKI_KERNEL_DIR}/build.config.gki.aarch64 \
SKIP_CP_KERNEL_HDR=1 \
LTO=full \
DIST_DIR= \
Expand All @@ -154,13 +154,13 @@ function update_aosp_abi {
build/build_abi.sh --update "$@"
# TODO: How do I know if the build failed or the ABI xml was updated??

# Create the git ABI xml commit for aosp/android13-5.10 if needed
# Create the git ABI xml commit for ${GKI_KERNEL_REMOTE}/${GKI_KERNEL_BRANCH} if needed
if [ -f "${out_dir}/dist/abi.report.short" ]; then
if [ "${commit_ret}" = "0" ]; then
# The ACK team requires the symbol list and xml changes to be committed
# in a single patch. So reset the git repo to drop the symbol list
# commit we made above.
git -C aosp reset HEAD~1
git -C ${GKI_KERNEL_DIR} reset HEAD~1
fi

COMMIT_TEXT=$(mktemp -t abi_xml_commit_text.XXXXX)
Expand All @@ -172,34 +172,34 @@ function update_aosp_abi {
if [ -n "${CHANGE_ID}" ]; then
echo "Change-Id: ${CHANGE_ID}" >> ${COMMIT_TEXT}
fi
git -C aosp commit -s -F ${COMMIT_TEXT} -- android/
git -C ${GKI_KERNEL_DIR} commit -s -F ${COMMIT_TEXT} -- android/
commit_ret=$?
rm -f ${COMMIT_TEXT}
fi
fi

echo "========================================================"
if ! git -C aosp diff --quiet aosp/android13-5.10..HEAD; then
if ! git -C ${GKI_KERNEL_DIR} diff --quiet ${GKI_KERNEL_REMOTE}/${GKI_KERNEL_BRANCH}..HEAD; then
if [ "${commit_ret}" = "0" ]; then
if [ -n "${FOR_AOSP_PUSH_BRANCH}" ]; then
echo " An ABI commit in aosp/ was created for you on the branch ${FOR_AOSP_PUSH_BRANCH}."
echo " An ABI commit in ${GKI_KERNEL_DIR}/ was created for you on the branch ${FOR_AOSP_PUSH_BRANCH}."
else
echo " An ABI commit in aosp/ was created for you on the current branch."
echo " An ABI commit in ${GKI_KERNEL_DIR}/ was created for you on the current branch."
fi
else
echo " The ABI xml and symbol list is up-to-date."
fi
echo " Please verify your commit(s) before pushing. Here are the steps to perform:"
echo
echo " cd aosp"
echo " cd ${GKI_KERNEL_DIR}"
echo " git log --oneline ${FOR_AOSP_PUSH_BRANCH}"
echo " git push aosp ${FOR_AOSP_PUSH_BRANCH:-HEAD}:refs/for/android13-5.10"
echo " git push ${GKI_KERNEL_REMOTE} ${FOR_AOSP_PUSH_BRANCH:-HEAD}:refs/for/${GKI_KERNEL_BRANCH}"
echo
if [ -n "${FOR_AOSP_PUSH_BRANCH}" ]; then
echo " After pushing your changes to aosp/, you can delete the temporary"
echo " After pushing your changes to ${GKI_KERNEL_DIR}/, you can delete the temporary"
echo " branch: ${FOR_AOSP_PUSH_BRANCH} using the command:"
echo
echo " cd aosp"
echo " cd ${GKI_KERNEL_DIR}"
echo " git branch -D ${FOR_AOSP_PUSH_BRANCH}"
echo
fi
Expand All @@ -209,13 +209,13 @@ function update_aosp_abi {

# Rollback to the original branch/commit
if [ -n "${AOSP_CUR_BRANCH_OR_SHA1}" ]; then
git -C aosp checkout ${AOSP_CUR_BRANCH_OR_SHA1}
git -C ${GKI_KERNEL_DIR} checkout ${AOSP_CUR_BRANCH_OR_SHA1}
fi
}

# Extract the kernel module symbols. Additionally, we strip out the core ABI
# symbols and sort the symbol list. We do our own sort in order to retain
# a predictable order when cat'ing the symbol lists in the pixel tree and aosp/
# a predictable order when cat'ing the symbol lists in the pixel tree and ${GKI_KERNEL_DIR}/
# tree.
# $1 Specifies if --additions-only should be used
# $2 The symbol list to update/create
Expand Down Expand Up @@ -245,7 +245,7 @@ function extract_pixel_symbols {
exit_if_error $? "Failed to extract symbols!"

# Strip the core ABI symbols from the pixel symbol list
grep "^ " aosp/android/abi_gki_aarch64_core | while read l; do
grep "^ " ${GKI_KERNEL_DIR}/android/abi_gki_aarch64_core | while read l; do
sed -i "/\<$l\>/d" ${pixel_symbol_list}
done

Expand All @@ -260,8 +260,8 @@ function extract_pixel_symbols {
function verify_new_symbols_require_abi_update {
local pixel_symbol_list=$1

pushd aosp/ >/dev/null
git diff --name-only aosp/android13-5.10..HEAD | grep -v "\<${pixel_symbol_list}\>"
pushd ${GKI_KERNEL_DIR}/ >/dev/null
git diff --name-only ${GKI_KERNEL_REMOTE}/${GKI_KERNEL_BRANCH}..HEAD | grep -v "\<${pixel_symbol_list}\>"
err=$?
if [ "${err}" = "0" ]; then
# Found other files beside the pixel symbol list
Expand All @@ -270,7 +270,7 @@ function verify_new_symbols_require_abi_update {
return
fi

local added_symbols=$(git diff aosp/android13-5.10..HEAD "${pixel_symbol_list}" \
local added_symbols=$(git diff ${GKI_KERNEL_REMOTE}/${GKI_KERNEL_BRANCH}..HEAD "${pixel_symbol_list}" \
| sed -n 's/^+ \([a-zA-Z_0-9]\+\)/\1/p')
for s in ${added_symbols}; do
grep "^ $s\>" --exclude=abi_gki_aarch64.xml \
Expand All @@ -292,6 +292,19 @@ export DIST_DIR=${DIST_DIR:-${BASE_OUT}/dist/}
VMLINUX_TMP=${BASE_OUT}/device-kernel/private/vmlinux
# Use mktemp -u to create a random branch name
FOR_AOSP_PUSH_BRANCH="update_symbol_list-delete-after-push"
BUILD_AOSP_KERNEL=${BUILD_AOSP_KERNEL:-1}
if [ -z "${GKI_KERNEL_DIR}" ];then
GKI_KERNEL_DIR="aosp"
fi
if [ -z "${GKI_KERNEL_REMOTE}" ];then
GKI_KERNEL_REMOTE="aosp"
fi
if [ -z "${GKI_KERNEL_BRANCH}" ];then
GKI_KERNEL_BRANCH="android13-5.10"
fi
if [ -z "${BUILD_SCRIPT}" ];then
BUILD_SCRIPT="./build_slider.sh"
fi
PREPARE_AOSP_ABI=${PREPARE_AOSP_ABI:-0}
CONTINUE_AFTER_REBASE=0
CHANGE_ID=
Expand Down Expand Up @@ -342,26 +355,30 @@ fi
verify_aosp_tree

if [ "${CONTINUE_AFTER_REBASE}" = "0" ]; then
BUILD_KERNEL=1 TRIM_NONLISTED_KMI=0 ENABLE_STRICT_KMI=0 ./build_slider.sh "$@"
exit_if_error $? "Failed to run ./build_slider.sh!"
if [ "${BUILD_AOSP_KERNEL}" = "1" ]; then
BUILD_AOSP_KERNEL=1 TRIM_NONLISTED_KMI=0 ENABLE_STRICT_KMI=0 ${BUILD_SCRIPT} "$@"
elif [ "${BUILD_STAGING_KERNEL}" = "1" ]; then
BUILD_STAGING_KERNEL=1 TRIM_NONLISTED_KMI=0 ENABLE_STRICT_KMI=0 ${BUILD_SCRIPT} "$@"
fi
exit_if_error $? "Failed to run ${BUILD_SCRIPT}!"
fi

if [ "${PREPARE_AOSP_ABI}" != "0" ]; then
update_aosp_abi "$@"
else
extract_pixel_symbols 1 "private/gs-google/android/abi_gki_aarch64_generic"
merge_and_sort_symbol_lists "aosp/android/abi_gki_aarch64_generic" \
merge_and_sort_symbol_lists "${GKI_KERNEL_DIR}/android/abi_gki_aarch64_generic" \
"private/gs-google/android/abi_gki_aarch64_generic"

echo "========================================================"
echo " The symbol list has been updated locally in aosp/ and private/gs-google."
echo " The symbol list has been updated locally in ${GKI_KERNEL_DIR}/ and private/gs-google."
echo " Compiling with BUILD_KERNEL=1 is now required until the new symbol(s)"
echo " are merged. Re-compile using the below command:"
echo
if [ -z "${DEVICE_KERNEL_BUILD_CONFIG}" ]; then
echo " SKIP_MRPROPER=1 BUILD_KERNEL=1 ./build_slider.sh"
else
echo " SKIP_MRPROPER=1 BUILD_KERNEL=1 ./build_cloudripper.sh"
if [ "${BUILD_AOSP_KERNEL}" = "1" ]; then
echo " SKIP_MRPROPER=1 BUILD_AOSP_KERNEL=1 ${BUILD_SCRIPT}"
elif [ "${BUILD_STAGING_KERNEL}" = "1" ]; then
echo " SKIP_MRPROPER=1 BUILD_STAGING_KERNEL=1 ${BUILD_SCRIPT}"
fi
echo
fi

0 comments on commit 9a6a689

Please sign in to comment.