aosp-merger: Switch all scripts to argument parsing

Change-Id: I7af863d3952e7ae9de16860404bccd2b582caa20
This commit is contained in:
Michael Bestas
2022-06-19 02:54:34 +03:00
committed by Chirayu Desai
parent f3b9352ed8
commit c44154f25c
8 changed files with 197 additions and 89 deletions

View File

@@ -7,21 +7,43 @@
# #
usage() { usage() {
echo "Usage ${0} <projectpath> <merge|rebase> <oldaosptag> <newaosptag>" echo "Usage ${0} -p <projectpath> -o <merge|rebase> -c <old-tag> -n <new-tag> -b <branch-suffix>"
} }
# Verify argument count # Verify argument count
if [ "$#" -ne 4 ]; then if [ "${#}" -eq 0 ]; then
usage usage
exit 1 exit 1
fi fi
PROJECTPATH="${1}" while [ "${#}" -gt 0 ]; do
OPERATION="${2}" case "${1}" in
OLDTAG="${3}" -p | --project-path )
NEWTAG="${4}" PROJECTPATH="${2}"; shift
;;
-o | --operation )
OPERATION="${2}"; shift
;;
-c | --old-tag )
OLDTAG="${2}"; shift
;;
-n | --new-tag )
NEWTAG="${2}"; shift
;;
-b | --branch-suffix )
BRANCHSUFFIX="${2}"; shift
;;
* )
usage
exit 1
;;
esac
shift
done
if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then if [ -z "${OPERATION}" ]; then
OPERATION="merge"
elif [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then
usage usage
exit 1 exit 1
fi fi
@@ -36,6 +58,7 @@ readonly hook="${script_path}/prepare-commit-msg"
TOP="${script_path}/../../.." TOP="${script_path}/../../.."
BRANCH="${lineageos_branch}" BRANCH="${lineageos_branch}"
STAGINGBRANCH="staging/${BRANCHSUFFIX}"
cd "${TOP}/${PROJECTPATH}" cd "${TOP}/${PROJECTPATH}"
repo start "${STAGINGBRANCH}" . repo start "${STAGINGBRANCH}" .
@@ -44,8 +67,6 @@ git fetch -q --force --tags aosp "${NEWTAG}"
[[ ! -e .git/hooks/prepare-commit-msg ]] && cp "${hook}" .git/hooks/ [[ ! -e .git/hooks/prepare-commit-msg ]] && cp "${hook}" .git/hooks/
chmod +x .git/hooks/prepare-commit-msg chmod +x .git/hooks/prepare-commit-msg
PROJECTOPERATION="${OPERATION}"
# Was there any change upstream? Skip if not. # Was there any change upstream? Skip if not.
if [[ -z "$(git diff ${OLDTAG} ${NEWTAG})" ]]; then if [[ -z "$(git diff ${OLDTAG} ${NEWTAG})" ]]; then
echo -e "nochange\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" echo -e "nochange\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}"
@@ -62,7 +83,7 @@ if [[ "$?" -eq 1 ]]; then
echo "of new tag ${NEWTAG} ####" echo "of new tag ${NEWTAG} ####"
fi fi
if [[ "${PROJECTOPERATION}" == "merge" ]]; then if [[ "${OPERATION}" == "merge" ]]; then
echo "#### Merging ${NEWTAG} into ${PROJECTPATH} ####" echo "#### Merging ${NEWTAG} into ${PROJECTPATH} ####"
git merge --no-commit --log "${NEWTAG}" && git commit --no-edit git merge --no-commit --log "${NEWTAG}" && git commit --no-edit
@@ -73,7 +94,7 @@ if [[ "${PROJECTOPERATION}" == "merge" ]]; then
repo abandon "${STAGINGBRANCH}" . repo abandon "${STAGINGBRANCH}" .
exit 0 exit 0
fi fi
elif [[ "${PROJECTOPERATION}" == "rebase" ]]; then elif [[ "${OPERATION}" == "rebase" ]]; then
echo "#### Rebasing ${PROJECTPATH} onto ${NEWTAG} ####" echo "#### Rebasing ${PROJECTPATH} onto ${NEWTAG} ####"
git rebase --onto "${NEWTAG}" "${OLDTAG}" git rebase --onto "${NEWTAG}" "${OLDTAG}"
fi fi
@@ -82,4 +103,4 @@ CONFLICT=""
if [[ -n "$(git status --porcelain)" ]]; then if [[ -n "$(git status --porcelain)" ]]; then
CONFLICT="conflict-" CONFLICT="conflict-"
fi fi
echo -e "${CONFLICT}${PROJECTOPERATION}\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" echo -e "${CONFLICT}${OPERATION}\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}"

View File

@@ -7,18 +7,46 @@
# #
usage() { usage() {
echo "Usage ${0} <projectpath> <oldaosptag> <newaosptag>" echo "Usage ${0} -p <projectpath> -o <merge|rebase> -c <old-tag> -n <new-tag> -b <branch-suffix>"
} }
# Verify argument count # Verify argument count
if [ "$#" -ne 3 ]; then if [ "${#}" -eq 0 ]; then
usage usage
exit 1 exit 1
fi fi
PROJECTPATH="${1}" while [ "${#}" -gt 0 ]; do
OLDTAG="${2}" case "${1}" in
NEWTAG="${3}" -p | --project-path )
PROJECTPATH="${2}"; shift
;;
-o | --operation )
OPERATION="${2}"; shift
;;
-c | --old-tag )
OLDTAG="${2}"; shift
;;
-n | --new-tag )
NEWTAG="${2}"; shift
;;
-b | --branch-suffix )
BRANCHSUFFIX="${2}"; shift
;;
* )
usage
exit 1
;;
esac
shift
done
if [ -z "${OPERATION}" ]; then
OPERATION="merge"
elif [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then
usage
exit 1
fi
### CONSTANTS ### ### CONSTANTS ###
readonly script_path="$(cd "$(dirname "$0")";pwd -P)" readonly script_path="$(cd "$(dirname "$0")";pwd -P)"
@@ -30,6 +58,7 @@ readonly hook="${script_path}/prepare-commit-msg"
TOP="${script_path}/../../.." TOP="${script_path}/../../.."
BRANCH="${lineageos_branch}" BRANCH="${lineageos_branch}"
STAGINGBRANCH="staging/${BRANCHSUFFIX}"
cd "${TOP}/${PROJECTPATH}" cd "${TOP}/${PROJECTPATH}"
# Ditch any existing staging branches # Ditch any existing staging branches
@@ -104,4 +133,4 @@ if [[ -z "$(git diff HEAD m/${lineageos_branch})" && -z "$(git status --porcelai
exit 0 exit 0
fi fi
echo -e "${CONFLICT}merge\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" echo -e "${CONFLICT}${OPERATION}\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}"

View File

@@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# SPDX-FileCopyrightText: 2022 The Calyx Institute # SPDX-FileCopyrightText: 2022 The Calyx Institute
# SPDX-FileCopyrightText: 2022 The LineageOS Project
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
@@ -44,63 +45,59 @@ export LC_TIME=C
### FUNCTIONS ### ### FUNCTIONS ###
merge_aosp() { merge_aosp() {
export STAGINGBRANCH="staging/${common_aosp_tag}_merge-${prev_common_aosp_tag}" "${script_path}"/merge-aosp.sh --old-tag "${common_aosp_tag}" --new-tag "${prev_common_aosp_tag}" --branch-suffix "${common_aosp_tag}_merge-${prev_common_aosp_tag}"
"${script_path}"/merge-aosp.sh merge "${common_aosp_tag}" "${prev_common_aosp_tag}"
} }
merge_aosp_forks() { merge_aosp_forks() {
export STAGINGBRANCH="staging/${lineageos_branch}_merge-${common_aosp_tag}" "${script_path}"/merge-aosp-forks.sh --old-tag "${prev_common_aosp_tag}" --new-tag "${common_aosp_tag}" --branch-suffix "${lineageos_branch}_merge-${common_aosp_tag}"
"${script_path}"/merge-aosp-forks.sh merge "${prev_common_aosp_tag}" "${common_aosp_tag}"
} }
squash_aosp_merge() { squash_aosp_merge() {
"${script_path}"/squash.sh merge "${prev_common_aosp_tag}" "${common_aosp_tag}" false "${script_path}"/squash.sh --branch-suffix "${lineageos_branch}_merge-${common_aosp_tag}"
} }
upload_squash_aosp_to_review() { upload_squash_aosp_to_review() {
"${script_path}"/upload-squash.sh merge "${prev_common_aosp_tag}" "${common_aosp_tag}" false "${script_path}"/upload-squash.sh --branch-suffix "${lineageos_branch}_merge-${common_aosp_tag}"
} }
push_aosp_merge() { push_aosp_merge() {
"${script_path}"/push-merge.sh merge "${prev_common_aosp_tag}" "${common_aosp_tag}" "${script_path}"/push-merge.sh --branch-suffix "${lineageos_branch}_merge-${common_aosp_tag}"
} }
merge_pixel_device() { merge_pixel_device() {
export STAGINGBRANCH="staging/${lineageos_branch}_merge-${aosp_tag}"
for repo in ${device_repos[@]}; do for repo in ${device_repos[@]}; do
"${script_path}"/_subtree_merge_helper.sh "${repo}" "${prev_aosp_tag}" "${aosp_tag}" "${script_path}"/_subtree_merge_helper.sh --project-path "${repo}" --old-tag "${prev_aosp_tag}" --new-tag "${aosp_tag}" --branch-suffix "${lineageos_branch}_merge-${aosp_tag}"
done done
} }
squash_pixel_device() { squash_pixel_device() {
"${script_path}"/squash.sh merge "${prev_aosp_tag}" "${aosp_tag}" true "${script_path}"/squash.sh --new-tag "${aosp_tag}" --branch-suffix "${lineageos_branch}_merge-${aosp_tag}" --pixel
} }
upload_squash_device_to_review() { upload_squash_device_to_review() {
"${script_path}"/upload-squash.sh merge "${prev_aosp_tag}" "${aosp_tag}" true "${script_path}"/upload-squash.sh --branch-suffix "${lineageos_branch}_merge-${aosp_tag}" --pixel
} }
push_device_merge() { push_device_merge() {
"${script_path}"/push-merge.sh merge "${prev_aosp_tag}" "${aosp_tag}" "${script_path}"/push-merge.sh --branch-suffix "${lineageos_branch}_merge-${aosp_tag}"
} }
merge_pixel_kernel() { merge_pixel_kernel() {
export STAGINGBRANCH="staging/${lineageos_branch}_merge-${kernel_tag}"
for repo in ${device_kernel_repos}; do for repo in ${device_kernel_repos}; do
"${script_path}"/_subtree_merge_helper.sh "${repo}" "${prev_kernel_tag}" "${kernel_tag}" "${script_path}"/_subtree_merge_helper.sh --project-path "${repo}" --old-tag "${prev_kernel_tag}" --new-tag "${kernel_tag}" --branch-suffix "${lineageos_branch}_merge-${kernel_tag}"
done done
} }
squash_pixel_kernel() { squash_pixel_kernel() {
"${script_path}"/squash.sh merge "${prev_kernel_tag}" "${kernel_tag}" true "${script_path}"/squash.sh --new-tag "${kernel_tag}" --branch-suffix "${lineageos_branch}_merge-${kernel_tag}" --pixel
} }
upload_squash_kernel_to_review() { upload_squash_kernel_to_review() {
"${script_path}"/upload-squash.sh merge "${prev_kernel_tag}" "${kernel_tag}" true "${script_path}"/upload-squash.sh --branch-suffix "${lineageos_branch}_merge-${kernel_tag}" --pixel
} }
push_kernel_merge() { push_kernel_merge() {
"${script_path}"/push-merge.sh merge "${prev_kernel_tag}" "${kernel_tag}" "${script_path}"/push-merge.sh --branch-suffix "${lineageos_branch}_merge-${kernel_tag}"
} }
# error message # error message

View File

@@ -7,20 +7,40 @@
# #
usage() { usage() {
echo "Usage ${0} <merge|rebase> <oldaosptag> <newaosptag>" echo "Usage ${0} -o <merge|rebase> -c <old-aosp-tag> -n <new-aosp-tag> -b <branch-suffix>"
} }
# Verify argument count # Verify argument count
if [ "$#" -ne 3 ]; then if [ "${#}" -eq 0 ]; then
usage usage
exit 1 exit 1
fi fi
OPERATION="${1}" while [ "${#}" -gt 0 ]; do
OLDTAG="${2}" case "${1}" in
NEWTAG="${3}" -o | --operation )
OPERATION="${2}"; shift
;;
-c | --old-tag )
OLDTAG="${2}"; shift
;;
-n | --new-tag )
NEWTAG="${2}"; shift
;;
-b | --branch-suffix )
BRANCHSUFFIX="${2}"; shift
;;
* )
usage
exit 1
;;
esac
shift
done
if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then if [ -z "${OPERATION}" ]; then
OPERATION="merge"
elif [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then
usage usage
exit 1 exit 1
fi fi
@@ -34,6 +54,7 @@ source "${vars_path}/common"
TOP="${script_path}/../../.." TOP="${script_path}/../../.."
MANIFEST="${TOP}/.repo/manifests/default.xml" MANIFEST="${TOP}/.repo/manifests/default.xml"
BRANCH="${lineageos_branch}" BRANCH="${lineageos_branch}"
STAGINGBRANCH="staging/${BRANCHSUFFIX}"
# Source build environment (needed for aospremote) # Source build environment (needed for aospremote)
source "${TOP}/build/envsetup.sh" source "${TOP}/build/envsetup.sh"
@@ -60,7 +81,5 @@ repo abandon "${STAGINGBRANCH}"
# Iterate over each forked project # Iterate over each forked project
for PROJECTPATH in ${PROJECTPATHS}; do for PROJECTPATH in ${PROJECTPATHS}; do
"${script_path}"/_merge_helper.sh "${PROJECTPATH}" "${@}" "${script_path}"/_merge_helper.sh --project-path "${PROJECTPATH}" --operation "${OPERATION}" --old-tag "${OLDTAG}" --new-tag "${NEWTAG}" --branch-suffix "${BRANCHSUFFIX}"
done done
unset STAGINGBRANCH

View File

@@ -7,21 +7,41 @@
# #
usage() { usage() {
echo "Usage ${0} <merge|rebase> <aosp-tag> <different-ancestor-aosp-tag>" echo "Usage ${0} -o <merge|rebase> -c <aosp-tag> -n <different-ancestor-aosp-tag> -b <branch-suffix>"
echo "Example ${0} merge android-12.0.0_r26 android-12.0.0_r18" echo "Example ${0} merge android-12.0.0_r26 android-12.0.0_r18"
} }
# Verify argument count # Verify argument count
if [ "$#" -ne 3 ]; then if [ "${#}" -eq 0 ]; then
usage usage
exit 1 exit 1
fi fi
OPERATION="${1}" while [ "${#}" -gt 0 ]; do
OLDTAG="${2}" case "${1}" in
NEWTAG="${3}" -o | --operation )
OPERATION="${2}"; shift
;;
-c | --old-tag )
OLDTAG="${2}"; shift
;;
-n | --new-tag )
NEWTAG="${2}"; shift
;;
-b | --branch-suffix )
BRANCHSUFFIX="${2}"; shift
;;
* )
usage
exit 1
;;
esac
shift
done
if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then if [ -z "${OPERATION}" ]; then
OPERATION="merge"
elif [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then
usage usage
exit 1 exit 1
fi fi
@@ -34,6 +54,7 @@ source "${vars_path}/common"
TOP="${script_path}/../../.." TOP="${script_path}/../../.."
MANIFEST="${TOP}/.repo/manifests/default.xml" MANIFEST="${TOP}/.repo/manifests/default.xml"
STAGINGBRANCH="staging/${BRANCHSUFFIX}"
# Build list of AOSP repos # Build list of AOSP repos
PROJECTPATHS=$(grep -v "remote=\"gitlab" "${MANIFEST}" | grep -v "clone-depth=\"1" | sed -n 's/.*path="\([^"]\+\)".*/\1/p') PROJECTPATHS=$(grep -v "remote=\"gitlab" "${MANIFEST}" | grep -v "clone-depth=\"1" | sed -n 's/.*path="\([^"]\+\)".*/\1/p')
@@ -56,7 +77,5 @@ repo abandon "${STAGINGBRANCH}"
# Iterate over each forked project # Iterate over each forked project
for PROJECTPATH in ${PROJECTPATHS}; do for PROJECTPATH in ${PROJECTPATHS}; do
"${script_path}"/_merge_helper.sh "${PROJECTPATH}" "${@}" "${script_path}"/_merge_helper.sh --project-path "${PROJECTPATH}" --operation "${OPERATION}" --old-tag "${OLDTAG}" --new-tag "${NEWTAG}" --branch-suffix "${BRANCHSUFFIX}"
done done
unset STAGINGBRANCH

View File

@@ -7,23 +7,27 @@
# #
usage() { usage() {
echo "Usage ${0} <merge|rebase> <oldaosptag> <newaosptag>" echo "Usage ${0} -b <branch-suffix>"
} }
# Verify argument count # Verify argument count
if [ "$#" -ne 3 ]; then if [ "${#}" -eq 0 ]; then
usage usage
exit 1 exit 1
fi fi
OPERATION="${1}" while [ "${#}" -gt 0 ]; do
OLDTAG="${2}" case "${1}" in
NEWTAG="${3}" -b | --branch-suffix )
BRANCHSUFFIX="${2}"; shift
if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then ;;
* )
usage usage
exit 1 exit 1
fi ;;
esac
shift
done
### CONSTANTS ### ### CONSTANTS ###
readonly script_path="$(cd "$(dirname "$0")";pwd -P)" readonly script_path="$(cd "$(dirname "$0")";pwd -P)"
@@ -33,7 +37,7 @@ source "${vars_path}/common"
TOP="${script_path}/../../.." TOP="${script_path}/../../.."
BRANCH="${lineageos_branch}" BRANCH="${lineageos_branch}"
STAGINGBRANCH="staging/${BRANCH}_${OPERATION}-${NEWTAG}" STAGINGBRANCH="staging/${BRANCHSUFFIX}"
# Source build environment (needed for lineageremote) # Source build environment (needed for lineageremote)
source "${TOP}/build/envsetup.sh" source "${TOP}/build/envsetup.sh"

