Skip to content

Commit af32e40

Browse files
committed
Quickfix to enable OSX build
1 parent c1c51f8 commit af32e40

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

travis_osx_brew_cache.sh

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#Should be in Travis' cache
55
BREW_LOCAL_BOTTLE_METADATA="$HOME/local_bottle_metadata"
66

7+
#FIXME: temporary fix to enable the build, should be replaced with the proper path to the cache dir
8+
mkdir -p $BREW_LOCAL_BOTTLE_METADATA
9+
710
# Starting reference point for elapsed build time; seconds since the epoch.
811
#TRAVIS_TIMER_START_TIME is set at the start of a log fold, in nanoseconds since the epoch
912
BREW_TIME_START=$(($TRAVIS_TIMER_START_TIME/10**9))
@@ -48,33 +51,33 @@ function brew_add_local_bottles {
4851
# so that `brew` commands can find them.
4952
# If the package was updated, removes the corresponding files
5053
# and the bottle's entry in the formula, if any.
51-
52-
# Bottle entry in formula:
54+
55+
# Bottle entry in formula:
5356
# bottle do
5457
# <...>
5558
# sha256 "<sha256>" => :<os_codename>
5659
# <...>
57-
# end
58-
60+
# end
61+
5962
echo "Cached bottles:"
6063
ls "$(brew --cache)/downloads" || true #may not exist initially since it's "$(brew --cache)" that is in Travis cache
6164
echo "Saved .json's and links:"
6265
ls "$BREW_LOCAL_BOTTLE_METADATA"
63-
66+
6467
for JSON in "$BREW_LOCAL_BOTTLE_METADATA"/*.json; do
6568
[ -e "$JSON" ] || break # OSX 10.11 bash has no nullglob
6669
local PACKAGE JSON_VERSION JSON_REBUILD OS_CODENAME BOTTLE_HASH
67-
70+
6871
_brew_parse_bottle_json "$JSON" PACKAGE JSON_VERSION JSON_REBUILD OS_CODENAME BOTTLE_HASH
6972

7073
echo "Adding local bottle: $PACKAGE ${JSON_VERSION}_${JSON_REBUILD}"
71-
74+
7275
local FORMULA_VERSION FORMULA_REBUILD FORMULA_BOTTLE_HASH
73-
76+
7477
_brew_parse_package_info "$PACKAGE" "$OS_CODENAME" FORMULA_VERSION FORMULA_REBUILD FORMULA_BOTTLE_HASH
7578

7679
local FORMULA_HAS_BOTTLE; [ -n "$FORMULA_BOTTLE_HASH" ] && FORMULA_HAS_BOTTLE=1 || true
77-
80+
7881

7982
local BOTTLE_LINK BOTTLE=""; BOTTLE_LINK="${JSON}.bottle.lnk";
8083
local BOTTLE_EXISTS= BOTTLE_MISMATCH= VERSION_MISMATCH=
@@ -88,10 +91,10 @@ function brew_add_local_bottles {
8891
if [ -f "$BOTTLE_LINK" ]; then
8992
BOTTLE=$(cat "$BOTTLE_LINK");
9093
BOTTLE=$(cd "$(dirname "$BOTTLE")"; pwd)/$(basename "$BOTTLE")
91-
94+
9295
if [ -e "$BOTTLE" ]; then
9396
BOTTLE_EXISTS=1;
94-
97+
9598
# The hash in `brew --cache $PACKAGE` entry is generated from download URL,
9699
# which itself is generated from base URL and version
97100
# (see Homebrew/Library/Homebrew/download_strategy.rb:cached_location).
@@ -110,7 +113,7 @@ function brew_add_local_bottles {
110113
else
111114
echo "Link file is missing or of invalid type!" >&2
112115
fi
113-
116+
114117
# Delete cached bottle and all metadata if invalid
115118
if [[ -z "$BOTTLE_EXISTS" || -n "$VERSION_MISMATCH" || -n "$BOTTLE_MISMATCH" ]]; then
116119
echo "Deleting the cached bottle and all metadata"
@@ -133,11 +136,11 @@ function brew_add_local_bottles {
133136
git commit -m "Removed obsolete local bottle ${JSON_VERSION}_${JSON_REBUILD} :${OS_CODENAME}" "$FORMULA"
134137
)
135138
fi
136-
139+
137140
if [ -n "$BOTTLE" -a -n "$BOTTLE_EXISTS" ]; then rm "$BOTTLE"; fi
138141
rm -f "$BOTTLE_LINK"
139142
rm "$JSON"
140-
143+
141144
#(Re)add metadata to the formula otherwise
142145
else
143146
if [ "$FORMULA_BOTTLE_HASH" == "$BOTTLE_HASH" ]; then
@@ -156,7 +159,7 @@ function brew_cache_cleanup {
156159

157160
#Lefovers from some failure probably
158161
rm -f "$BREW_LOCAL_BOTTLE_METADATA"/*.tar.gz
159-
162+
160163
#`brew cleanup` may delete locally-built bottles that weren't needed this time
161164
# so we're saving and restoring them
162165
local BOTTLE_LINK BOTTLE
@@ -187,16 +190,16 @@ function brew_go_bootstrap_mode {
187190
local EXIT_CODE=${1:-1}
188191

189192
echo "Going into cache bootstrap mode"
190-
193+
191194
BREW_BOOTSTRAP_MODE=1
192-
195+
193196
#Can't just `exit` because that would terminate the build without saving the cache
194197
#Have to replace further actions with no-ops
195-
198+
196199
local MESSAGE=""; if [ "$EXIT_CODE" -ne 0 ]; then
197200
MESSAGE='Building dependencies took too long. Restart the build in Travis UI to continue from cache.';
198201
fi
199-
202+
200203
eval '
201204
function '"$cmd"' { return 0; }
202205
function repair_wheelhouse { return 0; }
@@ -205,11 +208,11 @@ function brew_go_bootstrap_mode {
205208
echo \
206209
' echo -e "\n'"$MESSAGE"'\n"'
207210
fi)"\
208-
'
211+
'
209212
# Travis runs user scripts via `eval` i.e. in the same shell process.
210213
# So have to unset errexit in order to get to cache save stage
211214
set +e; return '"$EXIT_CODE"'
212-
}'
215+
}'
213216
}
214217

215218

@@ -228,15 +231,15 @@ function _brew_install_and_cache_within_time_limit {
228231
if grep -qxFf <(cat <<<"$_BREW_ALREADY_INSTALLED") <<<"$PACKAGE"; then
229232
MARKED_INSTALLED=1
230233
fi
231-
234+
232235
if [ -n "$MARKED_INSTALLED" ] || (brew list --versions "$PACKAGE" >/dev/null && ! (brew outdated | grep -qxF "$PACKAGE")); then
233236
echo "Already installed and the latest version: $PACKAGE"
234237
if [ -z "$MARKED_INSTALLED" ]; then _brew_mark_installed "$PACKAGE"; fi
235238
return 0
236239
fi
237-
240+
238241
local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
239-
242+
240243
_brew_is_bottle_available "$PACKAGE" KEG_ONLY || BUILD_FROM_SOURCE=1
241244
[ -n "$BUILD_FROM_SOURCE" ] && INCLUDE_BUILD="--include-build" || true
242245

@@ -254,7 +257,7 @@ function _brew_install_and_cache_within_time_limit {
254257
_brew_install_and_cache "$PACKAGE" "$([[ -z "$BUILD_FROM_SOURCE" ]] && echo 1 || echo 0)" "$KEG_ONLY" || return 2
255258
_brew_check_elapsed_build_time "$TIME_START" "$TIME_LIMIT" || return $?
256259
}
257-
260+
258261

259262
function _brew_parse_bottle_json {
260263
# Parse JSON file resulting from `brew bottle --json`
@@ -271,9 +274,9 @@ function _brew_parse_bottle_json {
271274
print tag_name
272275
print tag_dict["sha256"]
273276
' "$JSON")
274-
277+
275278
unset JSON
276-
279+
277280
{ local i v; for i in {1..5}; do
278281
read -r v
279282
eval "${1:?}=\"$v\""
@@ -284,7 +287,7 @@ function _brew_parse_bottle_json {
284287
function _brew_parse_package_info {
285288
# Get and parse `brew info --json` about a package
286289
# and save data into specified variables
287-
290+
288291
local PACKAGE OS_CODENAME
289292
PACKAGE="${1:?}"; shift
290293
OS_CODENAME="${1:?}"; shift
@@ -300,9 +303,9 @@ function _brew_parse_package_info {
300303
print bottle_data["files"].get(sys.argv[2],{"sha256":"!?"})["sha256"] #prevent losing trailing blank line to command substitution
301304
' \
302305
"$PACKAGE" "$OS_CODENAME"); JSON_DATA="${JSON_DATA%\!\?}" #!? can't occur in a hash
303-
306+
304307
unset PACKAGE OS_CODENAME
305-
308+
306309
{ local i v; for i in {1..3}; do
307310
read -r v
308311
eval "${1:?}=\"$v\""
@@ -346,13 +349,13 @@ function _brew_install_and_cache {
346349
# Install bottle or make and cache bottle.
347350
# assumes that deps were already installed
348351
# and not already the latest version
349-
352+
350353
local PACKAGE USE_BOTTLE KEG_ONLY
351354
PACKAGE="${1:?}"
352355
USE_BOTTLE="${2:?}"
353356
KEG_ONLY="${3:?}"
354357
local VERB
355-
358+
356359
if brew list --versions "$PACKAGE"; then
357360
# Install alongside the old version to avoid to have to update "runtime dependents"
358361
# https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
@@ -363,7 +366,7 @@ function _brew_install_and_cache {
363366
else
364367
VERB=install
365368
fi
366-
369+
367370
if [[ "$USE_BOTTLE" -gt 0 ]]; then
368371
echo "Installing bottle for: $PACKAGE"
369372
brew $VERB "$PACKAGE"
@@ -380,12 +383,12 @@ function _brew_install_and_cache {
380383
#proper procedure as per https://discourse.brew.sh/t/how-are-bottle-and-postinstall-related-is-it-safe-to-run-bottle-after-postinstall/3410/4
381384
brew uninstall --ignore-dependencies "$PACKAGE"
382385
brew $VERB "$BOTTLE"
383-
386+
384387
local JSON; JSON=$(sed -E 's/bottle(.[[:digit:]]+)?\.tar\.gz$/bottle.json/' <<<"$BOTTLE")
385-
388+
386389
#`brew bottle --merge` doesn't return nonzero on nonexisting json file
387390
test -f "$JSON" -a -f "$BOTTLE"
388-
391+
389392
brew bottle --merge --write "$JSON"
390393
local CACHED_BOTTLE; CACHED_BOTTLE="$(brew --cache "$PACKAGE")"
391394
mv "$BOTTLE" "$CACHED_BOTTLE";
@@ -394,9 +397,9 @@ function _brew_install_and_cache {
394397
#Symlinks aren't cached by Travis. Will just save paths in files then.
395398
local BOTTLE_LINK; BOTTLE_LINK="${CACHED_JSON}.bottle.lnk"
396399
echo "$CACHED_BOTTLE" >"$BOTTLE_LINK"
397-
400+
398401
fi
399-
402+
400403
_brew_mark_installed "$PACKAGE"
401404
}
402405
@@ -411,11 +414,11 @@ function _brew_check_elapsed_build_time {
411414
local TIME_START TIME_LIMIT ELAPSED_TIME
412415
TIME_START="${1:?}"
413416
TIME_LIMIT="${2:?}"
414-
417+
415418
ELAPSED_TIME=$(($(date +%s) - $TIME_START))
416419
echo "Elapsed time: "$(($ELAPSED_TIME/60))"m (${ELAPSED_TIME}s)"
417-
418-
if [[ "$ELAPSED_TIME" -gt $TIME_LIMIT ]]; then
420+
421+
if [[ "$ELAPSED_TIME" -gt $TIME_LIMIT ]]; then
419422
brew_go_bootstrap_mode
420423
return 1
421424
fi
@@ -426,19 +429,19 @@ function _brew_check_slow_building_ahead {
426429
427430
#If the package's projected build completion is higher than hard limit,
428431
# skip it and arrange for further build to be skipped and return 1
429-
432+
430433
local PACKAGE TIME_START TIME_HARD_LIMIT
431434
PACKAGE="${1:?}"
432435
TIME_START="${2:?}"
433436
TIME_HARD_LIMIT="${3:?}"
434-
435-
local PROJECTED_BUILD_TIME
437+
438+
local PROJECTED_BUILD_TIME
436439
PROJECTED_BUILD_TIME=$(echo "$BREW_SLOW_BUILIDING_PACKAGES" | awk '$1=="'"$PACKAGE"'"{print $2}')
437440
[ -z "$PROJECTED_BUILD_TIME" ] && return 0 || true
438-
441+
439442
local PROJECTED_BUILD_END_ELAPSED_TIME
440443
PROJECTED_BUILD_END_ELAPSED_TIME=$(( $(date +%s) - TIME_START + PROJECTED_BUILD_TIME * 60))
441-
444+
442445
if [[ "$PROJECTED_BUILD_END_ELAPSED_TIME" -ge "$TIME_HARD_LIMIT" ]]; then
443446
echo -e "\nProjected build end elapsed time for $PACKAGE: $((PROJECTED_BUILD_END_ELAPSED_TIME/60))m ($PROJECTED_BUILD_END_ELAPSED_TIMEs)"
444447
brew_go_bootstrap_mode

0 commit comments

Comments
 (0)