root/build-tools/patch_rebase_4
Scott Little d2d96619a2 Shorten "addons/wr-cgcs/layers/cgcs" to just "stx"
Part of the project to remove cgcs references.
Replace and shorten the path the needlessly long and
complex "addons/wr-cgcs/layers/cgcs" path with just "stx".

This update just fixes up paths found in scripts, comments
and config files.

Depends-On: https://review.openstack.org/579954
Depends-On: https://review.openstack.org/579957
Depends-On: https://review.openstack.org/580170
Depends-On: https://review.openstack.org/579984
Change-Id: I04d653f740f17d8a9b2732f26d36907f635d8950
Signed-off-by: Scott Little <scott.little@windriver.com>
2018-07-04 15:12:58 -04:00

404 lines
13 KiB
Bash
Executable File

#!/bin/bash
#
# Migrate Titanium Cloud patches to the new package version
#
usage () {
echo ""
echo "Step 4: Migrate Titanium Cloud patches to the new package version"
echo ""
echo "Usage: "
echo " patch_rebase_4 [--origin_branch <branch>] [--working_branch <branch>] [--upversion_data <file>]"
echo ""
echo "Assumes cgcs-centos-repo already has a working_branch commit that sets the new symlinks."
echo ""
echo "The upversion_data file has data on all the src.rpm being updated in the format:"
echo " export UPVERSION_DATA=$MY_WORKSPACE/upversion.log"
echo " PKG=lighttpd"
echo " OLD_SRC_RPM=lighttpd-1.4.41-1.el7.src.rpm"
echo " NEW_SRC_RPM=lighttpd-1.4.41-2.el7.src.rpm"
echo " SRPM_PATH=$MY_REPO/stx/stx-integ/extended/lighttpd/centos/srpm_path"
echo " echo \"\$PKG#\$SRPM_PATH##\$OLD_SRC_RPM#\$NEW_SRC_RPM\" > UPVERSION_DATA"
echo ""
}
TEMP=`getopt -o h --long origin_branch:,working_branch:,upversion_data:,help -n 'test.sh' -- "$@"`
eval set -- "$TEMP"
ORIGIN_BRANCH=""
WORKING_BRANCH=""
UPVERSION_LOG=""
HELP=0
while true ; do
case "$1" in
--origin_branch) shift ; ORIGIN_BRANCH="$1" ; shift ;;
--working_branch) shift ; WORKING_BRANCH="$1" ; shift ;;
--upversion_data) shift ; UPVERSION_LOG="$1" ; shift ;;
-h|--help) HELP=1 ; shift ;;
--) shift ; break ;;
*) usage; exit 1 ;;
esac
done
if [ $HELP -eq 1 ]; then
usage
exit 0
fi
if [ "$UPVERSION_LOG" == "" ]; then
UPVERSION_LOG=$UPVERSION_DATA
fi
if [ "$UPVERSION_LOG" == "" ]; then
echo "ERROR: please specify location of upversion data"
usage
exit 1
fi
if [ ! -f "$UPVERSION_LOG" ]; then
echo "File not found: '$UPVERSION_LOG'"
exit 1
fi
if [ "$ORIGIN_BRANCH" == "" ] && [ "$WORKING_BRANCH" == "" ]; then
ORIGIN_BRANCH=$PATCH_SOURCE_BRANCH
WORKING_BRANCH=$MY_PATCH_BRANCH
fi
if [ "$ORIGIN_BRANCH" == "" ] && [ "$WORKING_BRANCH" == "" ]; then
ORIGIN_BRANCH=$SOURCE_BRANCH
WORKING_BRANCH=$MY_BRANCH
fi
if [ "$ORIGIN_BRANCH" == "" ]; then
echo "ERROR: please specify a origin branch"
usage
exit 1
fi
if [ "$WORKING_BRANCH" == "" ]; then
echo "ERROR: please specify a working branch"
usage
exit 1
fi
if [ "$DISPLAY" == "" ]; then
echo "ERROR: X-Windows 'DISPLAY' variable not set. This script needs to open pop-up windows."
usage
exit 1
fi
# One step back to see the old symlinks
cd $MY_REPO/cgcs-centos-repo
git checkout $WORKING_BRANCH
if [ $? != 0 ]; then
echo "ERROR: Can't checkout branch '$WORKING_BRANCH' in directory '$MY_REPO/cgcs-centos-repo'"
exit 1
fi
FAILED=""
build_types="std rt"
for dat in $(cat $UPVERSION_LOG); do
(
name=$(echo $dat | awk -F '#' '{print $1}')
srpm_path=$(echo $dat | awk -F '#' '{print $2}')
old_src_rpm=$(echo $dat | awk -F '#' '{print $4}')
new_src_rpm=$(echo $dat | awk -F '#' '{print $5}')
PKG_DIR=$(dirname $(dirname $srpm_path))
OLD_BRANCH=$(echo $old_src_rpm | sed 's#[.]src[.]rpm$##')
NEW_BRANCH=$(echo $new_src_rpm | sed 's#[.]src[.]rpm$##')
WORK_META_DIR=""
for dd in $build_types; do
WORK_META_DIR=$MY_WORKSPACE/$dd/srpm_work/$name/rpmbuild
echo "WORK_META_DIR=$WORK_META_DIR"
if [ -d $WORK_META_DIR ]; then
break;
else
WORK_META_DIR=""
fi
done
if [ "$WORK_META_DIR" == "" ]; then
echo "ERROR: failed to find srpm_work directory for '$name'"
exit 1
fi
# WORK_SRC_DIR=$(dirname $(find $MY_WORKSPACE/srpm_work/$name/gits/ -type d -name .git))
NEW_WORK_SRC_DIR=""
OLD_WORK_SRC_DIR=""
for dd in $build_types; do
for g in $(find $MY_WORKSPACE/$dd/srpm_work/$name/gits/ -type d -name .git); do
d=$(dirname $g)
if [ -d $d ]; then
cd $d;
git tag | grep pre_wrs_ >> /dev/null
if [ $? -ne 0 ]; then
continue
fi
git checkout $OLD_BRANCH 2>> /dev/null
if [ $? -eq 0 ]; then
OLD_WORK_SRC_DIR=$d
fi
git checkout $NEW_BRANCH 2>> /dev/null
if [ $? -eq 0 ]; then
NEW_WORK_SRC_DIR=$d
fi
fi
done
done
if [ "$WORK_META_DIR" == "" ]; then
echo "ERROR: failed to find srpm_work directory for '$name'"
exit 1
fi
echo "$name $old_src_rpm $new_src_rpm"
echo "PKG_DIR=$PKG_DIR"
echo "OLD_BRANCH=$OLD_BRANCH"
echo "NEW_BRANCH=$NEW_BRANCH"
echo "WORK_META_DIR=$WORK_META_DIR"
echo "OLD_WORK_SRC_DIR=$OLD_WORK_SRC_DIR"
echo "NEW_WORK_SRC_DIR=$NEW_WORK_SRC_DIR"
echo ""
(
cd $WORK_META_DIR
if [ $? -ne 0 ]; then
echo "ERROR: failed to cd to WORK_META_DIR=$WORK_META_DIR"
exit 1
fi
echo "--- old meta git log (oldest to newest) ---"
git checkout $OLD_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to git checkout OLD_BRANCH=$OLD_BRANCH"
exit 1
fi
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit | tac
PATCH_COMMIT_LIST=$(git log --graph --pretty=format:'%h -%d %s (%ci) <%an>' --abbrev-commit | tac | grep WRS: | grep -v 'WRS: COPY_LIST content' | awk '{ print $2 }')
echo "--- new meta git log (oldest to newest) ---"
git checkout $NEW_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to git checkout NEW_BRANCH=$NEW_BRANCH"
exit 1
fi
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit | tac
REFERENCE_COMMIT=$(git log --graph --pretty=format:'%h -%d %s (%ci) <%an>' --abbrev-commit | head -n 1 | awk '{ print $2 }')
echo ""
for COMMIT in ${PATCH_COMMIT_LIST}; do
echo "git cherry-pick $COMMIT"
git cherry-pick "$COMMIT"
if [ $? -ne 0 ]; then
echo "WARNING: 'git cherry-pick $COMMIT' found merge conflicts. Please fix these files"
git status --porcelain | grep '^UU ' | awk '{ print $2}'
echo "pwd=$(pwd)"
# gitk &
echo "git mergetool --no-prompt"
git mergetool --no-prompt
# for FILE_NAME in $(git status --porcelain | grep '^UU ' | awk '{ print $2}'); do
# xterm -e "vi $FILE_NAME -c '/[<=>][<=>][<=>][<=>]'"
# if [ $? -ne 0 ]; then
# echo "ERROR: problem launching editor on "
# exit 1
# fi
# done
echo "git cherry-pick --continue"
git cherry-pick --continue
fi
done
PATCH_LIST=$(git format-patch -n $REFERENCE_COMMIT)
if [ $? -ne 0 ]; then
echo "ERROR: failed to git format-patch -n REFERENCE_COMMIT=$REFERENCE_COMMIT"
exit 1
fi
for PATCH_FILE in ${PATCH_LIST}; do
PATCH_TARGET=$(echo $PATCH_FILE | sed 's/^[0-9][0-9][0-9][0-9]-WRS-//' | sed 's/.patch$//')
echo "$PATCH_FILE -> $PATCH_TARGET"
N=$(find "$PKG_DIR/centos/meta_patches" -name "$PATCH_TARGET*" | wc -l)
if [ $N -eq 1 ]; then
PATCH_DEST=$(find "$PKG_DIR/centos/meta_patches" -name "$PATCH_TARGET*")
echo "cp -f $PATCH_FILE $PATCH_DEST"
\cp -f $PATCH_FILE $PATCH_DEST
if [ $? -ne 0 ]; then
echo "ERROR: copy failed $WORK_META_DIR/$PATCH_FILE -> $PATCH_DEST"
exit 1
fi
else
echo "ERROR: Don't know what destination file name to use for patch '$WORK_META_DIR/$PATCH_FILE' derived from commit $COMMIT, and to be copied to '$PKG_DIR/centos/meta_patches'"
fi
done
echo ""
echo ""
)
if [ $? -ne 0 ]; then
FAILED=$name
break
fi
(
echo "--- old git log (oldest to newest) ---"
cd $OLD_WORK_SRC_DIR
if [ $? -ne 0 ]; then
echo "ERROR: failed to cd to OLD_WORK_SRC_DIR=$OLD_WORK_SRC_DIR"
exit 1
fi
git checkout $OLD_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to git checkout OLD_BRANCH=$OLD_BRANCH in directory '$OLD_WORK_SRC_DIR'"
exit 1
fi
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit | tac
PATCH_COMMIT_LIST=$(git log --graph --pretty=format:'%h -%d %s (%ci) <%an>' --abbrev-commit | tac | grep WRS: | grep -v 'WRS: COPY_LIST content' | awk '{ print $2 }')
echo "--- new git log (oldest to newest) ---"
cd $NEW_WORK_SRC_DIR
if [ $? -ne 0 ]; then
echo "ERROR: failed to cd to NEW_WORK_SRC_DIR=$NEW_WORK_SRC_DIR"
exit 1
fi
git checkout $NEW_BRANCH
if [ $? -ne 0 ]; then
echo "ERROR: failed to git checkout NEW_BRANCH=$NEW_BRANCH in directory '$NEW_WORK_SRC_DIR'"
exit 1
fi
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit | tac
REFERENCE_COMMIT=$(git log --graph --pretty=format:'%h -%d %s (%ci) <%an>' --abbrev-commit | head -n 1 | awk '{ print $2 }')
echo ""
if [ "$OLD_WORK_SRC_DIR" == "$NEW_WORK_SRC_DIR" ]; then
for COMMIT in ${PATCH_COMMIT_LIST}; do
echo "git cherry-pick $COMMIT"
git cherry-pick "$COMMIT"
if [ $? -ne 0 ]; then
echo "WARNING: 'git cherry-pick $COMMIT' found merge conflicts. Please fix these files"
git status --porcelain | grep '^UU ' | awk '{ print $2}'
echo "pwd=$(pwd)"
# gitk &
echo "git mergetool --no-prompt"
git mergetool --no-prompt
# for FILE_NAME in $(git status --porcelain | grep '^UU ' | awk '{ print $2}'); do
# xterm -e "vi $FILE_NAME -c '/[<=>][<=>][<=>][<=>]'"
# if [ $? -ne 0 ]; then
# echo "ERROR: problem launching editor on "
# exit 1
# fi
# done
echo "git cherry-pick --continue"
git cherry-pick --continue
fi
done
else
cd $OLD_WORK_SRC_DIR
PATCH_LIST=$(git format-patch -n pre_wrs_$OLD_BRANCH)
if [ $? -ne 0 ]; then
echo "ERROR: failed to git format-patch -n REFERENCE_COMMIT=pre_wrs_$OLD_BRANCH"
exit 1
fi
cd $NEW_WORK_SRC_DIR
for PATCH_FILE in ${PATCH_LIST}; do
cat $OLD_WORK_SRC_DIR/$PATCH_FILE | patch -p1
if [ $? -ne 0 ]; then
for REJECT in $(find . -name '*.rej'); do
FILE_NAME=$(echo $REJECT | sed 's#.rej$##')
cd $OLD_WORK_SRC_DIR
gitk $FILE_NAME &
cd $NEW_WORK_SRC_DIR
if [ -f $FILE_NAME ] && [ -f $FILE_NAME.orig ]; then
\cp -f $FILE_NAME.orig $FILE_NAME
xterm -e "vi $FILE_NAME $REJECT"
rm -f $REJECT
rm -f $FILE_NAME.orig
fi
done
fi
git add --all
MSG=$(echo $PATCH_FILE | sed 's/^[0-9][0-9][0-9][0-9]-WRS-//' | sed 's/.patch$//')
git commit -m "WRS: $MSG"
done
fi
PATCH_LIST=$(git format-patch -n $REFERENCE_COMMIT)
if [ $? -ne 0 ]; then
echo "ERROR: failed to git format-patch -n REFERENCE_COMMIT=$REFERENCE_COMMIT"
exit 1
fi
for PATCH_FILE in ${PATCH_LIST}; do
PATCH_TARGET=$(echo $PATCH_FILE | sed 's/^[0-9][0-9][0-9][0-9]-WRS-Patch[0-9]*-//' | sed 's/^[0-9][0-9][0-9][0-9]-WRS-Patch//' | sed 's/.patch$//')
echo "$PATCH_FILE -> $PATCH_TARGET"
PKG_PATCH_DIR="$PKG_DIR/centos/patches"
N=0
if [ -d "$PKG_PATCH_DIR" ]; then
N=$(find "$PKG_PATCH_DIR" -name "$PATCH_TARGET*" | grep -v '[/]meta_patches[/]' | wc -l)
fi
if [ $N -ne 1 ]; then
PKG_PATCH_DIR="$PKG_DIR"
if [ -d "$PKG_PATCH_DIR" ]; then
N=$(find "$PKG_PATCH_DIR" -name "$PATCH_TARGET*" | grep -v '[/]meta_patches[/]' | wc -l)
fi
fi
echo "N=$N"
echo "PKG_PATCH_DIR=$PKG_PATCH_DIR"
if [ $N -eq 1 ]; then
PATCH_DEST=$(find "$PKG_PATCH_DIR" -name "$PATCH_TARGET*" | grep -v '[/]meta_patches[/]')
echo "meld $PATCH_FILE -> $PATCH_DEST"
meld $PATCH_FILE $PATCH_DEST
if [ $? -ne 0 ]; then
echo "ERROR: meld failed $WORK_SRC_DIR/$PATCH_FILE -> $PATCH_DEST"
exit 1
fi
else
echo "ERROR: Don't know what destination file name to use for patch '$OLD_WORK_SRC_DIR/$PATCH_FILE', and to be copied to '$PKG_PATCH_DIR'"
fi
done
echo ""
echo ""
)
if [ $? -ne 0 ]; then
FAILED=$name
break
fi
)
done
if [ "$FAILED" != "" ]; then
echo "Failed for ... $FAILED"
exit 1
fi
echo ""
for d in $(for dat in $(cat $UPVERSION_LOG); do srpm_path=$(echo $dat | awk -F '#' '{print $2}'); ( cd $(dirname $srpm_path); git rev-parse --show-toplevel ); done | sort --unique); do
(
cd $d
echo "cd $d"
for f in $(git status --porcelain | awk '{print $2}'); do
echo "git add $f";
done
if [ "$PATCH_ID" == "" ]; then
echo "git commit -m 'rebased patches'"
else
echo "git commit -m 'rebased patches for patch $PATCH_ID'"
fi
)
done
echo ""