blob: 631fe1d999501c83bc0a12fd173b9141e8d8e972 [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
Aaron Gablea0e5cc42016-06-21 14:22:1829# hardcode the paths to Git where possible.
[email protected]3b16a282014-02-21 17:20:5830OUTPUT="$(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:3159GIT="git"
[email protected]3b16a282014-02-21 17:20:5860if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then
61 GIT="cmd.exe //c \"$base_dir\\git.bat\""
[email protected]4c6e4042011-06-01 18:52:3162fi
63
[email protected]2a949042010-10-18 18:04:0164# Test git and git --version.
65function test_git {
[email protected]9f9aba12012-11-26 17:51:1566 local GITV
[email protected]3b16a282014-02-21 17:20:5867 GITV="$(eval "$GIT" --version)" || {
[email protected]2a949042010-10-18 18:04:0168 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 Gablea0e5cc42016-06-21 14:22:1874 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]2a949042010-10-18 18:04:0176 exit 1
77 fi
78}
79
[email protected]b9d08ce2012-05-01 18:32:4380function update_git_repo {
[email protected]3b16a282014-02-21 17:20:5881 remote_url=$(eval "$GIT" config --get remote.origin.url)
[email protected]143c3ff2013-01-03 23:08:4182 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]4fa02462013-10-08 01:50:1888 STATUS=$?
[email protected]143c3ff2013-01-03 23:08:4189 echo
[email protected]4fa02462013-10-08 01:50:1890 if [[ $STATUS -ne 0 ]]; then
[email protected]143c3ff2013-01-03 23:08:4191 echo "Timeout; not updating remote URL."
92 elif [ -z "$REPLY" -o "$REPLY" = "Y" -o "$REPLY" = "y" ]; then
[email protected]3b16a282014-02-21 17:20:5893 eval "$GIT" config remote.origin.url "$CANONICAL_GIT_URL"
[email protected]143c3ff2013-01-03 23:08:4194 echo "Remote URL updated."
95 fi
96 fi
97
Aaron Gablea0e5cc42016-06-21 14:22:1898 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]b9d08ce2012-05-01 18:32:43106 fi
Aaron Gablea0e5cc42016-06-21 14:22:18107 return $STATUS
[email protected]31ced092011-03-14 01:37:35108}
[email protected]2a949042010-10-18 18:04:01109
[email protected]3bc36d12011-04-14 22:02:08110# Update git checkouts.
[email protected]2a949042010-10-18 18:04:01111if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.git" ]
112then
113 cd $base_dir
[email protected]b9d08ce2012-05-01 18:32:43114 update_git_repo
[email protected]2a949042010-10-18 18:04:01115 cd - > /dev/null
116fi
117
[email protected]28e0e942011-02-23 18:49:54118# We're on POSIX. We can now safely look for svn checkout.
[email protected]2a949042010-10-18 18:04:01119if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.svn" ]
120then
[email protected]17c47712016-05-23 23:53:44121 echo "========================"
122 echo "WARNING: You have an SVN checkout of depot_tools!"
123 echo
Aaron Gablea0e5cc42016-06-21 14:22:18124 echo "depot_tools has migrated to Git. You are"
125 echo "NO LONGER RECEIVING UPDATES to depot_tools."
[email protected]17c47712016-05-23 23:53:44126 echo
Aaron Gablea0e5cc42016-06-21 14:22:18127 echo "You must follow these instructions[1] to get a Git copy of depot_tools."
[email protected]17c47712016-05-23 23:53:44128 echo
129 echo "[1]: https://www.chromium.org/developers/how-tos/install-depot-tools"
130 echo "========================"
Aaron Gablea0e5cc42016-06-21 14:22:18131 return 1
[email protected]2a949042010-10-18 18:04:01132fi
[email protected]81a82a92011-09-28 00:05:15133
[email protected]02ad7532015-09-11 17:04:32134find "$base_dir" -iname "*.pyc" -exec rm -f {} \;