1
1
# Library to cache downloaded and locally-built Homebrew bottles in Travis OSX build.
2
2
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'
10
3
11
4
# Should be in Travis' cache
12
5
BREW_LOCAL_BOTTLE_METADATA=" $HOME /local_bottle_metadata"
@@ -37,16 +30,17 @@ function brew_install_and_cache_within_time_limit {
37
30
# use bottle if available, build and cache bottle if not.
38
31
# Terminate and exit with status 1 if this takes too long.
39
32
# 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
46
40
47
41
local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
48
42
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
50
44
echo " Already installed and the latest version: $PACKAGE "
51
45
return 0
52
46
fi
@@ -266,8 +260,9 @@ function _brew_parse_package_info {
266
260
# Get and parse `brew info --json` about a package
267
261
# and save data into specified variables
268
262
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
271
266
272
267
local JSON_DATA; JSON_DATA=$( python2.7 -c ' if True:
273
268
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 {
325
320
# assumes that deps were already installed
326
321
# and not already the latest version
327
322
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:? } "
331
327
local VERB
332
328
333
- if brew list --versions " $PACKAGE " > /dev/null ; then
329
+ if brew list --versions " $PACKAGE " ; then
334
330
# Install alongside the old version to avoid to have to update "runtime dependents"
335
331
# https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
336
332
VERB=" install --force"
@@ -382,10 +378,11 @@ function _brew_check_elapsed_build_time {
382
378
# If time limit has been reached,
383
379
# arrange for further build to be skipped and return 1
384
380
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:? } "
387
384
388
- local ELAPSED_TIME ; ELAPSED_TIME=$(( $(date +% s) - $TIME_START ))
385
+ ELAPSED_TIME=$(( $(date +% s) - $TIME_START ))
389
386
echo " Elapsed time: " $(( $ELAPSED_TIME / 60 )) " m (${ELAPSED_TIME} s)"
390
387
391
388
if [[ " $ELAPSED_TIME " -gt $TIME_LIMIT ]]; then
@@ -400,10 +397,12 @@ function _brew_check_slow_building_ahead {
400
397
# If the package's projected build completion is higher than hard limit,
401
398
# skip it and arrange for further build to be skipped and return 1
402
399
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:? } "
406
404
405
+ local PROJECTED_BUILD_TIME
407
406
PROJECTED_BUILD_TIME=$( echo " $BREW_SLOW_BUILIDING_PACKAGES " | awk ' $1=="' " $PACKAGE " ' "{print $2}' )
408
407
[ -z " $PROJECTED_BUILD_TIME " ] && return 0 || true
409
408
0 commit comments