From 67702834ccbdc6e8f054f9cd2ba97a8c76848cd2 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 23 Jan 2023 15:31:10 +0000 Subject: [PATCH] cipd/python: optimize cat usage Bash has a builtin for reading files, so use that instead of running the cat program to save on time & overhead. Change-Id: Ia90fc22a47f2ead4ef056020a79ebdebd7bd70ca Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4111082 Reviewed-by: Brian Ryner Commit-Queue: Mike Frysinger Reviewed-by: Gavin Mak --- cipd | 6 +++--- python-bin/python3 | 2 +- python2-bin/python2 | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cipd b/cipd index 11f7475118..dc305f8aa3 100755 --- a/cipd +++ b/cipd @@ -90,13 +90,13 @@ CIPD_BACKEND="https://chrome-infra-packages.appspot.com" VERSION_FILE="${MYPATH}/cipd_client_version" CLIENT="${MYPATH}/.cipd_client" -VERSION=`cat "${VERSION_FILE}"` +VERSION=$(<"${VERSION_FILE}") PLATFORM="${OS}-${ARCH}" # A value in .cipd_client_platform overrides the "guessed" platform. PLATFORM_OVERRIDE_FILE="${MYPATH}/.cipd_client_platform" if [ -f "${PLATFORM_OVERRIDE_FILE}" ]; then - PLATFORM=`cat ${PLATFORM_OVERRIDE_FILE}` + PLATFORM=$(<"${PLATFORM_OVERRIDE_FILE}") fi URL="${CIPD_BACKEND}/client?platform=${PLATFORM}&version=${VERSION}" @@ -232,7 +232,7 @@ function self_update() { # so mismatches are very unlikely. INSTALLED_VERSION_FILE="${MYPATH}/.versions/.cipd_client.cipd_version" if [ -f "${INSTALLED_VERSION_FILE}" ]; then - JSON_BODY=`cat "${INSTALLED_VERSION_FILE}"` + JSON_BODY=$(<"${INSTALLED_VERSION_FILE}") if [[ "$JSON_BODY" != *"infra/tools/cipd/${PLATFORM}"* ]]; then >&2 echo "Detected CIPD client platform change to ${PLATFORM}." >&2 echo "Deleting the existing client to trigger the bootstrap..." diff --git a/python-bin/python3 b/python-bin/python3 index eec3590160..a29fdc63cf 100755 --- a/python-bin/python3 +++ b/python-bin/python3 @@ -6,7 +6,7 @@ if [ "$OSTYPE" = "msys" ] then PYTHON3_BIN_DIR="$DEPOT_TOOLS/$(sed -e 's-\\-/-g' $DEPOT_TOOLS/python3_bin_reldir.txt)" else - PYTHON3_BIN_DIR="$DEPOT_TOOLS/$(cat $DEPOT_TOOLS/python3_bin_reldir.txt)" + PYTHON3_BIN_DIR="$DEPOT_TOOLS/$(<"$DEPOT_TOOLS/python3_bin_reldir.txt")" fi PATH="$PYTHON3_BIN_DIR":"$PYTHON3_BIN_DIR/Scripts":"$PATH" "$PYTHON3_BIN_DIR/python3" "$@" diff --git a/python2-bin/python2 b/python2-bin/python2 index a5a27f2be2..f488199daf 100755 --- a/python2-bin/python2 +++ b/python2-bin/python2 @@ -8,7 +8,7 @@ then # this converts them to the forward slashes a unix environment expects. PYTHON_BIN_DIR="$DEPOT_TOOLS/$(sed -e 's-\\-/-g' $DEPOT_TOOLS/python_bin_reldir.txt)" else - PYTHON_BIN_DIR="$DEPOT_TOOLS/$(cat $DEPOT_TOOLS/python_bin_reldir.txt)" + PYTHON_BIN_DIR="$DEPOT_TOOLS/$(<"$DEPOT_TOOLS/python_bin_reldir.txt")" fi PATH="$PYTHON_BIN_DIR":"$PATH" "$PYTHON_BIN_DIR/python" "$@"