瀏覽代碼

setup & share path to depot_tools checkout

A lot of scripts like to compute the dirname of $0 to find itself to
load more files.  Have some scripts export & resuse this value so we
avoid recalculating when not needed.

Bug: 1469696
Change-Id: I3aac2e6119dbfa3c68715208df2786f67cdce92e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4750430
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Mike Frysinger 2 年之前
父節點
當前提交
248aa8ba81
共有 6 個文件被更改,包括 21 次插入12 次删除
  1. 4 1
      cipd
  2. 1 1
      cipd_bin_setup.sh
  3. 4 1
      ensure_bootstrap
  4. 4 1
      update_depot_tools
  5. 4 4
      vpython
  6. 4 4
      vpython3

+ 4 - 1
cipd

@@ -6,7 +6,10 @@
 
 
 set -e -o pipefail
 set -e -o pipefail
 
 
-MYPATH=$(dirname "${BASH_SOURCE[0]}")
+# Export for other depot_tools scripts to re-use.
+export DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$(dirname "${BASH_SOURCE[0]}")}"
+
+MYPATH="${DEPOT_TOOLS_DIR}"
 CYGWIN=false
 CYGWIN=false
 
 
 # Make sure this starts empty
 # Make sure this starts empty

+ 1 - 1
cipd_bin_setup.sh

@@ -3,7 +3,7 @@
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
 function cipd_bin_setup {
 function cipd_bin_setup {
-    local MYPATH=$(dirname "${BASH_SOURCE[0]}")
+    local MYPATH="${DEPOT_TOOLS_DIR:-$(dirname "${BASH_SOURCE[0]}")}"
     local ENSURE="$MYPATH/cipd_manifest.txt"
     local ENSURE="$MYPATH/cipd_manifest.txt"
     local ROOT="$MYPATH/.cipd_bin"
     local ROOT="$MYPATH/.cipd_bin"
 
 

+ 4 - 1
ensure_bootstrap

@@ -14,12 +14,15 @@
 # invoke this script instead of manually calling "cipd_bin_setup" and other
 # invoke this script instead of manually calling "cipd_bin_setup" and other
 # operations.
 # operations.
 
 
+# Export for other depot_tools scripts to re-use.
+export DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$(dirname "${BASH_SOURCE[0]}")}"
+
 # Test if this script is running under a MinGW install.  If it is, we will
 # Test if this script is running under a MinGW install.  If it is, we will
 # hardcode the paths to Git where possible.
 # hardcode the paths to Git where possible.
 OUTPUT="$(uname | grep 'MINGW')"
 OUTPUT="$(uname | grep 'MINGW')"
 MINGW=$?
 MINGW=$?
 
 
-base_dir=$(dirname "${BASH_SOURCE[0]}")
+base_dir="${DEPOT_TOOLS_DIR}"
 if [ $MINGW != 0 ]; then
 if [ $MINGW != 0 ]; then
   # Don't bootstrap Python 3 on windows, since it is already done by
   # Don't bootstrap Python 3 on windows, since it is already done by
   # bootstrap/win_tools.bat.
   # bootstrap/win_tools.bat.

+ 4 - 1
update_depot_tools

@@ -11,6 +11,9 @@ then
   exit
   exit
 fi
 fi
 
 
+# Export for other depot_tools scripts to re-use.
+export DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$(dirname "$0")}"
+
 # Test if this script is running under a MSYS install. This is likely an error
 # Test if this script is running under a MSYS install. This is likely an error
 # if it is, so we warn the user accordingly.
 # if it is, so we warn the user accordingly.
 OUTPUT="$(uname | grep 'MSYS')"
 OUTPUT="$(uname | grep 'MSYS')"
@@ -25,7 +28,7 @@ if [ $MSYS = 0 ]; then
   echo
   echo
 fi
 fi
 
 
-base_dir=$(dirname "$0")
+base_dir="${DEPOT_TOOLS_DIR}"
 if [ -e "$base_dir/.disable_auto_update" ]; then
 if [ -e "$base_dir/.disable_auto_update" ]; then
   exit
   exit
 fi
 fi

+ 4 - 4
vpython

@@ -35,10 +35,10 @@ then
   exec "python" "${NEWARGS[@]}"
   exec "python" "${NEWARGS[@]}"
 fi
 fi
 
 
+# Export for other depot_tools scripts to re-use.
+export DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$(dirname "$0")}"
 
 
-base_dir=$(dirname "$0")
-
-source "$base_dir/cipd_bin_setup.sh"
+source "${DEPOT_TOOLS_DIR}/cipd_bin_setup.sh"
 cipd_bin_setup &> /dev/null
 cipd_bin_setup &> /dev/null
 
 
 case $(uname -s) in
 case $(uname -s) in
@@ -46,6 +46,6 @@ MINGW*|CYGWIN*)
   cmd.exe //c $0.bat "$@"
   cmd.exe //c $0.bat "$@"
   ;;
   ;;
 *)
 *)
-  exec "$base_dir/.cipd_bin/vpython" "$@"
+  exec "${DEPOT_TOOLS_DIR}/.cipd_bin/vpython" "$@"
   ;;
   ;;
 esac
 esac

+ 4 - 4
vpython3

@@ -33,10 +33,10 @@ then
   exec "python3" "${NEWARGS[@]}"
   exec "python3" "${NEWARGS[@]}"
 fi
 fi
 
 
+# Export for other depot_tools scripts to re-use.
+export DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$(dirname "$0")}"
 
 
-base_dir=$(dirname "$0")
-
-source "$base_dir/cipd_bin_setup.sh"
+source "${DEPOT_TOOLS_DIR}/cipd_bin_setup.sh"
 cipd_bin_setup &> /dev/null
 cipd_bin_setup &> /dev/null
 
 
 case $(uname -s) in
 case $(uname -s) in
@@ -44,6 +44,6 @@ MINGW*|CYGWIN*)
   cmd.exe //c $0.bat "$@"
   cmd.exe //c $0.bat "$@"
   ;;
   ;;
 *)
 *)
-  exec "$base_dir/.cipd_bin/vpython3" "$@"
+  exec "${DEPOT_TOOLS_DIR}/.cipd_bin/vpython3" "$@"
   ;;
   ;;
 esac
 esac