1
1
# Library to cache downloaded and locally-built Homebrew bottles in Travis OSX build.
2
2
3
- trap ' { sleep 1; #if we terminale too abruptly, Travis will lose some log output
3
+ _BREW_ERREXIT='
4
+ set -e -o pipefail
5
+ trap ' \' ' { sleep 3; #if we terminale too abruptly, Travis will lose some log output
4
6
exit 2; #The trap isn' ' t called in the parent function, so can' ' t use `return` here.
5
7
#`exit` will terminate the entire build but it seems we have no choice.
6
- }' ERR
7
- set -E
8
+ }' \' ' ERR
9
+ set -E'
8
10
9
11
# Should be in Travis' cache
10
12
BREW_LOCAL_BOTTLE_METADATA=" $HOME /local_bottle_metadata"
@@ -30,19 +32,20 @@ function brew_install_and_cache_within_time_limit {
30
32
# use bottle if available, build and cache bottle if not.
31
33
# Terminate and exit with status 1 if this takes too long.
32
34
# Exit with status 2 on any other error.
35
+ ( eval " $_BREW_ERREXIT "
33
36
34
- local PACKAGE; PACKAGE=" ${1:? } "
35
- local TIME_LIMIT; TIME_LIMIT=${2:- $BREW_TIME_LIMIT }
36
- local TIME_HARD_LIMIT; TIME_HARD_LIMIT=${3:- $BREW_TIME_HARD_LIMIT }
37
- local TIME_START; TIME_START=${4:- $BREW_TIME_START }
37
+ local PACKAGE; PACKAGE=" ${1:? } " || return 2
38
+ local TIME_LIMIT; TIME_LIMIT=${2:- $BREW_TIME_LIMIT } || return 2
39
+ local TIME_HARD_LIMIT; TIME_HARD_LIMIT=${3:- $BREW_TIME_HARD_LIMIT } || return 2
40
+ local TIME_START; TIME_START=${4:- $BREW_TIME_START } || return 2
38
41
39
42
local BUILD_FROM_SOURCE INCLUDE_BUILD
40
43
41
44
_brew_is_bottle_available " $PACKAGE " || BUILD_FROM_SOURCE=1
42
45
[ -n " $BUILD_FROM_SOURCE " ] && INCLUDE_BUILD=" --include-build" || true
43
46
44
47
# Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
45
- DEPS=` brew deps " $PACKAGE " $INCLUDE_BUILD `
48
+ DEPS=` brew deps " $PACKAGE " $INCLUDE_BUILD ` || return 2
46
49
for dep in $DEPS ; do
47
50
# TIME_LIMIT only has to be met if we'll be actually building the main project this iteration, i.e. after the "root" module installation
48
51
# While we don't know that yet, we can make better use of Travis-given time with a laxer limit
@@ -51,8 +54,10 @@ function brew_install_and_cache_within_time_limit {
51
54
done
52
55
53
56
_brew_check_slow_building_ahead " $PACKAGE " " $TIME_START " " $TIME_HARD_LIMIT " || return $?
54
- _brew_install_and_cache " $PACKAGE " " $( [[ -z " $INCLUDE_BUILD " ]] && echo 1 || echo 0) "
57
+ _brew_install_and_cache " $PACKAGE " " $( [[ -z " $INCLUDE_BUILD " ]] && echo 1 || echo 0) " || return 2
55
58
_brew_check_elapsed_build_time " $TIME_START " " $TIME_LIMIT " || return $?
59
+ ) \
60
+ || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi # must run this in current process
56
61
}
57
62
58
63
function brew_add_local_bottles {
@@ -220,9 +225,8 @@ function brew_go_bootstrap_mode {
220
225
# Internal functions
221
226
222
227
function _brew_parse_bottle_json {
223
- # Parse JSON info about a package
224
- # from `brew info --json=v1` input or a JSON file on stdin
225
- # and save it into bash global variables specified in arguments
228
+ # Parse JSON file resulting from `brew bottle --json`
229
+ # and save data into specified variables
226
230
227
231
local JSON; JSON=" ${1:? } " ; shift
228
232
@@ -247,20 +251,22 @@ function _brew_parse_bottle_json {
247
251
248
252
function _brew_parse_package_info {
249
253
# Get and parse `brew info --json` about a package
250
- # and save it into bash variables specified in arguments
254
+ # and save data into specified variables
251
255
252
256
local PACKAGE; PACKAGE=" ${1:? } " ; shift
253
257
local OS_CODENAME; OS_CODENAME=" ${1:? } " ; shift
254
258
255
259
local JSON_DATA; JSON_DATA=$( python2.7 -c ' if True:
256
260
import sys, json, subprocess; j=json.loads(subprocess.check_output(("brew","info","--json=v1",sys.argv[1])))
257
261
data=j[0]
258
- print data["versions"]["stable"]
262
+ revision=data["revision"]
263
+ # in bottle' ' s json, revision is included into version; here, they are separate
264
+ print data["versions"]["stable"]+("_"+str(revision) if revision else "")
259
265
bottle_data=data["bottle"]["stable"]
260
266
print bottle_data["rebuild"]
261
- print bottle_data["files"].get(sys.argv[2],{"sha256":""})["sha256"]
267
+ print bottle_data["files"].get(sys.argv[2],{"sha256":"!? "})["sha256"] #prevent losing trailing blank line to command substitution
262
268
' \
263
- " $PACKAGE " " $OS_CODENAME " )
269
+ " $PACKAGE " " $OS_CODENAME " ) ; JSON_DATA= " ${JSON_DATA % \!\? } " #! ? can't occur in a hash
264
270
265
271
unset PACKAGE OS_CODENAME
266
272
0 commit comments