[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 | ||||
Aaron Gable | a0e5cc4 | 2016-06-21 14:22:18 | [diff] [blame] | 29 | # hardcode the paths to Git where possible. |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 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 | GIT="git" |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 60 | if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then |
61 | GIT="cmd.exe //c \"$base_dir\\git.bat\"" | ||||
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 62 | fi |
63 | |||||
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 64 | # Test git and git --version. |
65 | function test_git { | ||||
[email protected] | 9f9aba1 | 2012-11-26 17:51:15 | [diff] [blame] | 66 | local GITV |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 67 | GITV="$(eval "$GIT" --version)" || { |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 68 | echo "git isn't installed, please install it" |
69 | exit 1 | ||||
70 | } | ||||
71 | |||||
72 | GITV="${GITV##* }" # Only examine last word (i.e. version number) | ||||
73 | local GITD=( ${GITV//./ } ) # Split version number into decimals | ||||
Aaron Gable | a0e5cc4 | 2016-06-21 14:22:18 | [diff] [blame] | 74 | if ((GITD[0] < 1 || (GITD[0] == 2 && GITD[1] < 8) )); then |
75 | echo "git version is ${GITV}, please update to a version later than 2.8" | ||||
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 76 | exit 1 |
77 | fi | ||||
78 | } | ||||
79 | |||||
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 80 | function update_git_repo { |
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 81 | remote_url=$(eval "$GIT" config --get remote.origin.url) |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 82 | if [ -n "$remote_url" -a "$remote_url" != "$CANONICAL_GIT_URL" ]; then |
83 | echo "Your copy of depot_tools is configured to fetch from an obsolete URL:" | ||||
84 | echo | ||||
85 | echo " $remote_url" | ||||
86 | echo | ||||
87 | 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] | 88 | STATUS=$? |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 89 | echo |
[email protected] | 4fa0246 | 2013-10-08 01:50:18 | [diff] [blame] | 90 | if [[ $STATUS -ne 0 ]]; then |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 91 | echo "Timeout; not updating remote URL." |
92 | elif [ -z "$REPLY" -o "$REPLY" = "Y" -o "$REPLY" = "y" ]; then | ||||
[email protected] | 3b16a28 | 2014-02-21 17:20:58 | [diff] [blame] | 93 | eval "$GIT" config remote.origin.url "$CANONICAL_GIT_URL" |
[email protected] | 143c3ff | 2013-01-03 23:08:41 | [diff] [blame] | 94 | echo "Remote URL updated." |
95 | fi | ||||
96 | fi | ||||
97 | |||||
Aaron Gable | a0e5cc4 | 2016-06-21 14:22:18 | [diff] [blame] | 98 | git fetch -q origin &> /dev/null |
99 | local REBASE_TXT STATUS | ||||
100 | REBASE_TXT=$(git rebase -q origin/master 2>&1) | ||||
101 | STATUS=$? | ||||
102 | if [[ $STATUS -ne 0 ]]; then | ||||
103 | echo "depot_tools update failed. Conflict in $base_dir" >&2 | ||||
104 | echo "$REBASE_TXT" >&2 | ||||
105 | git rebase --abort 2> /dev/null | ||||
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 106 | fi |
Aaron Gable | a0e5cc4 | 2016-06-21 14:22:18 | [diff] [blame] | 107 | return $STATUS |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 108 | } |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 109 | |
[email protected] | 3bc36d1 | 2011-04-14 22:02:08 | [diff] [blame] | 110 | # Update git checkouts. |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 111 | if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.git" ] |
112 | then | ||||
113 | cd $base_dir | ||||
[email protected] | b9d08ce | 2012-05-01 18:32:43 | [diff] [blame] | 114 | update_git_repo |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 115 | cd - > /dev/null |
116 | fi | ||||
117 | |||||
[email protected] | 28e0e94 | 2011-02-23 18:49:54 | [diff] [blame] | 118 | # We're on POSIX. We can now safely look for svn checkout. |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 119 | if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.svn" ] |
120 | then | ||||
[email protected] | 17c4771 | 2016-05-23 23:53:44 | [diff] [blame] | 121 | echo "========================" |
122 | echo "WARNING: You have an SVN checkout of depot_tools!" | ||||
123 | echo | ||||
Aaron Gable | a0e5cc4 | 2016-06-21 14:22:18 | [diff] [blame] | 124 | echo "depot_tools has migrated to Git. You are" |
125 | echo "NO LONGER RECEIVING UPDATES to depot_tools." | ||||
[email protected] | 17c4771 | 2016-05-23 23:53:44 | [diff] [blame] | 126 | echo |
Aaron Gable | a0e5cc4 | 2016-06-21 14:22:18 | [diff] [blame] | 127 | echo "You must follow these instructions[1] to get a Git copy of depot_tools." |
[email protected] | 17c4771 | 2016-05-23 23:53:44 | [diff] [blame] | 128 | echo |
129 | echo "[1]: https://www.chromium.org/developers/how-tos/install-depot-tools" | ||||
130 | echo "========================" | ||||
Aaron Gable | a0e5cc4 | 2016-06-21 14:22:18 | [diff] [blame] | 131 | return 1 |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 132 | fi |
[email protected] | 81a82a9 | 2011-09-28 00:05:15 | [diff] [blame] | 133 | |
[email protected] | 02ad753 | 2015-09-11 17:04:32 | [diff] [blame] | 134 | find "$base_dir" -iname "*.pyc" -exec rm -f {} \; |