Skip to content

Commit e93bb93

Browse files
committed
Reduce the amount of trace output
* Reduce the number of command lines executed in most used functions * List existing versions only when installing
1 parent b5b4e84 commit e93bb93

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

travis_osx_brew_cache.sh

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
# Library to cache downloaded and locally-built Homebrew bottles in Travis OSX build.
22

3-
_BREW_ERREXIT='
4-
set -e -o pipefail
5-
trap '\''{ sleep 3; #if we terminale too abruptly, Travis will lose some log output
6-
exit 2; #The trap isn''t called in the parent function, so can''t use `return` here.
7-
#`exit` will terminate the entire build but it seems we have no choice.
8-
}'\'' ERR
9-
set -E'
103

114
#Should be in Travis' cache
125
BREW_LOCAL_BOTTLE_METADATA="$HOME/local_bottle_metadata"
@@ -37,16 +30,17 @@ function brew_install_and_cache_within_time_limit {
3730
# use bottle if available, build and cache bottle if not.
3831
# Terminate and exit with status 1 if this takes too long.
3932
# Exit with status 2 on any other error.
40-
( eval "$_BREW_ERREXIT"
41-
42-
local PACKAGE; PACKAGE="${1:?}" || exit 2
43-
local TIME_LIMIT;TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
44-
local TIME_HARD_LIMIT;TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
45-
local TIME_START;TIME_START=${4:-$BREW_TIME_START} || exit 2
33+
( set -eE -o pipefail; trap '{ sleep 3; exit 2; }' ERR
34+
35+
local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START
36+
PACKAGE="${1:?}" || exit 2
37+
TIME_LIMIT=${2:-$BREW_TIME_LIMIT} || exit 2
38+
TIME_HARD_LIMIT=${3:-$BREW_TIME_HARD_LIMIT} || exit 2
39+
TIME_START=${4:-$BREW_TIME_START} || exit 2
4640

4741
local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
4842

49-
if brew list --versions "$PACKAGE" && ! (brew outdated | grep -qx "$PACKAGE"); then
43+
if brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE"); then
5044
echo "Already installed and the latest version: $PACKAGE"
5145
return 0
5246
fi
@@ -266,8 +260,9 @@ function _brew_parse_package_info {
266260
# Get and parse `brew info --json` about a package
267261
# and save data into specified variables
268262

269-
local PACKAGE; PACKAGE="${1:?}"; shift
270-
local OS_CODENAME;OS_CODENAME="${1:?}"; shift
263+
local PACKAGE OS_CODENAME
264+
PACKAGE="${1:?}"; shift
265+
OS_CODENAME="${1:?}"; shift
271266

272267
local JSON_DATA; JSON_DATA=$(python2.7 -c 'if True:
273268
import sys, json, subprocess; j=json.loads(subprocess.check_output(("brew","info","--json=v1",sys.argv[1])))
@@ -325,12 +320,13 @@ function _brew_install_and_cache {
325320
# assumes that deps were already installed
326321
# and not already the latest version
327322

328-
local PACKAGE;PACKAGE="${1:?}"
329-
local USE_BOTTLE;USE_BOTTLE="${2:?}"
330-
local KEG_ONLY;KEG_ONLY="${3:?}"
323+
local PACKAGE USE_BOTTLE KEG_ONLY
324+
PACKAGE="${1:?}"
325+
USE_BOTTLE="${2:?}"
326+
KEG_ONLY="${3:?}"
331327
local VERB
332328

333-
if brew list --versions "$PACKAGE" >/dev/null; then
329+
if brew list --versions "$PACKAGE"; then
334330
# Install alongside the old version to avoid to have to update "runtime dependents"
335331
# https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
336332
VERB="install --force"
@@ -382,10 +378,11 @@ function _brew_check_elapsed_build_time {
382378
# If time limit has been reached,
383379
# arrange for further build to be skipped and return 1
384380

385-
local TIME_START;TIME_START="${1:?}"
386-
local TIME_LIMIT;TIME_LIMIT="${2:?}"
381+
local TIME_START TIME_LIMIT ELAPSED_TIME
382+
TIME_START="${1:?}"
383+
TIME_LIMIT="${2:?}"
387384

388-
local ELAPSED_TIME;ELAPSED_TIME=$(($(date +%s) - $TIME_START))
385+
ELAPSED_TIME=$(($(date +%s) - $TIME_START))
389386
echo "Elapsed time: "$(($ELAPSED_TIME/60))"m (${ELAPSED_TIME}s)"
390387

391388
if [[ "$ELAPSED_TIME" -gt $TIME_LIMIT ]]; then
@@ -400,10 +397,12 @@ function _brew_check_slow_building_ahead {
400397
#If the package's projected build completion is higher than hard limit,
401398
# skip it and arrange for further build to be skipped and return 1
402399

403-
local PACKAGE="${1:?}"
404-
local TIME_START="${2:?}"
405-
local TIME_HARD_LIMIT="${3:?}"
400+
local PACKAGE TIME_START TIME_HARD_LIMIT
401+
PACKAGE="${1:?}"
402+
TIME_START="${2:?}"
403+
TIME_HARD_LIMIT="${3:?}"
406404

405+
local PROJECTED_BUILD_TIME
407406
PROJECTED_BUILD_TIME=$(echo "$BREW_SLOW_BUILIDING_PACKAGES" | awk '$1=="'"$PACKAGE"'"{print $2}')
408407
[ -z "$PROJECTED_BUILD_TIME" ] && return 0 || true
409408

0 commit comments

Comments
 (0)