View File

@@ -1,30 +1,41 @@
#!/bin/bash #!/bin/bash
# #
# Copyright (C) 2017, 2020-2021 The LineageOS Project # SPDX-FileCopyrightText: 2017, 2020-2022 The LineageOS Project
# Copyright (C) 2021-2022 The Calyx Institute # SPDX-FileCopyrightText: 2021-2022 The Calyx Institute
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
usage() { usage() {
echo "Usage ${0} <merge|rebase> <oldaosptag> <newaosptag> <pixel>" echo "Usage ${0} -n <new-tag> -b <branch-suffix> --pixel"
} }
# Verify argument count # Verify argument count
if [ "$#" -ne 4 ]; then if [ "${#}" -eq 0 ]; then
usage usage
exit 1 exit 1
fi fi
OPERATION="${1}" PIXEL=false
OLDTAG="${2}"
NEWTAG="${3}"
PIXEL="${4}"
if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then while [ "${#}" -gt 0 ]; do
case "${1}" in
-n | --new-tag )
NEWTAG="${2}"; shift
;;
-b | --branch-suffix )
BRANCHSUFFIX="${2}"; shift
;;
-p | --pixel )
PIXEL=true; shift
;;
* )
usage usage
exit 1 exit 1
fi ;;
esac
shift
done
### CONSTANTS ### ### CONSTANTS ###
readonly script_path="$(cd "$(dirname "$0")";pwd -P)" readonly script_path="$(cd "$(dirname "$0")";pwd -P)"
@@ -34,8 +45,8 @@ source "${vars_path}/common"
TOP="${script_path}/../../.." TOP="${script_path}/../../.."
BRANCH="${lineageos_branch}" BRANCH="${lineageos_branch}"
STAGINGBRANCH="staging/${BRANCH}_${OPERATION}-${NEWTAG}" STAGINGBRANCH="staging/${BRANCHSUFFIX}"
SQUASHBRANCH="squash/${BRANCH}_${OPERATION}-${NEWTAG}" SQUASHBRANCH="squash/${BRANCHSUFFIX}"
# List of merged repos # List of merged repos
PROJECTPATHS=$(cat ${MERGEDREPOS} | grep -w merge | awk '{printf "%s\n", $2}') PROJECTPATHS=$(cat ${MERGEDREPOS} | grep -w merge | awk '{printf "%s\n", $2}')

