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