scripts: Add simplified AOSP merger
Usage: ./lineage/scripts/aosp-merger/aosp-merger.sh [merge|rebase] <oldaosptag> <newaosptag> Change-Id: I6663e51ee22d7ea262ef634ed5e33c189ee1c2d6
This commit is contained in:
committed by
Kevin Haggerty
parent
2e187ce924
commit
ccde24991f
33
aosp-merger/README.md
Normal file
33
aosp-merger/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Rough workflow
|
||||
|
||||
1. Snapshot the names of your current working branches to `branches.list` file:
|
||||
|
||||
./lineage/scripts/aosp-merge/branches_save.sh
|
||||
|
||||
2. Note current aosp tag in `.repo/manifests/default.xml`, update it to desired new tag and then create a local commit for the change (aosp-merge script checks for any uncommitted changes in the `.repo/manifests` git repo).
|
||||
3. Create a staging branch and merge in the new AOSP tag:
|
||||
|
||||
./lineage/scripts/aosp-merge/aosp-merge.sh merge \<oldaosptag> \<newaosptag>
|
||||
(where oldaosptag is the original AOSP tag that was in `.repo/manifests/default.xml`)
|
||||
* Example invocation:
|
||||
|
||||
./lineage/scripts/aosp-merge/aosp-merge.sh merge android-8.0.0_r3 android-8.0.0_r30
|
||||
|
||||
4. Every project in your tree should now be one of:
|
||||
* \<newaosptag> if the project was tracking AOSP
|
||||
* a staging branch if the project was a LineageOS fork from AOSP (check `merged_repos.txt` for status and whether there are conflicts to resolve)
|
||||
* the default repo lineage branch for `.repo/manifests/snippets.xml` projects
|
||||
5. Restore your local branches and merge in the staging branch:
|
||||
|
||||
./lineage/scripts/aosp-merge/branches_rebase.sh \<nameofstagingbranch>
|
||||
* Example invocation:
|
||||
|
||||
./lineage/scripts/aosp-merge/branches_rebase.sh staging/lineage-15.0_merge-android-8.0.0_r30
|
||||
6. Build, install, boot, verify, etc.
|
||||
|
||||
# TODO
|
||||
|
||||
* Make it work for rebase (I'm sure it'll need fixups).
|
||||
* Create squashed gerrits for each merge.
|
||||
* Abandon squashed gerrits and push each merge automatically.
|
||||
* DONE. Instead of merging the staging branch into your local branch (if you have one), create a new branch for the local+staging merge.
|
||||
124
aosp-merger/aosp-merger.sh
Executable file
124
aosp-merger/aosp-merger.sh
Executable file
@@ -0,0 +1,124 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2017 The LineageOS Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
usage() {
|
||||
echo "Usage ${0} <merge|rebase> <oldaosptag> <newaosptag>"
|
||||
}
|
||||
|
||||
# Verify argument count
|
||||
if [ "$#" -ne 3 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OPERATION="${1}"
|
||||
OLDTAG="${2}"
|
||||
NEWTAG="${3}"
|
||||
|
||||
if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check to make sure this is being run from the top level repo dir
|
||||
if [ ! -e "build/envsetup.sh" ]; then
|
||||
echo "Must be run from the top level repo dir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source build environment (needed for aospremote)
|
||||
. build/envsetup.sh
|
||||
|
||||
TOP="${ANDROID_BUILD_TOP}"
|
||||
MERGEDREPOS="${TOP}/merged_repos.txt"
|
||||
MANIFEST="${TOP}/.repo/manifest.xml"
|
||||
BRANCH=$(grep "default revision" "${MANIFEST}" \
|
||||
| sed 's/^ *//g;s/<default revision=\"refs\/heads\///g;s/\"//g')
|
||||
STAGINGBRANCH="staging/${BRANCH}_${OPERATION}-${NEWTAG}"
|
||||
|
||||
# Build list of LineageOS forked repos
|
||||
PROJECTPATHS=$(grep "name=\"LineageOS/" "${MANIFEST}" | sed -n 's/.*path="\([^"]\+\)".*/\1/p')
|
||||
|
||||
echo "#### Old tag = ${OLDTAG} Branch = ${BRANCH} Staging branch = ${STAGINGBRANCH} ####"
|
||||
|
||||
# Make sure manifest and forked repos are in a consistent state
|
||||
echo "#### Verifying there are no uncommitted changes on LineageOS forked AOSP projects ####"
|
||||
for PROJECTPATH in ${PROJECTPATHS} .repo/manifests; do
|
||||
cd "${TOP}/${PROJECTPATH}"
|
||||
if [[ -n "$(git status --porcelain)" ]]; then
|
||||
echo "Path ${PROJECTPATH} has uncommitted changes. Please fix."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo "#### Verification complete - no uncommitted changes found ####"
|
||||
|
||||
# Remove any existing list of merged repos file
|
||||
rm -f "${MERGEDREPOS}"
|
||||
|
||||
# Sync and detach from current branches
|
||||
repo sync -d
|
||||
|
||||
# Ditch any existing staging branches (across all projects)
|
||||
repo abandon "${STAGINGBRANCH}"
|
||||
|
||||
# Iterate over each forked project
|
||||
for PROJECTPATH in ${PROJECTPATHS}; do
|
||||
cd "${TOP}/${PROJECTPATH}"
|
||||
repo start "${STAGINGBRANCH}" .
|
||||
aospremote | grep -v "Remote 'aosp' created"
|
||||
git fetch -q --tags aosp "${NEWTAG}"
|
||||
|
||||
PROJECTOPERATION="${OPERATION}"
|
||||
|
||||
# Check if we've actually changed anything before attempting to merge
|
||||
# If we haven't, just "git reset --hard" to the tag
|
||||
if [[ -z "$(git diff HEAD ${OLDTAG})" ]]; then
|
||||
git reset --hard "${NEWTAG}"
|
||||
echo -e "reset\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Was there any change upstream? Skip if not.
|
||||
if [[ -z "$(git diff ${OLDTAG} ${NEWTAG})" ]]; then
|
||||
echo -e "nochange\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Determine whether OLDTAG is an ancestor of NEWTAG
|
||||
# ie is history consistent.
|
||||
git merge-base --is-ancestor "${OLDTAG}" "${NEWTAG}"
|
||||
# If no, force rebase.
|
||||
if [[ "$?" -eq 1 ]]; then
|
||||
echo -n "#### Project ${PROJECTPATH} old tag ${OLD} is not an ancestor "
|
||||
echo "of new tag ${NEWTAG}, forcing rebase ####"
|
||||
PROJECTOPERATION="rebase"
|
||||
fi
|
||||
|
||||
if [[ "${PROJECTOPERATION}" == "merge" ]]; then
|
||||
echo "#### Merging ${NEWTAG} into ${PROJECTPATH} ####"
|
||||
git merge --no-edit --log "${NEWTAG}"
|
||||
elif [[ "${PROJECTOPERATION}" == "rebase" ]]; then
|
||||
echo "#### Rebasing ${PROJECTPATH} onto ${NEWTAG} ####"
|
||||
git rebase --onto "${NEWTAG}" "${OLDTAG}"
|
||||
fi
|
||||
|
||||
CONFLICT=""
|
||||
if [[ -n "$(git status --porcelain)" ]]; then
|
||||
CONFLICT="conflict-"
|
||||
fi
|
||||
echo -e "${CONFLICT}${PROJECTOPERATION}\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}"
|
||||
done
|
||||
68
aosp-merger/branches_rebase.sh
Executable file
68
aosp-merger/branches_rebase.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2017 The LineageOS Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#####
|
||||
# Rebase your local working branches onto a new "upstream" branch.
|
||||
# Local branch list is defined in branches.list
|
||||
# (and can be created with branches_save.sh)
|
||||
# If the upstream branch doesn't exist (eg perhaps in lineage-sdk),
|
||||
# simply switch the working branch instead.
|
||||
|
||||
if [ ! -e "build/envsetup.sh" ]; then
|
||||
echo "Must run from root of repo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage ${0} <branch to rebase on top of>"
|
||||
exit 1
|
||||
fi
|
||||
REBASEONTO="${1}"
|
||||
|
||||
TOP="${PWD}"
|
||||
BRANCHLIST="${TOP}/branches.list"
|
||||
|
||||
cat "${BRANCHLIST}" | while read l; do
|
||||
set ${l}
|
||||
PROJECTPATH="${1}"
|
||||
BRANCH="${2}"
|
||||
NEWBRANCH="${2}-rebase"
|
||||
cd "${TOP}/${PROJECTPATH}"
|
||||
|
||||
# Sanity check
|
||||
[[ -n "$(git status --porcelain)" ]]; then
|
||||
echo -n "!!!! Project ${PROJECTPATH} has uncommitted files, "
|
||||
echo "not switching to branch ${BRANCH} (skipping) !!!!"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check the $REBASEONTO branch actually exists
|
||||
git show-ref "refs/heads/${REBASEONTO}" >/dev/null
|
||||
if [ "$?" -ne 0 ]; then
|
||||
# Nope
|
||||
echo -n "#### Project ${PROJECTPATH} branch ${REBASEONTO} does not exist, "
|
||||
echo "switching to ${BRANCH} instead ####"
|
||||
git checkout "${BRANCH}"
|
||||
else
|
||||
echo "#### Creating ${PROJECTPATH} branch ${NEWBRANCH} from ${BRANCH} ####"
|
||||
repo abandon "${NEWBRANCH}" .
|
||||
repo start "${NEWBRANCH}" .
|
||||
git reset --hard "${BRANCH}"
|
||||
echo -n "#### Project ${PROJECTPATH} Rebasing branch ${NEWBRANCH} "
|
||||
echo "on top of ${REBASEONTO} ####"
|
||||
git rebase --onto "${REBASEONTO}"
|
||||
fi
|
||||
done
|
||||
48
aosp-merger/branches_restore.sh
Executable file
48
aosp-merger/branches_restore.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2017 The LineageOS Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if [ ! -e "build/envsetup.sh" ]; then
|
||||
echo "Must run from root of repo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TOP="${PWD}"
|
||||
BRANCHLIST="${TOP}/branches.list"
|
||||
|
||||
cat "${BRANCHLIST}" | while read l; do
|
||||
set ${l}
|
||||
PROJECTPATH="${1}"
|
||||
BRANCH="${2}"
|
||||
cd "${TOP}/${PROJECTPATH}"
|
||||
|
||||
# Check if we're on this branch already
|
||||
CURBRANCH=$(git status -b --porcelain | head -1 | awk '{print $2}' | sed 's/\.\.\..*//')
|
||||
if [ "${CURBRANCH}" == "${BRANCH}" ]; then
|
||||
echo "#### Project ${PROJECTPATH} is already on branch ${BRANCH} ####"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Sanity check
|
||||
if [[ -n "$(git status --porcelain)" ]]; then
|
||||
echo -n "#!#! Project ${PROJECTPATH} has uncommitted files, "
|
||||
echo "not switching to branch ${BRANCH} #!#!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "#### Project ${PROJECTPATH} Switching to branch ${BRANCH} ####"
|
||||
git checkout "${BRANCH}"
|
||||
done
|
||||
35
aosp-merger/branches_save.sh
Executable file
35
aosp-merger/branches_save.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2017 The LineageOS Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if [ ! -e "build/envsetup.sh" ]; then
|
||||
echo "Must run from root of repo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TOP="${PWD}"
|
||||
BRANCHLIST="${TOP}/branches.list"
|
||||
|
||||
# Example repo status output:
|
||||
#project build/make/ branch x
|
||||
#project device/huawei/angler/ branch x
|
||||
|
||||
repo status | grep '^project ' | while read l; do
|
||||
set ${l}
|
||||
PROJECTPATH=$(echo ${2} | sed 's|/$||')
|
||||
BRANCH="${4}"
|
||||
echo "${PROJECTPATH} ${BRANCH}"
|
||||
done | sort > "${BRANCHLIST}"
|
||||
Reference in New Issue
Block a user