From c44154f25c07f0f669660eda94055d5cf8dbbd4a Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Sun, 19 Jun 2022 02:54:34 +0300 Subject: [PATCH] aosp-merger: Switch all scripts to argument parsing Change-Id: I7af863d3952e7ae9de16860404bccd2b582caa20 --- aosp-merger/_merge_helper.sh | 45 ++++++++++++++++++++-------- aosp-merger/_subtree_merge_helper.sh | 41 +++++++++++++++++++++---- aosp-merger/aosp-merger.sh | 31 +++++++++---------- aosp-merger/merge-aosp-forks.sh | 37 +++++++++++++++++------ aosp-merger/merge-aosp.sh | 37 +++++++++++++++++------ aosp-merger/push-merge.sh | 26 +++++++++------- aosp-merger/squash.sh | 39 +++++++++++++++--------- aosp-merger/upload-squash.sh | 30 ++++++++++++------- 8 files changed, 197 insertions(+), 89 deletions(-) diff --git a/aosp-merger/_merge_helper.sh b/aosp-merger/_merge_helper.sh index f2e7b7e..0e555b2 100755 --- a/aosp-merger/_merge_helper.sh +++ b/aosp-merger/_merge_helper.sh @@ -7,21 +7,43 @@ # usage() { - echo "Usage ${0} " + echo "Usage ${0} -p -o -c -n -b " } # Verify argument count -if [ "$#" -ne 4 ]; then +if [ "${#}" -eq 0 ]; then usage exit 1 fi -PROJECTPATH="${1}" -OPERATION="${2}" -OLDTAG="${3}" -NEWTAG="${4}" +while [ "${#}" -gt 0 ]; do + case "${1}" in + -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 [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then +if [ -z "${OPERATION}" ]; then + OPERATION="merge" +elif [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then usage exit 1 fi @@ -36,6 +58,7 @@ readonly hook="${script_path}/prepare-commit-msg" TOP="${script_path}/../../.." BRANCH="${lineageos_branch}" +STAGINGBRANCH="staging/${BRANCHSUFFIX}" cd "${TOP}/${PROJECTPATH}" repo start "${STAGINGBRANCH}" . @@ -44,8 +67,6 @@ git fetch -q --force --tags aosp "${NEWTAG}" [[ ! -e .git/hooks/prepare-commit-msg ]] && cp "${hook}" .git/hooks/ chmod +x .git/hooks/prepare-commit-msg -PROJECTOPERATION="${OPERATION}" - # Was there any change upstream? Skip if not. if [[ -z "$(git diff ${OLDTAG} ${NEWTAG})" ]]; then echo -e "nochange\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" @@ -62,7 +83,7 @@ if [[ "$?" -eq 1 ]]; then echo "of new tag ${NEWTAG} ####" fi -if [[ "${PROJECTOPERATION}" == "merge" ]]; then +if [[ "${OPERATION}" == "merge" ]]; then echo "#### Merging ${NEWTAG} into ${PROJECTPATH} ####" git merge --no-commit --log "${NEWTAG}" && git commit --no-edit @@ -73,7 +94,7 @@ if [[ "${PROJECTOPERATION}" == "merge" ]]; then repo abandon "${STAGINGBRANCH}" . exit 0 fi -elif [[ "${PROJECTOPERATION}" == "rebase" ]]; then +elif [[ "${OPERATION}" == "rebase" ]]; then echo "#### Rebasing ${PROJECTPATH} onto ${NEWTAG} ####" git rebase --onto "${NEWTAG}" "${OLDTAG}" fi @@ -82,4 +103,4 @@ CONFLICT="" if [[ -n "$(git status --porcelain)" ]]; then CONFLICT="conflict-" fi -echo -e "${CONFLICT}${PROJECTOPERATION}\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" +echo -e "${CONFLICT}${OPERATION}\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" diff --git a/aosp-merger/_subtree_merge_helper.sh b/aosp-merger/_subtree_merge_helper.sh index fbf938f..38c106d 100755 --- a/aosp-merger/_subtree_merge_helper.sh +++ b/aosp-merger/_subtree_merge_helper.sh @@ -7,18 +7,46 @@ # usage() { - echo "Usage ${0} " + echo "Usage ${0} -p -o -c -n -b " } # Verify argument count -if [ "$#" -ne 3 ]; then +if [ "${#}" -eq 0 ]; then usage exit 1 fi -PROJECTPATH="${1}" -OLDTAG="${2}" -NEWTAG="${3}" +while [ "${#}" -gt 0 ]; do + case "${1}" in + -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 ### readonly script_path="$(cd "$(dirname "$0")";pwd -P)" @@ -30,6 +58,7 @@ readonly hook="${script_path}/prepare-commit-msg" TOP="${script_path}/../../.." BRANCH="${lineageos_branch}" +STAGINGBRANCH="staging/${BRANCHSUFFIX}" cd "${TOP}/${PROJECTPATH}" # Ditch any existing staging branches @@ -104,4 +133,4 @@ if [[ -z "$(git diff HEAD m/${lineageos_branch})" && -z "$(git status --porcelai exit 0 fi -echo -e "${CONFLICT}merge\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" +echo -e "${CONFLICT}${OPERATION}\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" diff --git a/aosp-merger/aosp-merger.sh b/aosp-merger/aosp-merger.sh index 8a73f61..4ee6009 100755 --- a/aosp-merger/aosp-merger.sh +++ b/aosp-merger/aosp-merger.sh @@ -1,6 +1,7 @@ #!/bin/bash # # SPDX-FileCopyrightText: 2022 The Calyx Institute +# SPDX-FileCopyrightText: 2022 The LineageOS Project # # SPDX-License-Identifier: Apache-2.0 # @@ -44,63 +45,59 @@ export LC_TIME=C ### FUNCTIONS ### merge_aosp() { - export STAGINGBRANCH="staging/${common_aosp_tag}_merge-${prev_common_aosp_tag}" - "${script_path}"/merge-aosp.sh merge "${common_aosp_tag}" "${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}" } merge_aosp_forks() { - export STAGINGBRANCH="staging/${lineageos_branch}_merge-${common_aosp_tag}" - "${script_path}"/merge-aosp-forks.sh merge "${prev_common_aosp_tag}" "${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}" } 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() { - "${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() { - "${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() { - export STAGINGBRANCH="staging/${lineageos_branch}_merge-${aosp_tag}" 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 } 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() { - "${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() { - "${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() { - export STAGINGBRANCH="staging/${lineageos_branch}_merge-${kernel_tag}" 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 } 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() { - "${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() { - "${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 diff --git a/aosp-merger/merge-aosp-forks.sh b/aosp-merger/merge-aosp-forks.sh index 8b4ea0c..745f703 100755 --- a/aosp-merger/merge-aosp-forks.sh +++ b/aosp-merger/merge-aosp-forks.sh @@ -7,20 +7,40 @@ # usage() { - echo "Usage ${0} " + echo "Usage ${0} -o -c -n -b " } # Verify argument count -if [ "$#" -ne 3 ]; then +if [ "${#}" -eq 0 ]; then usage exit 1 fi -OPERATION="${1}" -OLDTAG="${2}" -NEWTAG="${3}" +while [ "${#}" -gt 0 ]; do + case "${1}" in + -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 exit 1 fi @@ -34,6 +54,7 @@ source "${vars_path}/common" TOP="${script_path}/../../.." MANIFEST="${TOP}/.repo/manifests/default.xml" BRANCH="${lineageos_branch}" +STAGINGBRANCH="staging/${BRANCHSUFFIX}" # Source build environment (needed for aospremote) source "${TOP}/build/envsetup.sh" @@ -60,7 +81,5 @@ repo abandon "${STAGINGBRANCH}" # Iterate over each forked project 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 - -unset STAGINGBRANCH diff --git a/aosp-merger/merge-aosp.sh b/aosp-merger/merge-aosp.sh index 5471d41..fd403e6 100755 --- a/aosp-merger/merge-aosp.sh +++ b/aosp-merger/merge-aosp.sh @@ -7,21 +7,41 @@ # usage() { - echo "Usage ${0} " + echo "Usage ${0} -o -c -n -b " echo "Example ${0} merge android-12.0.0_r26 android-12.0.0_r18" } # Verify argument count -if [ "$#" -ne 3 ]; then +if [ "${#}" -eq 0 ]; then usage exit 1 fi -OPERATION="${1}" -OLDTAG="${2}" -NEWTAG="${3}" +while [ "${#}" -gt 0 ]; do + case "${1}" in + -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 exit 1 fi @@ -34,6 +54,7 @@ source "${vars_path}/common" TOP="${script_path}/../../.." MANIFEST="${TOP}/.repo/manifests/default.xml" +STAGINGBRANCH="staging/${BRANCHSUFFIX}" # Build list of AOSP repos 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 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 - -unset STAGINGBRANCH diff --git a/aosp-merger/push-merge.sh b/aosp-merger/push-merge.sh index d0b9774..c5656f7 100755 --- a/aosp-merger/push-merge.sh +++ b/aosp-merger/push-merge.sh @@ -7,23 +7,27 @@ # usage() { - echo "Usage ${0} " + echo "Usage ${0} -b " } # Verify argument count -if [ "$#" -ne 3 ]; then +if [ "${#}" -eq 0 ]; then usage exit 1 fi -OPERATION="${1}" -OLDTAG="${2}" -NEWTAG="${3}" - -if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then - usage - exit 1 -fi +while [ "${#}" -gt 0 ]; do + case "${1}" in + -b | --branch-suffix ) + BRANCHSUFFIX="${2}"; shift + ;; + * ) + usage + exit 1 + ;; + esac + shift +done ### CONSTANTS ### readonly script_path="$(cd "$(dirname "$0")";pwd -P)" @@ -33,7 +37,7 @@ source "${vars_path}/common" TOP="${script_path}/../../.." BRANCH="${lineageos_branch}" -STAGINGBRANCH="staging/${BRANCH}_${OPERATION}-${NEWTAG}" +STAGINGBRANCH="staging/${BRANCHSUFFIX}" # Source build environment (needed for lineageremote) source "${TOP}/build/envsetup.sh" diff --git a/aosp-merger/squash.sh b/aosp-merger/squash.sh index 8d8b551..9d35669 100755 --- a/aosp-merger/squash.sh +++ b/aosp-merger/squash.sh @@ -1,30 +1,41 @@ #!/bin/bash # -# Copyright (C) 2017, 2020-2021 The LineageOS Project -# Copyright (C) 2021-2022 The Calyx Institute +# SPDX-FileCopyrightText: 2017, 2020-2022 The LineageOS Project +# SPDX-FileCopyrightText: 2021-2022 The Calyx Institute # # SPDX-License-Identifier: Apache-2.0 # usage() { - echo "Usage ${0} " + echo "Usage ${0} -n -b --pixel" } # Verify argument count -if [ "$#" -ne 4 ]; then +if [ "${#}" -eq 0 ]; then usage exit 1 fi -OPERATION="${1}" -OLDTAG="${2}" -NEWTAG="${3}" -PIXEL="${4}" +PIXEL=false -if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then - usage - exit 1 -fi +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 + exit 1 + ;; + esac + shift +done ### CONSTANTS ### readonly script_path="$(cd "$(dirname "$0")";pwd -P)" @@ -34,8 +45,8 @@ source "${vars_path}/common" TOP="${script_path}/../../.." BRANCH="${lineageos_branch}" -STAGINGBRANCH="staging/${BRANCH}_${OPERATION}-${NEWTAG}" -SQUASHBRANCH="squash/${BRANCH}_${OPERATION}-${NEWTAG}" +STAGINGBRANCH="staging/${BRANCHSUFFIX}" +SQUASHBRANCH="squash/${BRANCHSUFFIX}" # List of merged repos PROJECTPATHS=$(cat ${MERGEDREPOS} | grep -w merge | awk '{printf "%s\n", $2}') diff --git a/aosp-merger/upload-squash.sh b/aosp-merger/upload-squash.sh index 88cd390..f1d2c49 100755 --- a/aosp-merger/upload-squash.sh +++ b/aosp-merger/upload-squash.sh @@ -7,24 +7,32 @@ # usage() { - echo "Usage ${0} " + echo "Usage ${0} -b --pixel" } # Verify argument count -if [ "$#" -ne 4 ]; then +if [ "${#}" -eq 0 ]; then usage exit 1 fi -OPERATION="${1}" -OLDTAG="${2}" -NEWTAG="${3}" -PIXEL="${4}" +PIXEL=false -if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then - usage - exit 1 -fi +while [ "${#}" -gt 0 ]; do + case "${1}" in + -b | --branch-suffix ) + BRANCHSUFFIX="${2}"; shift + ;; + -p | --pixel ) + PIXEL=true; shift + ;; + * ) + usage + exit 1 + ;; + esac + shift +done ### CONSTANTS ### readonly script_path="$(cd "$(dirname "$0")";pwd -P)" @@ -34,7 +42,7 @@ source "${vars_path}/common" TOP="${script_path}/../../.." BRANCH="${lineageos_branch}" -SQUASHBRANCH="squash/${BRANCH}_${OPERATION}-${NEWTAG}" +SQUASHBRANCH="squash/${BRANCHSUFFIX}" if [ "${PIXEL}" = true ]; then TOPIC="${topic}_pixel" else