[email protected] | 711a16a | 2011-05-21 09:30:43 | [diff] [blame] | 1 | #!/usr/bin/env bash |
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 2 | # Copyright (c) 2011 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] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 14 | base_dir=$(dirname "$0") |
[email protected] | 6fe66e1 | 2011-04-12 23:12:35 | [diff] [blame] | 15 | if [ -L "$base_dir" ] |
16 | then | ||||
17 | base_dir=`cd "$base_dir" && pwd -P` | ||||
18 | fi | ||||
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 19 | |
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 20 | # Test if this script is running under a MSys install. If it is, we will |
21 | # hardcode the paths to SVN and Git where possible. | ||||
22 | OUTPUT="$(uname | grep 'MINGW')" | ||||
23 | MINGW=$? | ||||
24 | |||||
25 | SVN="svn" | ||||
26 | if [ -d "$base_dir/svn_bin" -a $MINGW = 0 ]; then | ||||
27 | SVN="$base_dir/svn_bin/svn.exe" | ||||
28 | fi | ||||
29 | |||||
30 | GIT="git" | ||||
31 | if [ -d "$base_dir/git_bin" -a $MINGW = 0 ]; then | ||||
32 | GIT="$base_dir/git_bin/bin/git.exe" | ||||
33 | fi | ||||
34 | |||||
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 35 | # Test git and git --version. |
36 | function test_git { | ||||
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 37 | local GITV="$("$GIT" --version)" || { |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 38 | echo "git isn't installed, please install it" |
39 | exit 1 | ||||
40 | } | ||||
41 | |||||
42 | GITV="${GITV##* }" # Only examine last word (i.e. version number) | ||||
43 | local GITD=( ${GITV//./ } ) # Split version number into decimals | ||||
44 | if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then | ||||
45 | echo "git version is ${GITV}, please update to a version later than 1.6" | ||||
46 | exit 1 | ||||
47 | fi | ||||
48 | } | ||||
49 | |||||
50 | # Test git svn and git svn --version. | ||||
51 | function test_git_svn { | ||||
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 52 | local GITV="$("$GIT" svn --version)" || { |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 53 | echo "git-svn isn't installed, please install it" |
54 | exit 1 | ||||
55 | } | ||||
56 | |||||
57 | GITV="${GITV#* version }" # git svn --version has extra output to remove. | ||||
58 | GITV="${GITV% (svn*}" | ||||
59 | local GITD=( ${GITV//./ } ) # Split version number into decimals | ||||
60 | if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then | ||||
61 | echo "git version is ${GITV}, please update to a version later than 1.6" | ||||
62 | exit 1 | ||||
63 | fi | ||||
64 | } | ||||
65 | |||||
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 66 | # Get the current SVN revision. |
67 | get_svn_revision() { | ||||
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 68 | LANGUAGE=C "$SVN" info "$base_dir" | \ |
[email protected] | 736aefe | 2011-04-19 18:01:08 | [diff] [blame] | 69 | awk -F': ' '{ if ($1 == "Last Changed Rev") { print $2 }}' |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 70 | } |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 71 | |
[email protected] | 3bc36d1 | 2011-04-14 22:02:08 | [diff] [blame] | 72 | # Update git checkouts. |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 73 | if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.git" ] |
74 | then | ||||
75 | cd $base_dir | ||||
76 | test_git_svn | ||||
77 | # work around a git-svn --quiet bug | ||||
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 78 | OUTPUT=`"$GIT" svn rebase -q -q` |
[email protected] | 7ace24d | 2011-02-28 17:58:47 | [diff] [blame] | 79 | if [[ ! "$OUTPUT" == *Current.branch* ]]; then |
[email protected] | 529e97b | 2011-03-23 01:04:45 | [diff] [blame] | 80 | echo $OUTPUT 1>&2 |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 81 | fi |
82 | cd - > /dev/null | ||||
83 | fi | ||||
84 | |||||
[email protected] | 28e0e94 | 2011-02-23 18:49:54 | [diff] [blame] | 85 | # We're on POSIX. We can now safely look for svn checkout. |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 86 | if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.svn" ] |
87 | then | ||||
[email protected] | e6c00f3 | 2012-04-13 15:39:49 | [diff] [blame] | 88 | # Update the root directory to stay up-to-date with the latest depot_tools. |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 89 | BEFORE_REVISION=$(get_svn_revision) |
[email protected] | 4c6e404 | 2011-06-01 18:52:31 | [diff] [blame] | 90 | "$SVN" -q up "$base_dir" |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 91 | AFTER_REVISION=$(get_svn_revision) |
92 | if [[ "$BEFORE_REVISION" != "$AFTER_REVISION" ]]; then | ||||
[email protected] | 529e97b | 2011-03-23 01:04:45 | [diff] [blame] | 93 | echo "Depot Tools has been updated to revision $AFTER_REVISION." 1>&2 |
[email protected] | 31ced09 | 2011-03-14 01:37:35 | [diff] [blame] | 94 | fi |
[email protected] | 2a94904 | 2010-10-18 18:04:01 | [diff] [blame] | 95 | fi |
[email protected] | 81a82a9 | 2011-09-28 00:05:15 | [diff] [blame] | 96 | |
[email protected] | bda0503 | 2011-09-29 00:36:27 | [diff] [blame] | 97 | find "$base_dir" -iname "*.pyc" -exec rm {} \; |