update_depot_tools 3.41 KB
Newer Older
1
#!/usr/bin/env bash
2
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 4 5 6 7
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This script will try to sync the bootstrap directories and then defer control.

8 9 10 11 12 13
if [ "$USER" == "root" ];
then
  echo Running depot tools as root is sad.
  exit
fi

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# Test if this script is running under a MSYS install. This is likely an error
# if it is, so we warn the user accordingly.
OUTPUT="$(uname | grep 'MSYS')"
MSYS=$?
if [ $MSYS = 0 ]; then
  echo 'WARNING: It looks like you are running these tools from an MSYS shell'
  echo '(as opposed to a MinGW shell). This shell is not supported and may'
  echo 'fail in mysterious ways.'
  echo
  echo 'To run the supported MinGW shell, use `git bash`, or use `bin/bash.exe`'
  echo 'in your MinGW installation, as opposed to `usr/bin/bash.exe`.'
  echo
fi

# Test if this script is running under a MinGW install.  If it is, we will
29
# hardcode the paths to Git where possible.
30 31 32 33
OUTPUT="$(uname | grep 'MINGW')"
MINGW=$?

if [ $MINGW = 0 ]; then
34
  base_dir="${0%/*}"
35 36 37
else
  base_dir=$(dirname "$0")
  if [ -L "$base_dir" ]; then
38
    base_dir=`cd "$base_dir" && pwd -P`
39
  fi
40
fi
41

42
if [ -e "$base_dir/.disable_auto_update" ]; then
43 44 45
  exit
fi

46 47
# We want to update the bundled tools even under MinGW.
if [ $MINGW = 0 ]; then
48
  $COMSPEC /c `cygpath -w "$base_dir/bootstrap/win/win_tools.bat"`
49 50 51 52 53 54 55 56 57 58
  case $? in
    123)
      # msys environment was upgraded, need to quit.
      exit 123
      ;;
    0)
      ;;
    *)
      exit $?
  esac
59 60
fi

61
CANONICAL_GIT_URL="https://chromium.googlesource.com/chromium/tools/depot_tools.git"
62

63
GIT="git"
64 65
if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then
  GIT="cmd.exe //c \"$base_dir\\git.bat\""
66 67
fi

68 69
# Test git and git --version.
function test_git {
70
  local GITV
71
  GITV="$(eval "$GIT" --version)" || {
72 73 74 75 76 77
    echo "git isn't installed, please install it"
    exit 1
  }

  GITV="${GITV##* }"          # Only examine last word (i.e. version number)
  local GITD=( ${GITV//./ } ) # Split version number into decimals
78 79
  if ((GITD[0] < 1 || (GITD[0] == 2 && GITD[1] < 8) )); then
    echo "git version is ${GITV}, please update to a version later than 2.8"
80 81 82 83
    exit 1
  fi
}

84
function update_git_repo {
85
  remote_url=$(eval "$GIT" config --get remote.origin.url)
86 87 88 89 90 91
  if [ -n "$remote_url" -a "$remote_url" != "$CANONICAL_GIT_URL" ]; then
    echo "Your copy of depot_tools is configured to fetch from an obsolete URL:"
    echo
    echo "  $remote_url"
    echo
    read -t 60 -p "OK to update it to $CANONICAL_GIT_URL ? [Y/n] " -n 1
92
    STATUS=$?
93
    echo
94
    if [[ $STATUS -ne 0 ]]; then
95 96
      echo "Timeout; not updating remote URL."
    elif [ -z "$REPLY" -o "$REPLY" = "Y" -o "$REPLY" = "y" ]; then
97
      eval "$GIT" config remote.origin.url "$CANONICAL_GIT_URL"
98 99 100 101
      echo "Remote URL updated."
    fi
  fi

102 103 104 105 106 107 108 109
  git fetch -q origin &> /dev/null
  local REBASE_TXT STATUS
  REBASE_TXT=$(git rebase -q origin/master 2>&1)
  STATUS=$?
  if [[ $STATUS -ne 0 ]]; then
    echo "depot_tools update failed. Conflict in $base_dir" >&2
    echo "$REBASE_TXT" >&2
    git rebase --abort 2> /dev/null
110
  fi
111
  return $STATUS
112
}
113

114
# Update git checkouts.
115 116 117 118 119 120 121 122 123
if [ "X$DEPOT_TOOLS_UPDATE" != "X0" ]; then
  if [ -e "$base_dir/.git" ]; then
    cd $base_dir
    update_git_repo
    cd - > /dev/null
  fi

  # Sync CIPD and CIPD client tools.
  source "$base_dir/cipd_bin_setup.sh"
124
  cipd_bin_setup
125 126

  find "$base_dir" -iname "*.pyc" -exec rm -f {} \;
127 128
fi