cmp@chromium.org | 711a16a | 2011-05-21 09:30:43 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
maruel@chromium.org | 6fd50f5 | 2012-07-17 19:23:39 +0000 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
msb@chromium.org | 2a94904 | 2010-10-18 18:04:01 +0000 | [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 | |
maruel@chromium.org | 31dcb49 | 2011-05-12 20:36:38 +0000 | [diff] [blame] | 8 | if [ "$USER" == "root" ]; |
| 9 | then |
| 10 | echo Running depot tools as root is sad. |
| 11 | exit |
| 12 | fi |
| 13 | |
iannucci@chromium.org | cf231dd | 2016-03-30 02:45:15 +0000 | [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 07:22:18 -0700 | [diff] [blame] | 29 | # hardcode the paths to Git where possible. |
mmoss@chromium.org | 3b16a28 | 2014-02-21 17:20:58 +0000 | [diff] [blame] | 30 | OUTPUT="$(uname | grep 'MINGW')" |
| 31 | MINGW=$? |
| 32 | |
| 33 | if [ $MINGW = 0 ]; then |
pkasting@chromium.org | 4845f0e | 2015-06-29 22:54:58 +0000 | [diff] [blame] | 34 | base_dir="${0%/*}" |
mmoss@chromium.org | 3b16a28 | 2014-02-21 17:20:58 +0000 | [diff] [blame] | 35 | else |
| 36 | base_dir=$(dirname "$0") |
| 37 | if [ -L "$base_dir" ]; then |
scottbyer@chromium.org | 6fe66e1 | 2011-04-12 23:12:35 +0000 | [diff] [blame] | 38 | base_dir=`cd "$base_dir" && pwd -P` |
mmoss@chromium.org | 3b16a28 | 2014-02-21 17:20:58 +0000 | [diff] [blame] | 39 | fi |
scottbyer@chromium.org | 6fe66e1 | 2011-04-12 23:12:35 +0000 | [diff] [blame] | 40 | fi |
msb@chromium.org | 2a94904 | 2010-10-18 18:04:01 +0000 | [diff] [blame] | 41 | |
Dirk Pranke | ecdfa41 | 2017-08-02 09:25:18 -0700 | [diff] [blame] | 42 | if [ -e "$base_dir/.disable_auto_update" ]; then |
Dan Jacques | 74d7e13 | 2017-06-01 15:17:15 -0700 | [diff] [blame] | 43 | exit |
| 44 | fi |
| 45 | |
iannucci@chromium.org | cf231dd | 2016-03-30 02:45:15 +0000 | [diff] [blame] | 46 | # We want to update the bundled tools even under MinGW. |
| 47 | if [ $MINGW = 0 ]; then |
Edward Lemur | 2499525 | 2019-09-18 18:31:07 +0000 | [diff] [blame] | 48 | $COMSPEC /c `cygpath -w "$base_dir/bootstrap/win_tools.bat"` |
iannucci@chromium.org | 3466b0d | 2016-04-04 19:50:20 +0000 | [diff] [blame] | 49 | case $? in |
| 50 | 123) |
| 51 | # msys environment was upgraded, need to quit. |
| 52 | exit 123 |
| 53 | ;; |
| 54 | 0) |
| 55 | ;; |
| 56 | *) |
| 57 | exit $? |
| 58 | esac |
pkasting@chromium.org | 682d0d7 | 2014-01-18 01:28:49 +0000 | [diff] [blame] | 59 | fi |
| 60 | |
szager@chromium.org | 9f36c38 | 2013-01-07 23:53:36 +0000 | [diff] [blame] | 61 | CANONICAL_GIT_URL="https://chromium.googlesource.com/chromium/tools/depot_tools.git" |
szager@chromium.org | 143c3ff | 2013-01-03 23:08:41 +0000 | [diff] [blame] | 62 | |
cmp@chromium.org | 4c6e404 | 2011-06-01 18:52:31 +0000 | [diff] [blame] | 63 | GIT="git" |
mmoss@chromium.org | 3b16a28 | 2014-02-21 17:20:58 +0000 | [diff] [blame] | 64 | if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then |
| 65 | GIT="cmd.exe //c \"$base_dir\\git.bat\"" |
cmp@chromium.org | 4c6e404 | 2011-06-01 18:52:31 +0000 | [diff] [blame] | 66 | fi |
| 67 | |
msb@chromium.org | 2a94904 | 2010-10-18 18:04:01 +0000 | [diff] [blame] | 68 | # Test git and git --version. |
| 69 | function test_git { |
newt@chromium.org | 9f9aba1 | 2012-11-26 17:51:15 +0000 | [diff] [blame] | 70 | local GITV |
mmoss@chromium.org | 3b16a28 | 2014-02-21 17:20:58 +0000 | [diff] [blame] | 71 | GITV="$(eval "$GIT" --version)" || { |
msb@chromium.org | 2a94904 | 2010-10-18 18:04:01 +0000 | [diff] [blame] | 72 | echo "git isn't installed, please install it" |
| 73 | exit 1 |
| 74 | } |
| 75 | |
| 76 | GITV="${GITV##* }" # Only examine last word (i.e. version number) |
| 77 | local GITD=( ${GITV//./ } ) # Split version number into decimals |
Aaron Gable | a0e5cc4 | 2016-06-21 07:22:18 -0700 | [diff] [blame] | 78 | if ((GITD[0] < 1 || (GITD[0] == 2 && GITD[1] < 8) )); then |
| 79 | echo "git version is ${GITV}, please update to a version later than 2.8" |
msb@chromium.org | 2a94904 | 2010-10-18 18:04:01 +0000 | [diff] [blame] | 80 | exit 1 |
| 81 | fi |
| 82 | } |
| 83 | |
cmp@chromium.org | b9d08ce | 2012-05-01 18:32:43 +0000 | [diff] [blame] | 84 | function update_git_repo { |
mmoss@chromium.org | 3b16a28 | 2014-02-21 17:20:58 +0000 | [diff] [blame] | 85 | remote_url=$(eval "$GIT" config --get remote.origin.url) |
szager@chromium.org | 143c3ff | 2013-01-03 23:08:41 +0000 | [diff] [blame] | 86 | if [ -n "$remote_url" -a "$remote_url" != "$CANONICAL_GIT_URL" ]; then |
| 87 | echo "Your copy of depot_tools is configured to fetch from an obsolete URL:" |
| 88 | echo |
| 89 | echo " $remote_url" |
| 90 | echo |
| 91 | read -t 60 -p "OK to update it to $CANONICAL_GIT_URL ? [Y/n] " -n 1 |
stuart@fivemicro.com | 4fa0246 | 2013-10-08 01:50:18 +0000 | [diff] [blame] | 92 | STATUS=$? |
szager@chromium.org | 143c3ff | 2013-01-03 23:08:41 +0000 | [diff] [blame] | 93 | echo |
stuart@fivemicro.com | 4fa0246 | 2013-10-08 01:50:18 +0000 | [diff] [blame] | 94 | if [[ $STATUS -ne 0 ]]; then |
szager@chromium.org | 143c3ff | 2013-01-03 23:08:41 +0000 | [diff] [blame] | 95 | echo "Timeout; not updating remote URL." |
| 96 | elif [ -z "$REPLY" -o "$REPLY" = "Y" -o "$REPLY" = "y" ]; then |
mmoss@chromium.org | 3b16a28 | 2014-02-21 17:20:58 +0000 | [diff] [blame] | 97 | eval "$GIT" config remote.origin.url "$CANONICAL_GIT_URL" |
szager@chromium.org | 143c3ff | 2013-01-03 23:08:41 +0000 | [diff] [blame] | 98 | echo "Remote URL updated." |
| 99 | fi |
| 100 | fi |
| 101 | |
Aaron Gable | a0e5cc4 | 2016-06-21 07:22:18 -0700 | [diff] [blame] | 102 | git fetch -q origin &> /dev/null |
Edward Lemur | 9577daf | 2019-11-12 18:05:55 +0000 | [diff] [blame] | 103 | local CHECKOUT_TXT STATUS |
Edward Lemur | fedbb7d | 2019-08-22 21:00:13 +0000 | [diff] [blame] | 104 | CHECKOUT_TXT=$(git checkout -q origin/master 2>&1) |
Aaron Gable | a0e5cc4 | 2016-06-21 07:22:18 -0700 | [diff] [blame] | 105 | STATUS=$? |
| 106 | if [[ $STATUS -ne 0 ]]; then |
| 107 | echo "depot_tools update failed. Conflict in $base_dir" >&2 |
Edward Lemur | 7f90416 | 2019-08-22 17:57:25 +0000 | [diff] [blame] | 108 | echo "$CHECKOUT_TXT" >&2 |
cmp@chromium.org | b9d08ce | 2012-05-01 18:32:43 +0000 | [diff] [blame] | 109 | fi |
Edward Lemur | 9577daf | 2019-11-12 18:05:55 +0000 | [diff] [blame] | 110 | # Having python3 on depot_tools causes problems if users put depot_tools in |
| 111 | # PATH before system's python3, so remove it if present. |
| 112 | # See crbug.com/1017812. |
| 113 | if [[ -e python3 ]]; then |
| 114 | rm python3 |
| 115 | fi |
Aaron Gable | a0e5cc4 | 2016-06-21 07:22:18 -0700 | [diff] [blame] | 116 | return $STATUS |
mhm@chromium.org | 31ced09 | 2011-03-14 01:37:35 +0000 | [diff] [blame] | 117 | } |
msb@chromium.org | 2a94904 | 2010-10-18 18:04:01 +0000 | [diff] [blame] | 118 | |
maruel@chromium.org | 3bc36d1 | 2011-04-14 22:02:08 +0000 | [diff] [blame] | 119 | # Update git checkouts. |
Dan Jacques | 5aeeb72 | 2017-07-28 15:22:25 +0200 | [diff] [blame] | 120 | if [ "X$DEPOT_TOOLS_UPDATE" != "X0" ]; then |
| 121 | if [ -e "$base_dir/.git" ]; then |
| 122 | cd $base_dir |
| 123 | update_git_repo |
| 124 | cd - > /dev/null |
| 125 | fi |
| 126 | |
Edward Lemur | 2499525 | 2019-09-18 18:31:07 +0000 | [diff] [blame] | 127 | # Sync CIPD-boostrapped packages. |
Edward Lemur | f73f0f4 | 2019-09-16 22:23:45 +0000 | [diff] [blame] | 128 | source "$base_dir/cipd_bin_setup.sh" |
| 129 | cipd_bin_setup |
| 130 | |
Edward Lemur | 2499525 | 2019-09-18 18:31:07 +0000 | [diff] [blame] | 131 | # Don't bootstrap Python 3 on windows, since it is already done by |
| 132 | # bootstrap/win_tools.bat. |
| 133 | if [ "X$MINGW" != "X0" -a "X$DEPOT_TOOLS_BOOTSTRAP_PYTHON3" != "X0" ]; then |
| 134 | source "$base_dir/bootstrap_python3" |
| 135 | bootstrap_python3 |
| 136 | fi |
msb@chromium.org | 2a94904 | 2010-10-18 18:04:01 +0000 | [diff] [blame] | 137 | fi |
| 138 | |