build_no_op_commits.sh (8717B)
1 #!/bin/bash 2 3 function show_error_msg() 4 { 5 echo "*** ERROR *** $? line $1 $0 did not complete successfully!" 6 echo "$ERROR_HELP" 7 } 8 ERROR_HELP="" 9 10 # Print an Error message if `set -eE` causes the script to exit due to a failed command 11 trap 'show_error_msg $LINENO' ERR 12 13 source dom/media/webrtc/third_party_build/use_config_env.sh 14 15 echo "MOZ_LIBWEBRTC_SRC: $MOZ_LIBWEBRTC_SRC" 16 17 # After this point: 18 # * eE: All commands should succeed. 19 # * u: All variables should be defined before use. 20 # * o pipefail: All stages of all pipes should succeed. 21 set -eEuo pipefail 22 23 CURRENT_DIR=`pwd` 24 cd $MOZ_LIBWEBRTC_SRC 25 26 MANUAL_INTERVENTION_COMMIT_FILE="$TMP_DIR/manual_commits.txt" 27 rm -f $MANUAL_INTERVENTION_COMMIT_FILE 28 29 # find the last upstream commit used by the previous update, so we don't 30 # accidentally grab release branch commits that were added after we started 31 # the previous update. 32 LAST_UPSTREAM_COMMIT_SHA=`tail -1 $CURRENT_DIR/third_party/libwebrtc/README.mozilla.last-vendor` 33 echo "previous update's last commit: $LAST_UPSTREAM_COMMIT_SHA" 34 35 # Find the common commit between our previous work branch and trunk 36 CURRENT_RELEASE_BASE=`git merge-base $LAST_UPSTREAM_COMMIT_SHA master` 37 38 # Write no-op files for the cherry-picked release branch commits. For more 39 # details on what this is doing, see make_upstream_revert_noop.sh. 40 COMMIT_RANGE="$CURRENT_RELEASE_BASE..$LAST_UPSTREAM_COMMIT_SHA" 41 echo "" 42 echo "Libwebrtc release branch commits are usually cherry-picked from upcoming" 43 echo "commits. Since these upcoming commits will result in near-zero files" 44 echo "changed, hopefully exactly 0, we need to build no-op commit files" 45 echo "so that processing doesn't stop unnecessarily when running the" 46 echo "fast-forward process." 47 echo "Previous update (Bug $MOZ_PRIOR_FASTFORWARD_BUG) release branch commits:" 48 # might be nice to indent this output for better readability 49 git log $COMMIT_RANGE --oneline 50 51 COMMITS=`git log -r $COMMIT_RANGE --format='%h'` 52 for commit in $COMMITS; do 53 54 echo "Processing release branch commit $commit for no-op handling" 55 56 # Don't process the commit if the commit message is missing the customary 57 # line that shows which upstream commit is being cherry-picked. 58 CNT=`git show $commit | grep "cherry picked from commit" | wc -l | tr -d " " || true` 59 if [ $CNT != 1 ]; then 60 # record the commit to list at the end of this script as 61 # 'needing intervention' 62 echo " no cherry-pick info found, skipping commit $commit" 63 echo "$commit" >> $MANUAL_INTERVENTION_COMMIT_FILE 64 continue 65 fi 66 67 CHERRY_PICK_COMMIT=`git show $commit | grep "cherry picked from commit" | tr -d "()" | awk '{ print $5; }'` 68 69 # I didn't think this was possible due to the automated tooling on 70 # Google's end, but upstream commit 71 # 847fe7905954f3ae883de2936415ff567aa9039b lists that it cherry-picks 72 # 602b06b1125ea4d107fbfbda7d314b4157c4c74b. However, 73 # 602b06b1125ea4d107fbfbda7d314b4157c4c74b doesn't exist in the repo. 74 # That means we need to verify that we have a valid commit before 75 # processing further. If not found we'll add it to the list of 76 # commits that need manual intervention/verification. 77 CHERRY_PICK_COMMIT_FOUND=`(git cat-file -e $CHERRY_PICK_COMMIT && echo "commit-found") || true` 78 if [ "x$CHERRY_PICK_COMMIT_FOUND" != "xcommit-found" ]; then 79 # record the commit to list at the end of this script as 80 # 'needing intervention' 81 echo " cherry-pick sha ($CHERRY_PICK_COMMIT) in commit message," 82 echo " but, the sha is not found in the libwebrtc repo." 83 echo " skipping commit $commit" 84 echo "$commit" >> $MANUAL_INTERVENTION_COMMIT_FILE 85 continue 86 fi 87 88 SHORT_SHA=`git show --name-only $CHERRY_PICK_COMMIT --format='%h' | head -1` 89 echo " commit $commit cherry-picks $SHORT_SHA" 90 91 echo "We already cherry-picked this when we vendored $commit." \ 92 > $STATE_DIR/$SHORT_SHA.no-op-cherry-pick-msg 93 94 done 95 96 # This section checks for commits that may have been cherry-picked in 97 # more than one release branch. An example of multiple cherry-picks 98 # across release branches can be seen when starting the following 99 # updates: 100 # Bug 1934695 - updated default_config_env for v132 101 # Bug 1903098 - updated default_config_env for v126 (this is moz 102 # cherry-pick that is then cherry-picked in the upcoming release 103 # branch) 104 105 TARGET_RELEASE_BASE=`git merge-base $MOZ_TARGET_UPSTREAM_BRANCH_HEAD master` 106 107 COMMIT_RANGE="$TARGET_RELEASE_BASE..$MOZ_TARGET_UPSTREAM_BRANCH_HEAD" 108 echo "" 109 echo "Occasionally, successive libwebrtc release branches need to cherry-pick" 110 echo "the same _far_ upstream commit. We need to examine the upcoming release" 111 echo "branch commits for our new v$MOZ_NEXT_LIBWEBRTC_MILESTONE update." 112 echo "Upcoming (Bug $MOZ_FASTFORWARD_BUG) release branch commits:" 113 # might be nice to indent this output for better readability 114 git log $COMMIT_RANGE --oneline 115 116 # Convert the files that we've already generated for no-op detection into 117 # something that we can use as a regular expression for searching. 118 KNOWN_NO_OP_COMMITS=`cd $STATE_DIR ; \ 119 ls *.no-op-cherry-pick-msg \ 120 | sed 's/\.no-op-cherry-pick-msg//' \ 121 | paste -sd '|' /dev/stdin` 122 123 NEW_COMMITS=`git log -r $COMMIT_RANGE --format='%h'` 124 for commit in $NEW_COMMITS; do 125 126 echo "Processing next release branch commit $commit for no-op handling" 127 128 # Don't process the commit if the commit message is missing the customary 129 # line that shows which upstream commit is being cherry-picked. 130 CNT=`git show $commit | grep "cherry picked from commit" | wc -l | tr -d " " || true` 131 if [ $CNT != 1 ]; then 132 # record the commit to list at the end of this script as 133 # 'needing intervention' 134 echo " no cherry-pick info found, skipping commit $commit" 135 echo "$commit" >> $MANUAL_INTERVENTION_COMMIT_FILE 136 continue 137 fi 138 139 CHERRY_PICK_COMMIT=`git show $commit | grep "cherry picked from commit" | tr -d "()" | awk '{ print $5; }'` 140 141 # I didn't think this was possible due to the automated tooling on 142 # Google's end, but upstream commit 143 # 847fe7905954f3ae883de2936415ff567aa9039b lists that it cherry-picks 144 # 602b06b1125ea4d107fbfbda7d314b4157c4c74b. However, 145 # 602b06b1125ea4d107fbfbda7d314b4157c4c74b doesn't exist in the repo. 146 # That means we need to verify that we have a valid commit before 147 # processing further. If not found we'll add it to the list of 148 # commits that need manual intervention/verification. 149 CHERRY_PICK_COMMIT_FOUND=`(git cat-file -e $CHERRY_PICK_COMMIT && echo "commit-found") || true` 150 if [ "x$CHERRY_PICK_COMMIT_FOUND" != "xcommit-found" ]; then 151 # record the commit to list at the end of this script as 152 # 'needing intervention' 153 echo " cherry-pick sha ($CHERRY_PICK_COMMIT) found in commit" 154 echo " message, but the sha is not found in the libwebrtc repo." 155 echo " skipping commit $commit" 156 echo "$commit" >> $MANUAL_INTERVENTION_COMMIT_FILE 157 continue 158 fi 159 160 SHORT_SHA=`git show --name-only $CHERRY_PICK_COMMIT --format='%h' | head -1` 161 162 # The trick here is that we only want to include no-op processing for the 163 # commits that appear both here _and_ in the previous release's cherry-pick 164 # commits. We check the known list of no-op commits to see if it was 165 # cherry picked in the previous release branch and then create another 166 # file for the new release branch commit that will ultimately be a no-op. 167 if [[ "$SHORT_SHA" =~ ^($KNOWN_NO_OP_COMMITS)$ ]]; then 168 echo " commit $commit cherry-picks $SHORT_SHA" 169 cp $STATE_DIR/$SHORT_SHA.no-op-cherry-pick-msg $STATE_DIR/$commit.no-op-cherry-pick-msg 170 fi 171 172 done 173 174 if [ ! -f $MANUAL_INTERVENTION_COMMIT_FILE ]; then 175 echo "" 176 echo "No commits require manual intervention" 177 exit 178 fi 179 180 echo $" 181 Each of the following commits requires manual intervention to 182 verify the source of the cherry-pick or there may be errors 183 reported during the fast-forward processing. Without this 184 intervention, the common symptom is that the vendored commit 185 file count (0) will not match the upstream commit file count. 186 187 In some cases, these commits may be listed because invalid 188 cherry-pick info (not simply missing info) is present in the 189 commit message. 190 " 191 192 for commit in `cat $MANUAL_INTERVENTION_COMMIT_FILE`; do 193 SUMMARY=`git show --oneline --name-only $commit | head -1` 194 echo " '$SUMMARY'" 195 done 196 197 echo $" 198 To manually create the no-op tracking files needed, 199 run the following command (in bash) for each commit in question: 200 ( export FUTURE_UPSTREAM_COMMIT=\"{short-sha-of-upstream-commit}\" ; \\ 201 export ALREADY_USED_COMMIT=\"{short-sha-of-already-used-commit}\" ; \\ 202 echo \"We already cherry-picked this when we vendored \$ALREADY_USED_COMMIT.\" \\ 203 > $STATE_DIR/\$FUTURE_UPSTREAM_COMMIT.no-op-cherry-pick-msg ) 204 "