blob: 82b397312b6cf84bcce7322fcc5c7f84cdd4bd7f [file] [log] [blame]
cmp@chromium.org711a16a2011-05-21 09:30:43 +00001#!/usr/bin/env bash
maruel@chromium.org6fd50f52012-07-17 19:23:39 +00002# Copyright (c) 2012 The Chromium Authors. All rights reserved.
msb@chromium.org2a949042010-10-18 18:04:01 +00003# 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.org31dcb492011-05-12 20:36:38 +00008if [ "$USER" == "root" ];
9then
10 echo Running depot tools as root is sad.
11 exit
12fi
13
iannucci@chromium.orgcf231dd2016-03-30 02:45:15 +000014# 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.
16OUTPUT="$(uname | grep 'MSYS')"
17MSYS=$?
18if [ $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
26fi
27
28# Test if this script is running under a MinGW install. If it is, we will
Aaron Gablea0e5cc42016-06-21 07:22:18 -070029# hardcode the paths to Git where possible.
mmoss@chromium.org3b16a282014-02-21 17:20:58 +000030OUTPUT="$(uname | grep 'MINGW')"
31MINGW=$?
32
33if [ $MINGW = 0 ]; then
pkasting@chromium.org4845f0e2015-06-29 22:54:58 +000034 base_dir="${0%/*}"
mmoss@chromium.org3b16a282014-02-21 17:20:58 +000035else
36 base_dir=$(dirname "$0")
37 if [ -L "$base_dir" ]; then
scottbyer@chromium.org6fe66e12011-04-12 23:12:35 +000038 base_dir=`cd "$base_dir" && pwd -P`
mmoss@chromium.org3b16a282014-02-21 17:20:58 +000039 fi
scottbyer@chromium.org6fe66e12011-04-12 23:12:35 +000040fi
msb@chromium.org2a949042010-10-18 18:04:01 +000041
Dirk Prankeecdfa412017-08-02 09:25:18 -070042if [ -e "$base_dir/.disable_auto_update" ]; then
Dan Jacques74d7e132017-06-01 15:17:15 -070043 exit
44fi
45
iannucci@chromium.orgcf231dd2016-03-30 02:45:15 +000046# We want to update the bundled tools even under MinGW.
47if [ $MINGW = 0 ]; then
Edward Lemur24995252019-09-18 18:31:07 +000048 $COMSPEC /c `cygpath -w "$base_dir/bootstrap/win_tools.bat"`
iannucci@chromium.org3466b0d2016-04-04 19:50:20 +000049 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.org682d0d72014-01-18 01:28:49 +000059fi
60
szager@chromium.org9f36c382013-01-07 23:53:36 +000061CANONICAL_GIT_URL="https://chromium.googlesource.com/chromium/tools/depot_tools.git"
szager@chromium.org143c3ff2013-01-03 23:08:41 +000062
cmp@chromium.org4c6e4042011-06-01 18:52:31 +000063GIT="git"
mmoss@chromium.org3b16a282014-02-21 17:20:58 +000064if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then
65 GIT="cmd.exe //c \"$base_dir\\git.bat\""
cmp@chromium.org4c6e4042011-06-01 18:52:31 +000066fi
67
msb@chromium.org2a949042010-10-18 18:04:01 +000068# Test git and git --version.
69function test_git {
newt@chromium.org9f9aba12012-11-26 17:51:15 +000070 local GITV
mmoss@chromium.org3b16a282014-02-21 17:20:58 +000071 GITV="$(eval "$GIT" --version)" || {
msb@chromium.org2a949042010-10-18 18:04:01 +000072 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 Gablea0e5cc42016-06-21 07:22:18 -070078 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.org2a949042010-10-18 18:04:01 +000080 exit 1
81 fi
82}
83
cmp@chromium.orgb9d08ce2012-05-01 18:32:43 +000084function update_git_repo {
mmoss@chromium.org3b16a282014-02-21 17:20:58 +000085 remote_url=$(eval "$GIT" config --get remote.origin.url)
szager@chromium.org143c3ff2013-01-03 23:08:41 +000086 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.com4fa02462013-10-08 01:50:18 +000092 STATUS=$?
szager@chromium.org143c3ff2013-01-03 23:08:41 +000093 echo
stuart@fivemicro.com4fa02462013-10-08 01:50:18 +000094 if [[ $STATUS -ne 0 ]]; then
szager@chromium.org143c3ff2013-01-03 23:08:41 +000095 echo "Timeout; not updating remote URL."
96 elif [ -z "$REPLY" -o "$REPLY" = "Y" -o "$REPLY" = "y" ]; then
mmoss@chromium.org3b16a282014-02-21 17:20:58 +000097 eval "$GIT" config remote.origin.url "$CANONICAL_GIT_URL"
szager@chromium.org143c3ff2013-01-03 23:08:41 +000098 echo "Remote URL updated."
99 fi
100 fi
101
Aaron Gablea0e5cc42016-06-21 07:22:18 -0700102 git fetch -q origin &> /dev/null
Edward Lemur9577daf2019-11-12 18:05:55 +0000103 local CHECKOUT_TXT STATUS
Edward Lemurfedbb7d2019-08-22 21:00:13 +0000104 CHECKOUT_TXT=$(git checkout -q origin/master 2>&1)
Aaron Gablea0e5cc42016-06-21 07:22:18 -0700105 STATUS=$?
106 if [[ $STATUS -ne 0 ]]; then
107 echo "depot_tools update failed. Conflict in $base_dir" >&2
Edward Lemur7f904162019-08-22 17:57:25 +0000108 echo "$CHECKOUT_TXT" >&2
cmp@chromium.orgb9d08ce2012-05-01 18:32:43 +0000109 fi
Edward Lemur9577daf2019-11-12 18:05:55 +0000110 # 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 Gablea0e5cc42016-06-21 07:22:18 -0700116 return $STATUS
mhm@chromium.org31ced092011-03-14 01:37:35 +0000117}
msb@chromium.org2a949042010-10-18 18:04:01 +0000118
maruel@chromium.org3bc36d12011-04-14 22:02:08 +0000119# Update git checkouts.
Dan Jacques5aeeb722017-07-28 15:22:25 +0200120if [ "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 Lemur24995252019-09-18 18:31:07 +0000127 # Sync CIPD-boostrapped packages.
Edward Lemurf73f0f42019-09-16 22:23:45 +0000128 source "$base_dir/cipd_bin_setup.sh"
129 cipd_bin_setup
130
Edward Lemur24995252019-09-18 18:31:07 +0000131 # 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.org2a949042010-10-18 18:04:01 +0000137fi
138