[email protected] | 711a16a | 2011-05-21 09:30:43 | [diff] [blame] | 1 | #!/usr/bin/env bash |
[email protected] | 6fd50f5 | 2012-07-17 19:23:39 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | # This script will try to sync the bootstrap directories and then defer control. |
| 7 | |
[email protected] | 31dcb49 | 2011-05-12 20:36:38 | [diff] [blame] | 8 | if [ "$USER" == "root" ]; |
| 9 | then |
| 10 | echo Running depot tools as root is sad. |
| 11 | exit |
| 12 | fi |
| 13 | |
[email protected] | cf231dd | 2016-03-30 02:45:15 | [diff] [blame] | 14 | # Test if this script is running under a MSYS install. This is likely an error |
| 15 | # if it is, so we warn the user accordingly. |
| 16 | OUTPUT="$(uname | grep 'MSYS')" |
| 17 | MSYS=$? |
| 18 | if [ $MSYS = 0 ]; then |
| 19 | echo 'WARNING: It looks like you are running these tools from an MSYS shell' |
| 20 | echo '(as opposed to a MinGW shell). This shell is not supported and may' |
| 21 | echo 'fail in mysterious ways.' |
| 22 | echo |
| 23 | echo 'To run the supported MinGW shell, use `git bash`, or use `bin/bash.exe`' |
| 24 | echo 'in your MinGW installation, as opposed to `usr/bin/bash.exe`.' |
| 25 | echo |
| 26 | fi |
| 27 | |
| 28 | # Test if this script is running under a MinGW install. If it is, we will |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 29 | # hardcode the paths to SVN and Git where possible. |
| 30 | OUTPUT="$(uname | grep 'MINGW')" |
| 31 | MINGW=$? |
| 32 | |
| 33 | if [ $MINGW = 0 ]; then |
[email protected] | 4845f0e | 2015-06-29 22:54:58 | [diff] [blame] | 34 | base_dir="${0%/*}" |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 35 | else |
| 36 | base_dir=$(dirname "$0") |
| 37 | if [ -L "$base_dir" ]; then |
[email protected] | 6fe66e1 | 2011-04-12 23:12:35 | [diff] [blame] | 38 | base_dir=`cd "$base_dir" && pwd -P` |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 39 | fi |
[email protected] | 6fe66e1 | 2011-04-12 23:12:35 | [diff] [blame] | 40 | fi |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 41 | |
[email protected] | cf231dd | 2016-03-30 02:45:15 | [diff] [blame] | 42 | # We want to update the bundled tools even under MinGW. |
| 43 | if [ $MINGW = 0 ]; then |
[email protected] | 02ef57e | 2016-03-30 01:46:41 | [diff] [blame] | 44 | $COMSPEC /c `cygpath -w "$base_dir/bootstrap/win/win_tools.bat"` |
[email protected] | 3466b0d | 2016-04-04 19:50:20 | [diff] [blame] | 45 | case $? in |
| 46 | 123) |
| 47 | # msys environment was upgraded, need to quit. |
| 48 | exit 123 |
| 49 | ;; |
| 50 | 0) |
| 51 | ;; |
| 52 | *) |
| 53 | exit $? |
| 54 | esac |
[email protected] | 682d0d7 | 2014-01-18 01:28:49 | [diff] [blame] | 55 | fi |
| 56 | |
[email protected] | 9f36c38 | 2013-01-07 23:53:36 | [diff] [blame] | 57 | CANONICAL_GIT_URL="https://chromium.googlesource.com/chromium/tools/depot_tools.git" |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 58 | |
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 59 | SVN="svn" |
| 60 | if [ -d "$base_dir/svn_bin" -a $MINGW = 0 ]; then |
| 61 | SVN="$base_dir/svn_bin/svn.exe" |
| 62 | fi |
| 63 | |
| 64 | GIT="git" |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 65 | if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then |
| 66 | GIT="cmd.exe //c \"$base_dir\\git.bat\"" |
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 67 | fi |
| 68 | |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 69 | # Test git and git --version. |
| 70 | function test_git { |
[email protected] | 9f9aba1 | 2012-11-26 17:51:15 | [diff] [blame] | 71 | local GITV |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 72 | GITV="$(eval "$GIT" --version)" || { |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 73 | echo "git isn't installed, please install it" |
| 74 | exit 1 |
| 75 | } |
| 76 | |
| 77 | GITV="${GITV##* }" # Only examine last word (i.e. version number) |
| 78 | local GITD=( ${GITV//./ } ) # Split version number into decimals |
| 79 | if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then |
| 80 | echo "git version is ${GITV}, please update to a version later than 1.6" |
| 81 | exit 1 |
| 82 | fi |
| 83 | } |
| 84 | |
| 85 | # Test git svn and git svn --version. |
| 86 | function test_git_svn { |
[email protected] | 9f9aba1 | 2012-11-26 17:51:15 | [diff] [blame] | 87 | local GITV |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 88 | GITV="$(eval "$GIT" svn --version)" || { |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 89 | echo "git-svn isn't installed, please install it" |
| 90 | exit 1 |
| 91 | } |
| 92 | |
| 93 | GITV="${GITV#* version }" # git svn --version has extra output to remove. |
| 94 | GITV="${GITV% (svn*}" |
| 95 | local GITD=( ${GITV//./ } ) # Split version number into decimals |
| 96 | if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then |
| 97 | echo "git version is ${GITV}, please update to a version later than 1.6" |
| 98 | exit 1 |
| 99 | fi |
| 100 | } |
| 101 | |
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 102 | function is_git_clone_repo { |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 103 | eval "$GIT" config remote.origin.fetch > /dev/null |
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | function update_git_repo { |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 107 | remote_url=$(eval "$GIT" config --get remote.origin.url) |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 108 | if [ -n "$remote_url" -a "$remote_url" != "$CANONICAL_GIT_URL" ]; then |
| 109 | echo "Your copy of depot_tools is configured to fetch from an obsolete URL:" |
| 110 | echo |
| 111 | echo " $remote_url" |
| 112 | echo |
| 113 | read -t 60 -p "OK to update it to $CANONICAL_GIT_URL ? [Y/n] " -n 1 |
[email protected] | 4fa0246 | 2013-10-08 01:50:18 | [diff] [blame] | 114 | STATUS=$? |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 115 | echo |
[email protected] | 4fa0246 | 2013-10-08 01:50:18 | [diff] [blame] | 116 | if [[ $STATUS -ne 0 ]]; then |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 117 | echo "Timeout; not updating remote URL." |
| 118 | elif [ -z "$REPLY" -o "$REPLY" = "Y" -o "$REPLY" = "y" ]; then |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 119 | eval "$GIT" config remote.origin.url "$CANONICAL_GIT_URL" |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 120 | echo "Remote URL updated." |
| 121 | fi |
| 122 | fi |
| 123 | |
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 124 | if is_git_clone_repo; then |
[email protected] | 2164926 | 2012-11-09 03:30:05 | [diff] [blame] | 125 | git fetch -q origin &> /dev/null |
[email protected] | 9f9aba1 | 2012-11-26 17:51:15 | [diff] [blame] | 126 | local REBASE_TXT STATUS |
| 127 | REBASE_TXT=$(git rebase -q origin/master 2>&1) |
| 128 | STATUS=$? |
| 129 | if [[ $STATUS -ne 0 ]]; then |
[email protected] | 2164926 | 2012-11-09 03:30:05 | [diff] [blame] | 130 | echo "depot_tools update failed. Conflict in $base_dir" >&2 |
| 131 | echo "$REBASE_TXT" >&2 |
| 132 | git rebase --abort 2> /dev/null |
| 133 | fi |
| 134 | return $STATUS |
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 135 | fi |
| 136 | |
| 137 | test_git_svn |
| 138 | # work around a git-svn --quiet bug |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 139 | OUTPUT=`eval "$GIT" svn rebase -q -q` |
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 140 | if [[ ! "$OUTPUT" == *Current.branch* ]]; then |
| 141 | echo $OUTPUT 1>&2 |
| 142 | fi |
| 143 | return 0 |
| 144 | } |
| 145 | |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 146 | # Get the current SVN revision. |
| 147 | get_svn_revision() { |
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 148 | LANGUAGE=C "$SVN" info "$base_dir" | \ |
[email protected] | 736aefe | 2011-04-19 18:01:08 | [diff] [blame] | 149 | awk -F': ' '{ if ($1 == "Last Changed Rev") { print $2 }}' |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 150 | } |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 151 | |
[email protected] | 3bc36d1 | 2011-04-14 22:02:08 | [diff] [blame] | 152 | # Update git checkouts. |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 153 | if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.git" ] |
| 154 | then |
| 155 | cd $base_dir |
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 156 | update_git_repo |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 157 | cd - > /dev/null |
| 158 | fi |
| 159 | |
[email protected] | 28e0e94 | 2011-02-23 18:49:54 | [diff] [blame] | 160 | # We're on POSIX. We can now safely look for svn checkout. |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 161 | if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.svn" ] |
| 162 | then |
[email protected] | 17c4771 | 2016-05-23 23:53:44 | [diff] [blame] | 163 | echo "========================" |
| 164 | echo "WARNING: You have an SVN checkout of depot_tools!" |
| 165 | echo |
| 166 | echo "depot_tools is migrating to Git on June 6, 2016. If you still have an" |
| 167 | echo "SVN checkout then, you will STOP RECEIVING UPDATES to depot_tools." |
| 168 | echo |
| 169 | echo "Before that date, please follow the instructions here[1] to get a Git" |
| 170 | echo "copy of depot_tools." |
| 171 | echo |
| 172 | echo "[1]: https://www.chromium.org/developers/how-tos/install-depot-tools" |
| 173 | echo "========================" |
[email protected] | e6c00f3 | 2012-04-13 15:39:49 | [diff] [blame] | 174 | # Update the root directory to stay up-to-date with the latest depot_tools. |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 175 | BEFORE_REVISION=$(get_svn_revision) |
[email protected] | 884b52c | 2014-12-12 19:26:49 | [diff] [blame] | 176 | if echo $* | grep -e --force > /dev/null; then |
[email protected] | 69b6758 | 2014-11-25 23:34:41 | [diff] [blame] | 177 | "$SVN" -q revert -R "$base_dir" |
| 178 | fi |
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 179 | "$SVN" -q up "$base_dir" |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 180 | AFTER_REVISION=$(get_svn_revision) |
| 181 | if [[ "$BEFORE_REVISION" != "$AFTER_REVISION" ]]; then |
[email protected] | 48d661e | 2015-04-13 14:03:53 | [diff] [blame] | 182 | if [ -z "$DEPOT_TOOLS_HIDE_UPDATED_MESSAGE" ]; then |
| 183 | echo "Depot Tools has been updated to revision $AFTER_REVISION." 1>&2 |
| 184 | fi |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 185 | fi |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 186 | fi |
[email protected] | 81a82a9 | 2011-09-28 00:05:15 | [diff] [blame] | 187 | |
[email protected] | 02ad753 | 2015-09-11 17:04:32 | [diff] [blame] | 188 | find "$base_dir" -iname "*.pyc" -exec rm -f {} \; |