Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | # |
| 3 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # This tool is used to update libaom source code to a revision of the upstream |
| 8 | # repository. |
| 9 | |
| 10 | # Usage: |
| 11 | # |
| 12 | # $ ./update_libaom.sh [branch | revision | file or url containing a revision] |
| 13 | # When specifying a branch it may be necessary to prefix with origin/ |
| 14 | |
| 15 | # Tools required for running this tool: |
| 16 | # |
| 17 | # 1. Linux / Mac |
| 18 | # 2. git |
| 19 | |
| 20 | export LC_ALL=C |
| 21 | |
| 22 | # Location for the remote git repository. |
| 23 | GIT_REPO="https://aomedia.googlesource.com/aom" |
| 24 | |
| 25 | # Update to TOT by default. |
| 26 | GIT_BRANCH="origin/master" |
| 27 | |
| 28 | # Relative path of target checkout. |
| 29 | LIBAOM_SRC_DIR="libaom" |
| 30 | |
| 31 | BASE_DIR=`pwd` |
| 32 | |
| 33 | if [ -n "$1" ]; then |
| 34 | GIT_BRANCH="$1" |
| 35 | if [ -f "$1" ]; then |
| 36 | GIT_BRANCH=$(<"$1") |
| 37 | elif [[ $1 = http* ]]; then |
| 38 | GIT_BRANCH=`curl $1` |
| 39 | fi |
| 40 | fi |
| 41 | |
| 42 | prev_hash="$(egrep "^Commit: [[:alnum:]]" README.android | awk '{ print $2 }')" |
| 43 | echo "prev_hash:$prev_hash" |
| 44 | |
| 45 | rm -rf $LIBAOM_SRC_DIR |
| 46 | # be robust in the face of errors (meaning don't overwrite the wrong place) |
| 47 | mkdir $LIBAOM_SRC_DIR || exit 1 |
| 48 | cd $LIBAOM_SRC_DIR || exit 1 |
| 49 | |
| 50 | # Start a local git repo. |
| 51 | git clone $GIT_REPO . |
| 52 | |
| 53 | # Switch the content to the desired revision. |
| 54 | git checkout -b tot $GIT_BRANCH |
| 55 | |
| 56 | add="$(git diff-index --diff-filter=A $prev_hash | \ |
| 57 | tr -s [:blank:] ' ' | cut -f6 -d\ )" |
| 58 | delete="$(git diff-index --diff-filter=D $prev_hash | \ |
| 59 | tr -s [:blank:] ' ' | cut -f6 -d\ )" |
| 60 | |
| 61 | # Get the current commit hash. |
| 62 | hash=$(git log -1 --format="%H") |
| 63 | |
| 64 | # README reminder. |
| 65 | ( |
| 66 | # keep meta info / header |
| 67 | sed -n '0,/^====/p' < ../README.android |
| 68 | |
| 69 | # sed kept it in there |
| 70 | #echo "========" |
| 71 | |
| 72 | echo "Date: $(date +"%A %B %d %Y")" |
| 73 | echo "Branch: $GIT_BRANCH" |
| 74 | echo "Commit: $hash" |
| 75 | echo "" |
| 76 | ) > ../update.$$-README.android |
| 77 | cat ../update.$$-README.android |
| 78 | mv ../update.$$-README.android ../README.android |
| 79 | |
| 80 | # Commit message header. |
| 81 | COMMIT_MSG=../commit-message-`date +"%Y%m%d.%H%M%S"` |
| 82 | ( |
| 83 | echo "libaom: Pull from upstream" |
| 84 | echo "" |
| 85 | |
| 86 | # Output the current commit hash. |
| 87 | echo "Prev HEAD: $prev_hash" |
| 88 | echo "New HEAD: $hash" |
| 89 | echo "" |
| 90 | |
| 91 | # Output log for upstream from current hash. |
| 92 | if [ -n "$prev_hash" ]; then |
| 93 | echo "git log from upstream:" |
| 94 | pretty_git_log="$(git log \ |
| 95 | --no-merges \ |
| 96 | --topo-order \ |
| 97 | --pretty="%h %s" \ |
| 98 | --max-count=20 \ |
| 99 | $prev_hash..$hash)" |
| 100 | if [ -z "$pretty_git_log" ]; then |
| 101 | echo "No log found. Checking for reverts." |
| 102 | pretty_git_log="$(git log \ |
| 103 | --no-merges \ |
| 104 | --topo-order \ |
| 105 | --pretty="%h %s" \ |
| 106 | --max-count=20 \ |
| 107 | $hash..$prev_hash)" |
| 108 | fi |
| 109 | echo "$pretty_git_log" |
| 110 | # If it makes it to 20 then it's probably skipping even more. |
| 111 | if [ `echo "$pretty_git_log" | wc -l` -eq 20 ]; then |
| 112 | echo "<...>" |
| 113 | fi |
| 114 | else |
| 115 | # no previous hash |
| 116 | echo "git log from upstream:" |
| 117 | pretty_git_log="$(git log \ |
| 118 | --no-merges \ |
| 119 | --topo-order \ |
| 120 | --pretty="%h %s" \ |
| 121 | --max-count=20)" |
| 122 | if [ -z "$pretty_git_log" ]; then |
| 123 | echo "No log found. Checking for reverts." |
| 124 | fi |
| 125 | echo "$pretty_git_log" |
| 126 | # If it makes it to 20 then it's probably skipping even more. |
| 127 | if [ `echo "$pretty_git_log" | wc -l` -eq 20 ]; then |
| 128 | echo "<...>" |
| 129 | fi |
| 130 | fi |
| 131 | ) > ${COMMIT_MSG} |
| 132 | |
| 133 | # Tell user about it |
| 134 | echo "Commit message: (stored in ./${COMMIT_MSG})" |
| 135 | echo "===============" |
| 136 | cat ${COMMIT_MSG} |
| 137 | echo "" |
| 138 | echo "===============" |
| 139 | |
| 140 | # Git is useless now, remove the local git repo. |
| 141 | rm -rf .git .gitignore .gitattributes |
| 142 | |
| 143 | # Add and remove files. |
| 144 | echo "$add" | xargs -I {} git add {} |
| 145 | echo "$delete" | xargs -I {} git rm --ignore-unmatch {} |
| 146 | |
| 147 | # Find empty directories and remove them. |
| 148 | find . -type d -empty -exec git rm {} \; |
| 149 | |
| 150 | chmod 755 build/cmake/*.sh build/cmake/*.pl |
| 151 | |
| 152 | # not even sure why we're doing a chdir here as the last thing in the script |
| 153 | # it isn't going to make any difference semantically. |
| 154 | cd $BASE_DIR || exit 1 |