diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2018-01-17 13:29:06 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2018-01-22 17:09:17 +0000 |
commit | 6670c6bf3479e255fb54289e70435716de04a746 (patch) | |
tree | 2798c389cd17d212c8e5cdd6f0c1446f982dde0c /tcwg-upstream2gerrit.sh | |
parent | b2cf594b653489b13b5c88bc850303ec8014220c (diff) |
tcwg-upstream2gerrit.sh: Proof-of-concept script to test upstream patches
Change-Id: I158f1927126c8e9bac22a7ec5956bfa956989cd4
Diffstat (limited to 'tcwg-upstream2gerrit.sh')
-rwxr-xr-x | tcwg-upstream2gerrit.sh | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/tcwg-upstream2gerrit.sh b/tcwg-upstream2gerrit.sh new file mode 100755 index 00000000..88899321 --- /dev/null +++ b/tcwg-upstream2gerrit.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +set -ex + +# Make shellcheck happy and workaround Jenkins not defining variables +# for empty arguments. +branch="${branch:-master}" +patches="${patches:-last}" +project="${project:-gcc}" +squash="${squash:-false}" + +# Jenkins doesn't define variables when parameter value is empty (like cflags), +# so enable "set -u" only after above binding of variables. +set -u + +. jenkins-helpers.sh + +rm -f pwclient +wget http://people.linaro.org/~maxim.kuvyrkov/pwclient/pwclient + +pwc="$(pwd)/pwclient" +chmod +x "$pwc" +sed -i -e "s#~/.pwclientrc#$(pwd)/pwclientrc#g" "$pwc" +cat > pwclientrc <<EOF +[options] +default=$project + +[$project] +url= https://patches-$project.linaro.org/xmlrpc/ +EOF + +last_id=$($pwc list -N 1 -f %{id}) +if [ "$last_id" = "" ]; then + echo "ERROR: Cannot fetch last patch id." + exit 1 +fi + +patches=$(echo "$patches" | sed -e "s/last/$last_id/g") + +clone_or_update_repo $project refs/heads/$branch https://git-us.linaro.org/toolchain/$project + +cd $project +cat > .gitreview <<EOF +[gerrit] +host=review.linaro.org +port=29418 +project=toolchain/$project +EOF +git review -s +rm .gitreview + +case "$project" in + "gcc") + # Attempt to apply patches to nested gcc/ directory if top-level + # fails. + try_dirs=". gcc" + ;; + *) try_dirs="." ;; +esac + +patch_file=$(mktemp) +trap "rm -f $patch_file" EXIT + +count="0" +for patch in $patches; do + download_file=$($pwc get -p $project $patch | sed -e "s/Saved patch to //") + mv $download_file $patch_file + + res=0 + git reset --hard + git clean -df + if grep -q "diff --git" $patch_file; then + git am $patch_file || res=$? + if [ "$res" = "0" ]; then + git commit --amend --reset-author -C HEAD + fi + else + for dir in $try_dirs; do + pushd $dir + git reset --hard + git clean -df + patch -f -p0 < $patch_file || res=$? + if [ "$res" = "0" ]; then + git add . + git reset $patch_file + git commit -m "Patch #$patch" + fi + popd + if [ "$res" = "0" ]; then + break + fi + done + fi + if [ "$res" != "0" ]; then + echo "ERROR: Cannot apply patch $patch" + exit 1 + fi + count=$(($count+1)) +done + +if $squash; then + git reset --soft HEAD~$count + git commit -m "Patches: $patches" +fi +git review -y "$branch" |