update_depot_tools 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. GIT="git"
  49. if [ -e "$base_dir/git.bat" -a $MINGW = 0 ]; then
  50. GIT="cmd.exe //c \"$base_dir\\git.bat\""
  51. fi
  52. # Test git and git --version.
  53. function test_git {
  54. local GITV
  55. GITV="$(eval "$GIT" --version)" || {
  56. echo "git isn't installed, please install it"
  57. exit 1
  58. }
  59. GITV="${GITV##* }" # Only examine last word (i.e. version number)
  60. local GITD=( ${GITV//./ } ) # Split version number into decimals
  61. if ((GITD[0] < 1 || (GITD[0] == 2 && GITD[1] < 8) )); then
  62. echo "git version is ${GITV}, please update to a version later than 2.8"
  63. exit 1
  64. fi
  65. }
  66. function update_git_repo {
  67. remote_url=$(eval "$GIT" config --get remote.origin.url)
  68. local GIT_CMD_TXT STATUS
  69. GIT_CMD_TXT=$(git fetch -q origin main 2>&1)
  70. STATUS=$?
  71. if [[ $STATUS -ne 0 ]]; then
  72. echo "depot_tools update failed. Couldn't fetch main branch."
  73. echo "Retry later or reclone depot_tools" >&2
  74. echo "$GIT_CMD_TXT" >&2
  75. else
  76. GIT_CMD_TXT=$(git checkout -q origin/main 2>&1)
  77. STATUS=$?
  78. if [[ $STATUS -ne 0 ]]; then
  79. echo "depot_tools update failed. Conflict in $base_dir" >&2
  80. echo "$GIT_CMD_TXT" >&2
  81. fi
  82. fi
  83. # Having python3 on depot_tools causes problems if users put depot_tools in
  84. # PATH before system's python3, so remove it if present.
  85. # See crbug.com/1017812.
  86. if [[ -e python3 ]]; then
  87. rm python3
  88. fi
  89. return $STATUS
  90. }
  91. # Update git checkouts.
  92. if [ "X$DEPOT_TOOLS_UPDATE" = "X0" ]; then
  93. echo "DEPOT_TOOLS_UPDATE environment variable is 0, skipping update. Set DEPOT_TOOLS_UPDATE to 1 to force update." >&2
  94. else
  95. if [ -e "$base_dir/.git" ]; then
  96. cd "$base_dir"
  97. update_git_repo
  98. UPDATE_RESULT=$?
  99. cd - > /dev/null
  100. if [[ $UPDATE_RESULT -ne 0 ]]; then
  101. exit $UPDATE_RESULT
  102. fi
  103. else
  104. echo "Warning: Your depot_tools directory does not appear to be a git repository, and cannot be updated." 1>&2
  105. 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
  106. fi
  107. # Sync CIPD-boostrapped packages.
  108. source "$base_dir/cipd_bin_setup.sh"
  109. cipd_bin_setup &> /dev/null
  110. # Don't bootstrap Python 3 on windows, since it is already done by
  111. # bootstrap/win_tools.bat.
  112. if [ "X$MINGW" != "X0" -a "X$DEPOT_TOOLS_BOOTSTRAP_PYTHON3" != "X0" ]; then
  113. source "$base_dir/bootstrap_python3"
  114. bootstrap_python3
  115. fi
  116. fi