Home | History | Annotate | Download | only in tools
      1 #!/bin/bash
      2 # Copyright 2012 the V8 project authors. All rights reserved.
      3 # Redistribution and use in source and binary forms, with or without
      4 # modification, are permitted provided that the following conditions are
      5 # met:
      6 #
      7 #     * Redistributions of source code must retain the above copyright
      8 #       notice, this list of conditions and the following disclaimer.
      9 #     * Redistributions in binary form must reproduce the above
     10 #       copyright notice, this list of conditions and the following
     11 #       disclaimer in the documentation and/or other materials provided
     12 #       with the distribution.
     13 #     * Neither the name of Google Inc. nor the names of its
     14 #       contributors may be used to endorse or promote products derived
     15 #       from this software without specific prior written permission.
     16 #
     17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 
     29 
     30 ########## Global variable definitions
     31 
     32 BRANCHNAME=prepare-push
     33 TRUNKBRANCH=trunk-push
     34 PERSISTFILE_BASENAME=/tmp/v8-push-to-trunk-tempfile
     35 CHROME_PATH=
     36 
     37 ########## Function definitions
     38 
     39 source $(dirname $BASH_SOURCE)/common-includes.sh
     40 
     41 usage() {
     42 cat << EOF
     43 usage: $0 OPTIONS
     44 
     45 Performs the necessary steps for a V8 push to trunk. Only works for \
     46 git checkouts.
     47 
     48 OPTIONS:
     49   -h    Show this message
     50   -s    Specify the step where to start work. Default: 0.
     51   -l    Manually specify the git commit ID of the last push to trunk.
     52   -c    Specify the path to your Chromium src/ directory to automate the
     53         V8 roll.
     54 EOF
     55 }
     56 
     57 ########## Option parsing
     58 
     59 while getopts ":hs:l:c:" OPTION ; do
     60   case $OPTION in
     61     h)  usage
     62         exit 0
     63         ;;
     64     s)  START_STEP=$OPTARG
     65         ;;
     66     l)  LASTPUSH=$OPTARG
     67         ;;
     68     c)  CHROME_PATH=$OPTARG
     69         ;;
     70     ?)  echo "Illegal option: -$OPTARG"
     71         usage
     72         exit 1
     73         ;;
     74   esac
     75 done
     76 
     77 
     78 ########## Regular workflow
     79 
     80 initial_environment_checks
     81 
     82 if [ $START_STEP -le $CURRENT_STEP ] ; then
     83   echo ">>> Step $CURRENT_STEP: Preparation"
     84   common_prepare
     85   delete_branch $TRUNKBRANCH
     86 fi
     87 
     88 let CURRENT_STEP+=1
     89 if [ $START_STEP -le $CURRENT_STEP ] ; then
     90   echo ">>> Step $CURRENT_STEP: Create a fresh branch."
     91   git checkout -b $BRANCHNAME svn/bleeding_edge \
     92     || die "Creating branch $BRANCHNAME failed."
     93 fi
     94 
     95 let CURRENT_STEP+=1
     96 if [ $START_STEP -le $CURRENT_STEP ] ; then
     97   echo ">>> Step $CURRENT_STEP: Detect commit ID of last push to trunk."
     98   [[ -n "$LASTPUSH" ]] || LASTPUSH=$(git log -1 --format=%H ChangeLog)
     99   LOOP=1
    100   while [ $LOOP -eq 1 ] ; do
    101     # Print assumed commit, circumventing git's pager.
    102     git log -1 $LASTPUSH | cat
    103     confirm "Is the commit printed above the last push to trunk?"
    104     if [ $? -eq 0 ] ; then
    105       LOOP=0
    106     else
    107       LASTPUSH=$(git log -1 --format=%H $LASTPUSH^ ChangeLog)
    108     fi
    109   done
    110   persist "LASTPUSH"
    111 fi
    112 
    113 let CURRENT_STEP+=1
    114 if [ $START_STEP -le $CURRENT_STEP ] ; then
    115   echo ">>> Step $CURRENT_STEP: Prepare raw ChangeLog entry."
    116   # These version numbers are used again later for the trunk commit.
    117   read_and_persist_version
    118 
    119   DATE=$(date +%Y-%m-%d)
    120   persist "DATE"
    121   echo "$DATE: Version $MAJOR.$MINOR.$BUILD" > "$CHANGELOG_ENTRY_FILE"
    122   echo "" >> "$CHANGELOG_ENTRY_FILE"
    123   COMMITS=$(git log $LASTPUSH..HEAD --format=%H)
    124   for commit in $COMMITS ; do
    125     # Get the commit's title line.
    126     git log -1 $commit --format="%w(80,8,8)%s" >> "$CHANGELOG_ENTRY_FILE"
    127     # Grep for "BUG=xxxx" lines in the commit message and convert them to
    128     # "(issue xxxx)".
    129     git log -1 $commit --format="%B" \
    130         | grep "^BUG=" | grep -v "BUG=$" | grep -v "BUG=none$" \
    131         | sed -e 's/^/        /' \
    132         | sed -e 's/BUG=v8:\(.*\)$/(issue \1)/' \
    133         | sed -e 's/BUG=\(.*\)$/(Chromium issue \1)/' \
    134         >> "$CHANGELOG_ENTRY_FILE"
    135     # Append the commit's author for reference.
    136     git log -1 $commit --format="%w(80,8,8)(%an)" >> "$CHANGELOG_ENTRY_FILE"
    137     echo "" >> "$CHANGELOG_ENTRY_FILE"
    138   done
    139   echo "        Performance and stability improvements on all platforms." \
    140     >> "$CHANGELOG_ENTRY_FILE"
    141 fi
    142 
    143 let CURRENT_STEP+=1
    144 if [ $START_STEP -le $CURRENT_STEP ] ; then
    145   echo ">>> Step $CURRENT_STEP: Edit ChangeLog entry."
    146   echo -n "Please press <Return> to have your EDITOR open the ChangeLog entry, \
    147 then edit its contents to your liking. When you're done, save the file and \
    148 exit your EDITOR. "
    149   read ANSWER
    150   $EDITOR "$CHANGELOG_ENTRY_FILE"
    151   NEWCHANGELOG=$(mktemp)
    152   # Eliminate any trailing newlines by going through a shell variable.
    153   # Also (1) eliminate tabs, (2) fix too little and (3) too much indentation,
    154   # and (4) eliminate trailing whitespace.
    155   CHANGELOGENTRY=$(cat "$CHANGELOG_ENTRY_FILE" \
    156                    | sed -e 's/\t/        /g' \
    157                    | sed -e 's/^ \{1,7\}\([^ ]\)/        \1/g' \
    158                    | sed -e 's/^ \{9,80\}\([^ ]\)/        \1/g' \
    159                    | sed -e 's/ \+$//')
    160   [[ -n "$CHANGELOGENTRY" ]] || die "Empty ChangeLog entry."
    161   echo "$CHANGELOGENTRY" > "$NEWCHANGELOG"
    162   echo "" >> "$NEWCHANGELOG" # Explicitly insert two empty lines.
    163   echo "" >> "$NEWCHANGELOG"
    164   cat ChangeLog >> "$NEWCHANGELOG"
    165   mv "$NEWCHANGELOG" ChangeLog
    166 fi
    167 
    168 let CURRENT_STEP+=1
    169 if [ $START_STEP -le $CURRENT_STEP ] ; then
    170   echo ">>> Step $CURRENT_STEP: Increment version number."
    171   restore_if_unset "BUILD"
    172   NEWBUILD=$(($BUILD + 1))
    173   confirm "Automatically increment BUILD_NUMBER? (Saying 'n' will fire up \
    174 your EDITOR on $VERSION_FILE so you can make arbitrary changes. When \
    175 you're done, save the file and exit your EDITOR.)"
    176   if [ $? -eq 0 ] ; then
    177     sed -e "/#define BUILD_NUMBER/s/[0-9]*$/$NEWBUILD/" \
    178         -i "$VERSION_FILE"
    179   else
    180     $EDITOR "$VERSION_FILE"
    181   fi
    182   read_and_persist_version "NEW"
    183 fi
    184 
    185 let CURRENT_STEP+=1
    186 if [ $START_STEP -le $CURRENT_STEP ] ; then
    187   echo ">>> Step $CURRENT_STEP: Commit to local branch."
    188   restore_version_if_unset "NEW"
    189   PREPARE_COMMIT_MSG="Prepare push to trunk.  \
    190 Now working on version $NEWMAJOR.$NEWMINOR.$NEWBUILD."
    191   persist "PREPARE_COMMIT_MSG"
    192   git commit -a -m "$PREPARE_COMMIT_MSG" \
    193     || die "'git commit -a' failed."
    194 fi
    195 
    196 upload_step
    197 
    198 let CURRENT_STEP+=1
    199 if [ $START_STEP -le $CURRENT_STEP ] ; then
    200   echo ">>> Step $CURRENT_STEP: Commit to the repository."
    201   wait_for_lgtm
    202   # Re-read the ChangeLog entry (to pick up possible changes).
    203   cat ChangeLog | awk --posix '{
    204     if ($0 ~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}:/) {
    205       if (in_firstblock == 1) {
    206         exit 0;
    207       } else {
    208         in_firstblock = 1;
    209       }
    210     };
    211     print $0;
    212   }' > "$CHANGELOG_ENTRY_FILE"
    213   git cl dcommit || die "'git cl dcommit' failed, please try again."
    214 fi
    215 
    216 let CURRENT_STEP+=1
    217 if [ $START_STEP -le $CURRENT_STEP ] ; then
    218   echo ">>> Step $CURRENT_STEP: Fetch straggler commits that sneaked in \
    219 since this script was started."
    220   git svn fetch || die "'git svn fetch' failed."
    221   git checkout svn/bleeding_edge
    222   restore_if_unset "PREPARE_COMMIT_MSG"
    223   PREPARE_COMMIT_HASH=$(git log -1 --format=%H --grep="$PREPARE_COMMIT_MSG")
    224   persist "PREPARE_COMMIT_HASH"
    225 fi
    226 
    227 let CURRENT_STEP+=1
    228 if [ $START_STEP -le $CURRENT_STEP ] ; then
    229   echo ">>> Step $CURRENT_STEP: Squash commits into one."
    230   # Instead of relying on "git rebase -i", we'll just create a diff, because
    231   # that's easier to automate.
    232   restore_if_unset "PREPARE_COMMIT_HASH"
    233   git diff svn/trunk $PREPARE_COMMIT_HASH > "$PATCH_FILE"
    234   # Convert the ChangeLog entry to commit message format:
    235   # - remove date
    236   # - remove indentation
    237   # - merge paragraphs into single long lines, keeping empty lines between them.
    238   restore_if_unset "DATE"
    239   CHANGELOGENTRY=$(cat "$CHANGELOG_ENTRY_FILE")
    240   echo "$CHANGELOGENTRY" \
    241     | sed -e "s/^$DATE: //" \
    242     | sed -e 's/^ *//' \
    243     | awk '{
    244         if (need_space == 1) {
    245           printf(" ");
    246         };
    247         printf("%s", $0);
    248         if ($0 ~ /^$/) {
    249           printf("\n\n");
    250           need_space = 0;
    251         } else {
    252           need_space = 1;
    253         }
    254       }' > "$COMMITMSG_FILE" || die "Commit message editing failed."
    255   rm -f "$CHANGELOG_ENTRY_FILE"
    256 fi
    257 
    258 let CURRENT_STEP+=1
    259 if [ $START_STEP -le $CURRENT_STEP ] ; then
    260   echo ">>> Step $CURRENT_STEP: Create a new branch from trunk."
    261   git checkout -b $TRUNKBRANCH svn/trunk \
    262     || die "Checking out a new branch '$TRUNKBRANCH' failed."
    263 fi
    264 
    265 let CURRENT_STEP+=1
    266 if [ $START_STEP -le $CURRENT_STEP ] ; then
    267   echo ">>> Step $CURRENT_STEP: Apply squashed changes."
    268   rm -f "$TOUCHED_FILES_FILE"
    269   apply_patch "$PATCH_FILE"
    270   stage_files
    271   rm -f "$PATCH_FILE"
    272 fi
    273 
    274 let CURRENT_STEP+=1
    275 if [ $START_STEP -le $CURRENT_STEP ] ; then
    276   echo ">>> Step $CURRENT_STEP: Set correct version for trunk."
    277   restore_version_if_unset
    278   sed -e "/#define MAJOR_VERSION/s/[0-9]*$/$MAJOR/" \
    279       -e "/#define MINOR_VERSION/s/[0-9]*$/$MINOR/" \
    280       -e "/#define BUILD_NUMBER/s/[0-9]*$/$BUILD/" \
    281       -e "/#define PATCH_LEVEL/s/[0-9]*$/0/" \
    282       -e "/#define IS_CANDIDATE_VERSION/s/[0-9]*$/0/" \
    283       -i "$VERSION_FILE" || die "Patching $VERSION_FILE failed."
    284 fi
    285 
    286 let CURRENT_STEP+=1
    287 if [ $START_STEP -le $CURRENT_STEP ] ; then
    288   echo ">>> Step $CURRENT_STEP: Commit to local trunk branch."
    289   git add "$VERSION_FILE"
    290   git commit -F "$COMMITMSG_FILE" || die "'git commit' failed."
    291   rm -f "$COMMITMSG_FILE"
    292 fi
    293 
    294 let CURRENT_STEP+=1
    295 if [ $START_STEP -le $CURRENT_STEP ] ; then
    296   echo ">>> Step $CURRENT_STEP: Sanity check."
    297   confirm "Please check if your local checkout is sane: Inspect $VERSION_FILE, \
    298 compile, run tests. Do you want to commit this new trunk revision to the \
    299 repository?"
    300   [[ $? -eq 0 ]] || die "Execution canceled."
    301 fi
    302 
    303 let CURRENT_STEP+=1
    304 if [ $START_STEP -le $CURRENT_STEP ] ; then
    305   echo ">>> Step $CURRENT_STEP: Commit to SVN."
    306   git svn dcommit | tee >(grep -E "^Committed r[0-9]+" \
    307                           | sed -e 's/^Committed r\([0-9]\+\)/\1/' \
    308                           > "$TRUNK_REVISION_FILE") \
    309     || die "'git svn dcommit' failed."
    310   TRUNK_REVISION=$(cat "$TRUNK_REVISION_FILE")
    311   persist "TRUNK_REVISION"
    312   rm -f "$TRUNK_REVISION_FILE"
    313 fi
    314 
    315 let CURRENT_STEP+=1
    316 if [ $START_STEP -le $CURRENT_STEP ] ; then
    317   echo ">>> Step $CURRENT_STEP: Tag the new revision."
    318   restore_version_if_unset
    319   git svn tag $MAJOR.$MINOR.$BUILD -m "Tagging version $MAJOR.$MINOR.$BUILD" \
    320     || die "'git svn tag' failed."
    321 fi
    322 
    323 if [ -n "$CHROME_PATH" ] ; then
    324 
    325   let CURRENT_STEP+=1
    326   if [ $START_STEP -le $CURRENT_STEP ] ; then
    327     echo ">>> Step $CURRENT_STEP: Switch to Chromium checkout."
    328     V8_PATH=$(pwd)
    329     persist "V8_PATH"
    330     cd "$CHROME_PATH"
    331     initial_environment_checks
    332     # Check for a clean workdir.
    333     [[ -z "$(git status -s -uno)" ]] \
    334       || die "Workspace is not clean. Please commit or undo your changes."
    335     # Assert that the DEPS file is there.
    336     [[ -w "DEPS" ]] || die "DEPS file not present or not writable; \
    337 current directory is: $(pwd)."
    338   fi
    339 
    340   let CURRENT_STEP+=1
    341   if [ $START_STEP -le $CURRENT_STEP ] ; then
    342     echo ">>> Step $CURRENT_STEP: Update the checkout and create a new branch."
    343     git checkout master || die "'git checkout master' failed."
    344     git pull || die "'git pull' failed, please try again."
    345     restore_if_unset "TRUNK_REVISION"
    346     git checkout -b "v8-roll-$TRUNK_REVISION" \
    347       || die "Failed to checkout a new branch."
    348   fi
    349 
    350   let CURRENT_STEP+=1
    351   if [ $START_STEP -le $CURRENT_STEP ] ; then
    352     echo ">>> Step $CURRENT_STEP: Create and upload CL."
    353     # Patch DEPS file.
    354     sed -r -e "/\"v8_revision\": /s/\"[0-9]+\"/\"$TRUNK_REVISION\"/" \
    355         -i DEPS
    356     restore_version_if_unset
    357     echo -n "Please enter the email address of a reviewer for the roll CL: "
    358     read REVIEWER
    359     git commit -am "Update V8 to version $MAJOR.$MINOR.$BUILD.
    360 
    361 TBR=$REVIEWER" || die "'git commit' failed."
    362     git cl upload --send-mail \
    363       || die "'git cl upload' failed, please try again."
    364     echo "CL uploaded."
    365   fi
    366 
    367   let CURRENT_STEP+=1
    368   if [ $START_STEP -le $CURRENT_STEP ] ; then
    369     echo ">>> Step $CURRENT_STEP: Returning to V8 checkout."
    370     restore_if_unset "V8_PATH"
    371     cd "$V8_PATH"
    372   fi
    373 fi  # if [ -n "$CHROME_PATH" ]
    374 
    375 let CURRENT_STEP+=1
    376 if [ $START_STEP -le $CURRENT_STEP ] ; then
    377   echo ">>> Step $CURRENT_STEP: Done!"
    378   restore_version_if_unset
    379   restore_if_unset "TRUNK_REVISION"
    380   if [ -n "$CHROME_PATH" ] ; then
    381     echo "Congratulations, you have successfully created the trunk revision \
    382 $MAJOR.$MINOR.$BUILD and rolled it into Chromium. Please don't forget to \
    383 update the v8rel spreadsheet:"
    384   else
    385     echo "Congratulations, you have successfully created the trunk revision \
    386 $MAJOR.$MINOR.$BUILD. Please don't forget to roll this new version into \
    387 Chromium, and to update the v8rel spreadsheet:"
    388   fi
    389   echo -e "$MAJOR.$MINOR.$BUILD\ttrunk\t$TRUNK_REVISION"
    390   common_cleanup
    391   [[ "$TRUNKBRANCH" != "$CURRENT_BRANCH" ]] && git branch -D $TRUNKBRANCH
    392 fi
    393