View File

@@ -7,24 +7,32 @@
# #
usage() { usage() {
echo "Usage ${0} <merge|rebase> <oldaosptag> <newaosptag> <pixel>" echo "Usage ${0} -b <branch-suffix> --pixel"
} }
# Verify argument count # Verify argument count
if [ "$#" -ne 4 ]; then if [ "${#}" -eq 0 ]; then
usage usage
exit 1 exit 1
fi fi
OPERATION="${1}" PIXEL=false
OLDTAG="${2}"
NEWTAG="${3}"
PIXEL="${4}"
if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then while [ "${#}" -gt 0 ]; do
case "${1}" in
-b | --branch-suffix )
BRANCHSUFFIX="${2}"; shift
;;
-p | --pixel )
PIXEL=true; shift
;;
* )
usage usage
exit 1 exit 1
fi ;;
esac
shift
done
### CONSTANTS ### ### CONSTANTS ###
readonly script_path="$(cd "$(dirname "$0")";pwd -P)" readonly script_path="$(cd "$(dirname "$0")";pwd -P)"
@@ -34,7 +42,7 @@ source "${vars_path}/common"
TOP="${script_path}/../../.." TOP="${script_path}/../../.."
BRANCH="${lineageos_branch}" BRANCH="${lineageos_branch}"
SQUASHBRANCH="squash/${BRANCH}_${OPERATION}-${NEWTAG}" SQUASHBRANCH="squash/${BRANCHSUFFIX}"
if [ "${PIXEL}" = true ]; then if [ "${PIXEL}" = true ]; then
TOPIC="${topic}_pixel" TOPIC="${topic}_pixel"
else else