From 248aa8ba818b752ef507c73db988b6d32bb90df1 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 3 Aug 2023 22:05:10 +0000 Subject: [PATCH] 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 Reviewed-by: Josip Sokcevic Commit-Queue: Josip Sokcevic --- cipd | 5 ++++- cipd_bin_setup.sh | 2 +- ensure_bootstrap | 5 ++++- update_depot_tools | 5 ++++- vpython | 8 ++++---- vpython3 | 8 ++++---- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cipd b/cipd index dc305f8aa3..099526bd60 100755 --- a/cipd +++ b/cipd @@ -6,7 +6,10 @@ 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 # Make sure this starts empty diff --git a/cipd_bin_setup.sh b/cipd_bin_setup.sh index 611d1539b9..38ec886aa6 100644 --- a/cipd_bin_setup.sh +++ b/cipd_bin_setup.sh @@ -3,7 +3,7 @@ # found in the LICENSE file. 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 ROOT="$MYPATH/.cipd_bin" diff --git a/ensure_bootstrap b/ensure_bootstrap index ebcaa19a22..4e44b41b85 100755 --- a/ensure_bootstrap +++ b/ensure_bootstrap @@ -14,12 +14,15 @@ # invoke this script instead of manually calling "cipd_bin_setup" and other # 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 # hardcode the paths to Git where possible. OUTPUT="$(uname | grep 'MINGW')" MINGW=$? -base_dir=$(dirname "${BASH_SOURCE[0]}") +base_dir="${DEPOT_TOOLS_DIR}" if [ $MINGW != 0 ]; then # Don't bootstrap Python 3 on windows, since it is already done by # bootstrap/win_tools.bat. diff --git a/update_depot_tools b/update_depot_tools index f1505d0315..e5dfcd469d 100755 --- a/update_depot_tools +++ b/update_depot_tools @@ -11,6 +11,9 @@ then exit 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 # if it is, so we warn the user accordingly. OUTPUT="$(uname | grep 'MSYS')" @@ -25,7 +28,7 @@ if [ $MSYS = 0 ]; then echo fi -base_dir=$(dirname "$0") +base_dir="${DEPOT_TOOLS_DIR}" if [ -e "$base_dir/.disable_auto_update" ]; then exit fi diff --git a/vpython b/vpython index 45b0d02b58..08ed05bafc 100755 --- a/vpython +++ b/vpython @@ -35,10 +35,10 @@ then exec "python" "${NEWARGS[@]}" 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 case $(uname -s) in @@ -46,6 +46,6 @@ MINGW*|CYGWIN*) cmd.exe //c $0.bat "$@" ;; *) - exec "$base_dir/.cipd_bin/vpython" "$@" + exec "${DEPOT_TOOLS_DIR}/.cipd_bin/vpython" "$@" ;; esac diff --git a/vpython3 b/vpython3 index 27fcfc05af..307fcbd3b6 100755 --- a/vpython3 +++ b/vpython3 @@ -33,10 +33,10 @@ then exec "python3" "${NEWARGS[@]}" 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 case $(uname -s) in @@ -44,6 +44,6 @@ MINGW*|CYGWIN*) cmd.exe //c $0.bat "$@" ;; *) - exec "$base_dir/.cipd_bin/vpython3" "$@" + exec "${DEPOT_TOOLS_DIR}/.cipd_bin/vpython3" "$@" ;; esac