blob: 993298f91bd72e2856c725dde1726ab49858b0c5 [file] [log] [blame]
[email protected]711a16a2011-05-21 09:30:431#!/usr/bin/env bash
[email protected]6fd50f52012-07-17 19:23:392# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]2a949042010-10-18 18:04:013# 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]31dcb492011-05-12 20:36:388if [ "$USER" == "root" ];
9then
10 echo Running depot tools as root is sad.
11 exit
12fi
13
[email protected]cf231dd2016-03-30 02:45:1514# 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
[email protected]3b16a282014-02-21 17:20:5829# hardcode the paths to SVN and Git where possible.
30OUTPUT="$(uname | grep 'MINGW')"
31MINGW=$?
32
33if [ $MINGW = 0 ]; then
[email protected]4845f0e2015-06-29 22:54:5834 base_dir="${0%/*}"
[email protected]3b16a282014-02-21 17:20:5835else
36 base_dir=$(dirname "$0")
37 if [ -L "$base_dir" ]; then
[email protected]6fe66e12011-04-12 23:12:3538 base_dir=`cd "$base_dir" && pwd -P`
[email protected]3b16a282014-02-21 17:20:5839 fi
[email protected]6fe66e12011-04-12 23:12:3540fi
[email protected]2a949042010-10-18 18:04:0141
[email protected]cf231dd2016-03-30 02:45:1542# We want to update the bundled tools even under MinGW.
43if [ $MINGW = 0 ]; then
[email protected]02ef57e2016-03-30 01:46:4144 $COMSPEC /c `cygpath -w "$base_dir/bootstrap/win/win_tools.bat"`
[email protected]3466b0d2016-04-04 19:50:2045 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]682d0d72014-01-18 01:28:4955fi
56
[email protected]9f36c382013-01-07 23:53:3657CANONICAL_GIT_URL="https://chromium.googlesource.com/chromium/tools/depot_tools.git"
[email protected]143c3ff2013-01-03 23:08:4158
[email protected]4c6e4042011-06-01 18:52:3159SVN="svn"
60if [ -d "$base_dir/svn_bin" -a $MINGW = 0 ]; then
61 SVN="$base_dir/svn_bin/svn.exe"
62fi
63
64GIT="git"
[email protected]3b16a282014-02-21 17:20:5865if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then
66 GIT="cmd.exe //c \"$base_dir\\git.bat\""
[email protected]4c6e4042011-06-01 18:52:3167fi
68
[email protected]2a949042010-10-18 18:04:0169# Test git and git --version.
70function test_git {
[email protected]9f9aba12012-11-26 17:51:1571 local GITV
[email protected]3b16a282014-02-21 17:20:5872 GITV="$(eval "$GIT" --version)" || {
[email protected]2a949042010-10-18 18:04:0173 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.
86function test_git_svn {
[email protected]9f9aba12012-11-26 17:51:1587 local GITV
[email protected]3b16a282014-02-21 17:20:5888 GITV="$(eval "$GIT" svn --version)" || {
[email protected]2a949042010-10-18 18:04:0189 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]b9d08ce2012-05-01 18:32:43102function is_git_clone_repo {
[email protected]3b16a282014-02-21 17:20:58103 eval "$GIT" config remote.origin.fetch > /dev/null
[email protected]b9d08ce2012-05-01 18:32:43104}
105
106function update_git_repo {
[email protected]3b16a282014-02-21 17:20:58107 remote_url=$(eval "$GIT" config --get remote.origin.url)
[email protected]143c3ff2013-01-03 23:08:41108 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]4fa02462013-10-08 01:50:18114 STATUS=$?
[email protected]143c3ff2013-01-03 23:08:41115 echo
[email protected]4fa02462013-10-08 01:50:18116 if [[ $STATUS -ne 0 ]]; then
[email protected]143c3ff2013-01-03 23:08:41117 echo "Timeout; not updating remote URL."
118 elif [ -z "$REPLY" -o "$REPLY" = "Y" -o "$REPLY" = "y" ]; then
[email protected]3b16a282014-02-21 17:20:58119 eval "$GIT" config remote.origin.url "$CANONICAL_GIT_URL"
[email protected]143c3ff2013-01-03 23:08:41120 echo "Remote URL updated."
121 fi
122 fi
123
[email protected]b9d08ce2012-05-01 18:32:43124 if is_git_clone_repo; then
[email protected]21649262012-11-09 03:30:05125 git fetch -q origin &> /dev/null
[email protected]9f9aba12012-11-26 17:51:15126 local REBASE_TXT STATUS
127 REBASE_TXT=$(git rebase -q origin/master 2>&1)
128 STATUS=$?
129 if [[ $STATUS -ne 0 ]]; then
[email protected]21649262012-11-09 03:30:05130 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]b9d08ce2012-05-01 18:32:43135 fi
136
137 test_git_svn
138 # work around a git-svn --quiet bug
[email protected]3b16a282014-02-21 17:20:58139 OUTPUT=`eval "$GIT" svn rebase -q -q`
[email protected]b9d08ce2012-05-01 18:32:43140 if [[ ! "$OUTPUT" == *Current.branch* ]]; then
141 echo $OUTPUT 1>&2
142 fi
143 return 0
144}
145
[email protected]31ced092011-03-14 01:37:35146# Get the current SVN revision.
147get_svn_revision() {
[email protected]4c6e4042011-06-01 18:52:31148 LANGUAGE=C "$SVN" info "$base_dir" | \
[email protected]736aefe2011-04-19 18:01:08149 awk -F': ' '{ if ($1 == "Last Changed Rev") { print $2 }}'
[email protected]31ced092011-03-14 01:37:35150}
[email protected]2a949042010-10-18 18:04:01151
[email protected]3bc36d12011-04-14 22:02:08152# Update git checkouts.
[email protected]2a949042010-10-18 18:04:01153if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.git" ]
154then
155 cd $base_dir
[email protected]b9d08ce2012-05-01 18:32:43156 update_git_repo
[email protected]2a949042010-10-18 18:04:01157 cd - > /dev/null
158fi
159
[email protected]28e0e942011-02-23 18:49:54160# We're on POSIX. We can now safely look for svn checkout.
[email protected]2a949042010-10-18 18:04:01161if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.svn" ]
162then
[email protected]17c47712016-05-23 23:53:44163 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]e6c00f32012-04-13 15:39:49174 # Update the root directory to stay up-to-date with the latest depot_tools.
[email protected]31ced092011-03-14 01:37:35175 BEFORE_REVISION=$(get_svn_revision)
[email protected]884b52c2014-12-12 19:26:49176 if echo $* | grep -e --force > /dev/null; then
[email protected]69b67582014-11-25 23:34:41177 "$SVN" -q revert -R "$base_dir"
178 fi
[email protected]4c6e4042011-06-01 18:52:31179 "$SVN" -q up "$base_dir"
[email protected]31ced092011-03-14 01:37:35180 AFTER_REVISION=$(get_svn_revision)
181 if [[ "$BEFORE_REVISION" != "$AFTER_REVISION" ]]; then
[email protected]48d661e2015-04-13 14:03:53182 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]31ced092011-03-14 01:37:35185 fi
[email protected]2a949042010-10-18 18:04:01186fi
[email protected]81a82a92011-09-28 00:05:15187
[email protected]02ad7532015-09-11 17:04:32188find "$base_dir" -iname "*.pyc" -exec rm -f {} \;