OLD | NEW |
1 #!/usr/bin/env bash | 1 #!/usr/bin/env bash |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # This script will try to sync the bootstrap directories and then defer control. | 6 # This script will try to sync the bootstrap directories and then defer control. |
7 | 7 |
8 if [ "$USER" == "root" ]; | 8 if [ "$USER" == "root" ]; |
9 then | 9 then |
10 echo Running depot tools as root is sad. | 10 echo Running depot tools as root is sad. |
11 exit | 11 exit |
12 fi | 12 fi |
13 | 13 |
14 base_dir=$(dirname "$0") | 14 base_dir=$(dirname "$0") |
15 if [ -L "$base_dir" ] | 15 if [ -L "$base_dir" ] |
16 then | 16 then |
17 base_dir=`cd "$base_dir" && pwd -P` | 17 base_dir=`cd "$base_dir" && pwd -P` |
18 fi | 18 fi |
19 | 19 |
| 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 |
20 # Test git and git --version. | 35 # Test git and git --version. |
21 function test_git { | 36 function test_git { |
22 local GITV="$(git --version)" || { | 37 local GITV="$("$GIT" --version)" || { |
23 echo "git isn't installed, please install it" | 38 echo "git isn't installed, please install it" |
24 exit 1 | 39 exit 1 |
25 } | 40 } |
26 | 41 |
27 GITV="${GITV##* }" # Only examine last word (i.e. version number) | 42 GITV="${GITV##* }" # Only examine last word (i.e. version number) |
28 local GITD=( ${GITV//./ } ) # Split version number into decimals | 43 local GITD=( ${GITV//./ } ) # Split version number into decimals |
29 if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then | 44 if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then |
30 echo "git version is ${GITV}, please update to a version later than 1.6" | 45 echo "git version is ${GITV}, please update to a version later than 1.6" |
31 exit 1 | 46 exit 1 |
32 fi | 47 fi |
33 } | 48 } |
34 | 49 |
35 # Test git svn and git svn --version. | 50 # Test git svn and git svn --version. |
36 function test_git_svn { | 51 function test_git_svn { |
37 local GITV="$(git svn --version)" || { | 52 local GITV="$("$GIT" svn --version)" || { |
38 echo "git-svn isn't installed, please install it" | 53 echo "git-svn isn't installed, please install it" |
39 exit 1 | 54 exit 1 |
40 } | 55 } |
41 | 56 |
42 GITV="${GITV#* version }" # git svn --version has extra output to remove. | 57 GITV="${GITV#* version }" # git svn --version has extra output to remove. |
43 GITV="${GITV% (svn*}" | 58 GITV="${GITV% (svn*}" |
44 local GITD=( ${GITV//./ } ) # Split version number into decimals | 59 local GITD=( ${GITV//./ } ) # Split version number into decimals |
45 if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then | 60 if ((GITD[0] < 1 || (GITD[0] == 1 && GITD[1] < 6) )); then |
46 echo "git version is ${GITV}, please update to a version later than 1.6" | 61 echo "git version is ${GITV}, please update to a version later than 1.6" |
47 exit 1 | 62 exit 1 |
48 fi | 63 fi |
49 } | 64 } |
50 | 65 |
51 # Get the current SVN revision. | 66 # Get the current SVN revision. |
52 get_svn_revision() { | 67 get_svn_revision() { |
53 LANGUAGE=C svn info "$base_dir" | \ | 68 LANGUAGE=C "$SVN" info "$base_dir" | \ |
54 awk -F': ' '{ if ($1 == "Last Changed Rev") { print $2 }}' | 69 awk -F': ' '{ if ($1 == "Last Changed Rev") { print $2 }}' |
55 } | 70 } |
56 | 71 |
57 # Update git checkouts. | 72 # Update git checkouts. |
58 if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.git" ] | 73 if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.git" ] |
59 then | 74 then |
60 cd $base_dir | 75 cd $base_dir |
61 test_git_svn | 76 test_git_svn |
62 # work around a git-svn --quiet bug | 77 # work around a git-svn --quiet bug |
63 OUTPUT=`git svn rebase -q -q` | 78 OUTPUT=`"$GIT" svn rebase -q -q` |
64 if [[ ! "$OUTPUT" == *Current.branch* ]]; then | 79 if [[ ! "$OUTPUT" == *Current.branch* ]]; then |
65 echo $OUTPUT 1>&2 | 80 echo $OUTPUT 1>&2 |
66 fi | 81 fi |
67 cd - > /dev/null | 82 cd - > /dev/null |
68 fi | 83 fi |
69 | 84 |
70 # We're on POSIX. We can now safely look for svn checkout. | 85 # We're on POSIX. We can now safely look for svn checkout. |
71 if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.svn" ] | 86 if [ "X$DEPOT_TOOLS_UPDATE" != "X0" -a -e "$base_dir/.svn" ] |
72 then | 87 then |
73 # Update the bootstrap directory to stay up-to-date with the latest | 88 # Update the bootstrap directory to stay up-to-date with the latest |
74 # depot_tools. | 89 # depot_tools. |
75 BEFORE_REVISION=$(get_svn_revision) | 90 BEFORE_REVISION=$(get_svn_revision) |
76 svn -q up "$base_dir" | 91 "$SVN" -q up "$base_dir" |
77 AFTER_REVISION=$(get_svn_revision) | 92 AFTER_REVISION=$(get_svn_revision) |
78 if [[ "$BEFORE_REVISION" != "$AFTER_REVISION" ]]; then | 93 if [[ "$BEFORE_REVISION" != "$AFTER_REVISION" ]]; then |
79 echo "Depot Tools has been updated to revision $AFTER_REVISION." 1>&2 | 94 echo "Depot Tools has been updated to revision $AFTER_REVISION." 1>&2 |
80 fi | 95 fi |
81 fi | 96 fi |
OLD | NEW |