make_upstream_revert_noop.sh (4175B)
1 #!/bin/bash 2 3 # This script takes the current base sha, the next base sha, and the sha 4 # of the commit that reverts the next base as determined by 5 # detect_upstream_revert.sh and "inserts" two commits at the bottom of the 6 # moz_libwebrtc GitHub patch stack. The two commits are exact copies of 7 # the upcoming commit and its corresponding revert commit, with commit 8 # messages indicating they are temporary commits. Additionally, 2 files 9 # are written that act as markers for the fast-forward script and contain 10 # supplemental commit message text. 11 # 12 # When the fast-forward script runs, it will rebase onto the next base 13 # sha. Since we have a corresponding, identical temp commit at the bottom 14 # of our patch stack, the temp commit will be absorbed as unnecessary. 15 # Since the patch stack now has the temp revert commit at the bottom, this 16 # results in a “no-op” commit. The marker file indicates that specially 17 # handling should occur in the fast-forward-libwebrtc.sh and loop-ff.sh 18 # scripts. This special handling includes adding the supplemental commit 19 # text that explains why the commit is a no-op (or empty) commit and 20 # skipping the verification of the number of files changed between our 21 # mercurial repository and the GitHub repository. 22 23 function show_error_msg() 24 { 25 echo "*** ERROR *** $? line $1 $0 did not complete successfully!" 26 echo "$ERROR_HELP" 27 } 28 ERROR_HELP="" 29 30 # Print an Error message if `set -eE` causes the script to exit due to a failed command 31 trap 'show_error_msg $LINENO' ERR 32 33 source dom/media/webrtc/third_party_build/use_config_env.sh 34 35 # If DEBUG_GEN is set all commands should be printed as they are executed 36 if [ ! "x$DEBUG_GEN" = "x" ]; then 37 set -x 38 fi 39 40 if [ "x$MOZ_LIBWEBRTC_SRC" = "x" ]; then 41 echo "MOZ_LIBWEBRTC_SRC is not defined, see README.md" 42 exit 43 fi 44 45 if [ -d $MOZ_LIBWEBRTC_SRC ]; then 46 echo "MOZ_LIBWEBRTC_SRC is $MOZ_LIBWEBRTC_SRC" 47 else 48 echo "Path $MOZ_LIBWEBRTC_SRC is not found, see README.md" 49 exit 50 fi 51 52 if [ "x$MOZ_LIBWEBRTC_BRANCH" = "x" ]; then 53 echo "MOZ_LIBWEBRTC_BRANCH is not defined, see README.md" 54 exit 55 fi 56 57 # After this point: 58 # * eE: All commands should succeed. 59 # * u: All variables should be defined before use. 60 # * o pipefail: All stages of all pipes should succeed. 61 set -eEuo pipefail 62 63 find_base_commit 64 find_next_commit 65 echo "MOZ_LIBWEBRTC_BASE: $MOZ_LIBWEBRTC_BASE" 66 echo "MOZ_LIBWEBRTC_NEXT_BASE: $MOZ_LIBWEBRTC_NEXT_BASE" 67 echo "MOZ_LIBWEBRTC_REVERT_SHA: $MOZ_LIBWEBRTC_REVERT_SHA" 68 69 # These files serve dual purposes: 70 # 1) They serve as marker/indicator files to loop-ff.sh to 71 # know to process the commit differently, accounting for 72 # the no-op nature of the commit and it's corresponding 73 # revert commit. 74 # 2) The contain supplemental commit message text to explain 75 # why the commits are essentially empty. 76 # They are written first on the off chance that the rebase 77 # operation below fails and requires manual intervention, 78 # thus avoiding the operator of these scripts to remember to 79 # generate these two files. 80 echo $"Essentially a no-op since we're going to see this change 81 reverted when we vendor in $MOZ_LIBWEBRTC_REVERT_SHA." \ 82 > $STATE_DIR/$MOZ_LIBWEBRTC_NEXT_BASE.no-op-cherry-pick-msg 83 84 echo "We already cherry-picked this when we vendored $MOZ_LIBWEBRTC_NEXT_BASE." \ 85 > $STATE_DIR/$MOZ_LIBWEBRTC_REVERT_SHA.no-op-cherry-pick-msg 86 87 cd $MOZ_LIBWEBRTC_SRC 88 git checkout -b moz-cherry-pick $MOZ_LIBWEBRTC_BASE 89 90 COMMIT_MSG_FILE=$TMP_DIR/commit.msg 91 92 # build commit message with annotated summary 93 git show --format='%s%n%n%b' --no-patch $MOZ_LIBWEBRTC_NEXT_BASE > $COMMIT_MSG_FILE 94 ed -s $COMMIT_MSG_FILE <<EOF 95 1,s/^\(.*\)$/(tmp-cherry-pick) & ($MOZ_LIBWEBRTC_NEXT_BASE)/ 96 w 97 q 98 EOF 99 git cherry-pick --no-commit $MOZ_LIBWEBRTC_NEXT_BASE 100 git commit --file $COMMIT_MSG_FILE 101 102 # build commit message with annotated summary 103 git show --format='%s%n%n%b' --no-patch $MOZ_LIBWEBRTC_REVERT_SHA > $COMMIT_MSG_FILE 104 ed -s $COMMIT_MSG_FILE <<EOF 105 1,s/^\(.*\)$/(tmp-cherry-pick) & ($MOZ_LIBWEBRTC_REVERT_SHA)/ 106 w 107 q 108 EOF 109 git cherry-pick --no-commit $MOZ_LIBWEBRTC_REVERT_SHA 110 git commit --file $COMMIT_MSG_FILE 111 112 git checkout $MOZ_LIBWEBRTC_BRANCH 113 git rebase moz-cherry-pick 114 git branch -d moz-cherry-pick