update_depot_tools 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # This script will try to sync the bootstrap directories and then defer control.
  6. if [ "$USER" == "root" ];
  7. then
  8. echo Running depot tools as root is sad.
  9. exit
  10. fi
  11. # Export for other depot_tools scripts to re-use.
  12. export DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$(dirname "$0")}"
  13. # Test if this script is running under a MSYS install. This is likely an error
  14. # if it is, so we warn the user accordingly.
  15. OUTPUT="$(uname | grep 'MSYS')"
  16. MSYS=$?
  17. if [ $MSYS = 0 ]; then
  18. echo 'WARNING: It looks like you are running these tools from an MSYS shell'
  19. echo '(as opposed to a MinGW shell). This shell is not supported and may'
  20. echo 'fail in mysterious ways.'
  21. echo
  22. echo 'To run the supported MinGW shell, use `git bash`, or use `bin/bash.exe`'
  23. echo 'in your MinGW installation, as opposed to `usr/bin/bash.exe`.'
  24. echo
  25. fi
  26. base_dir="${DEPOT_TOOLS_DIR}"
  27. if [ -e "$base_dir/.disable_auto_update" ]; then
  28. exit
  29. fi
  30. # Test if this script is running under a MinGW install. If it is, we will
  31. # hardcode the paths to Git where possible.
  32. OUTPUT="$(uname | grep 'MINGW')"
  33. MINGW=$?
  34. # We want to update the bundled tools even under MinGW.
  35. if [ $MINGW = 0 ]; then
  36. $COMSPEC //c `cygpath -w "$base_dir/bootstrap/win_tools.bat"`
  37. case $? in
  38. 123)
  39. # msys environment was upgraded, need to quit.
  40. exit 123
  41. ;;
  42. 0)
  43. ;;
  44. *)
  45. exit $?
  46. esac
  47. fi
  48. CANONICAL_GIT_URL="https://chromium.googlesource.com/chromium/tools/depot_tools.git"
  49. GIT="git"
  50. if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then
  51. GIT="cmd.exe //c \"$base_dir\\git.bat\""
  52. fi
  53. # Test git and git --version.
  54. function test_git {
  55. local GITV
  56. GITV="$(eval "$GIT" --version)" || {
  57. echo "git isn't installed, please install it"
  58. exit 1
  59. }
  60. GITV="${GITV##* }" # Only examine last word (i.e. version number)
  61. local GITD=( ${GITV//./ } ) # Split version number into decimals
  62. if ((GITD[0] < 1 || (GITD[0] == 2 && GITD[1] < 8) )); then
  63. echo "git version is ${GITV}, please update to a version later than 2.8"
  64. exit 1
  65. fi
  66. }
  67. function update_git_repo {
  68. remote_url=$(eval "$GIT" config --get remote.origin.url)
  69. if [ -n "$remote_url" -a "$remote_url" != "$CANONICAL_GIT_URL" ]; then
  70. echo "Your copy of depot_tools is configured to fetch from an obsolete URL:"
  71. echo
  72. echo " $remote_url"
  73. echo
  74. read -t 60 -p "OK to update it to $CANONICAL_GIT_URL ? [Y/n] " -n 1
  75. STATUS=$?
  76. echo
  77. if [[ $STATUS -ne 0 ]]; then
  78. echo "Timeout; not updating remote URL."
  79. elif [ -z "$REPLY" -o "$REPLY" = "Y" -o "$REPLY" = "y" ]; then
  80. eval "$GIT" config remote.origin.url "$CANONICAL_GIT_URL"
  81. echo "Remote URL updated."
  82. fi
  83. fi
  84. local GIT_CMD_TXT STATUS
  85. GIT_CMD_TXT=$(git fetch -q origin main 2>&1)
  86. STATUS=$?
  87. if [[ $STATUS -ne 0 ]]; then
  88. echo "depot_tools update failed. Couldn't fetch main branch."
  89. echo "Retry later or reclone depot_tools" >&2
  90. echo "$GIT_CMD_TXT" >&2
  91. else
  92. GIT_CMD_TXT=$(git checkout -q origin/main 2>&1)
  93. STATUS=$?
  94. if [[ $STATUS -ne 0 ]]; then
  95. echo "depot_tools update failed. Conflict in $base_dir" >&2
  96. echo "$GIT_CMD_TXT" >&2
  97. fi
  98. fi
  99. # Having python3 on depot_tools causes problems if users put depot_tools in
  100. # PATH before system's python3, so remove it if present.
  101. # See crbug.com/1017812.
  102. if [[ -e python3 ]]; then
  103. rm python3
  104. fi
  105. return $STATUS
  106. }
  107. # Update git checkouts.
  108. if [ "X$DEPOT_TOOLS_UPDATE" != "X0" ]; then
  109. if [ -e "$base_dir/.git" ]; then
  110. cd "$base_dir"
  111. update_git_repo
  112. UPDATE_RESULT=$?
  113. cd - > /dev/null
  114. if [[ $UPDATE_RESULT -ne 0 ]]; then
  115. exit $UPDATE_RESULT
  116. fi
  117. else
  118. echo "Warning: Your depot_tools directory does not appear to be a git repository, and cannot be updated." 1>&2
  119. echo "Consider deleting your depot_tools directory and following the instructions at https://www.chromium.org/developers/how-tos/install-depot-tools/ to reinstall it." 1>&2
  120. fi
  121. # Sync CIPD-boostrapped packages.
  122. source "$base_dir/cipd_bin_setup.sh"
  123. cipd_bin_setup
  124. # Don't bootstrap Python 3 on windows, since it is already done by
  125. # bootstrap/win_tools.bat.
  126. if [ "X$MINGW" != "X0" -a "X$DEPOT_TOOLS_BOOTSTRAP_PYTHON3" != "X0" ]; then
  127. source "$base_dir/bootstrap_python3"
  128. bootstrap_python3
  129. fi
  130. fi