@@ -24,6 +24,11 @@ BREW_TIME_LIMIT=$((30*60))
24
24
BREW_TIME_HARD_LIMIT=$(( 40 * 60 ))
25
25
26
26
27
+ # Auto cleanup can delete locally-built bottles
28
+ # when the caching logic isn't prepared for that
29
+ export HOMEBREW_NO_INSTALL_CLEANUP=1
30
+
31
+
27
32
28
33
# Public functions
29
34
@@ -34,34 +39,34 @@ function brew_install_and_cache_within_time_limit {
34
39
# Exit with status 2 on any other error.
35
40
( eval " $_BREW_ERREXIT "
36
41
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
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
41
46
42
- local BUILD_FROM_SOURCE INCLUDE_BUILD
47
+ local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
43
48
44
49
if brew list --versions " $PACKAGE " && ! (brew outdated | grep -qx " $PACKAGE " ); then
45
50
echo " Already installed and the latest version: $PACKAGE "
46
51
return 0
47
52
fi
48
53
49
54
50
- _brew_is_bottle_available " $PACKAGE " || BUILD_FROM_SOURCE=1
55
+ _brew_is_bottle_available " $PACKAGE " KEG_ONLY || BUILD_FROM_SOURCE=1
51
56
[ -n " $BUILD_FROM_SOURCE " ] && INCLUDE_BUILD=" --include-build" || true
52
57
53
58
# Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
54
- DEPS=` brew deps " $PACKAGE " $INCLUDE_BUILD ` || return 2
59
+ DEPS=` brew deps " $PACKAGE " $INCLUDE_BUILD ` || exit 2
55
60
for dep in $DEPS ; do
56
61
# 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
57
62
# While we don't know that yet, we can make better use of Travis-given time with a laxer limit
58
63
# We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
59
- brew_install_and_cache_within_time_limit " $dep " $(( (TIME_LIMIT+ TIME_HARD_LIMIT)/ 2 )) " $TIME_HARD_LIMIT " " $TIME_START " || return $?
64
+ brew_install_and_cache_within_time_limit " $dep " $(( (TIME_LIMIT+ TIME_HARD_LIMIT)/ 2 )) " $TIME_HARD_LIMIT " " $TIME_START " || exit $?
60
65
done
61
66
62
- _brew_check_slow_building_ahead " $PACKAGE " " $TIME_START " " $TIME_HARD_LIMIT " || return $?
63
- _brew_install_and_cache " $PACKAGE " " $( [[ -z " $INCLUDE_BUILD " ]] && echo 1 || echo 0) " || return 2
64
- _brew_check_elapsed_build_time " $TIME_START " " $TIME_LIMIT " || return $?
67
+ _brew_check_slow_building_ahead " $PACKAGE " " $TIME_START " " $TIME_HARD_LIMIT " || exit $?
68
+ _brew_install_and_cache " $PACKAGE " " $( [[ -z " $BUILD_FROM_SOURCE " ]] && echo 1 || echo 0) " " $KEG_ONLY " || exit 2
69
+ _brew_check_elapsed_build_time " $TIME_START " " $TIME_LIMIT " || exit $?
65
70
) \
66
71
|| if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi # must run this in current process
67
72
}
@@ -288,8 +293,22 @@ function _brew_parse_package_info {
288
293
function _brew_is_bottle_available {
289
294
290
295
local PACKAGE; PACKAGE=" ${1:? } "
291
-
292
- local INFO=" $( brew info " $PACKAGE " | head -n 1) "
296
+ local VAR_KEG_ONLY=" $2 "
297
+
298
+ local INFO; INFO=" $( brew info " $PACKAGE " | head -n 1) "
299
+ if [ -n " $VAR_KEG_ONLY " ]; then
300
+ if grep -qwF ' [keg-only]' <<< " $INFO" ; then
301
+ eval " ${VAR_KEG_ONLY} =1"
302
+ else
303
+ eval " ${VAR_KEG_ONLY} =0"
304
+ fi
305
+ fi
306
+
307
+ if grep -qxEe ' [[:space:]]*bottle :unneeded' $( brew formula " $PACKAGE " ) ; then
308
+ echo " Bottle disabled: $PACKAGE "
309
+ return 0
310
+ fi
311
+
293
312
if grep -qwF ' (bottled)' <<< " $INFO" ; then
294
313
echo " Bottle available: $INFO "
295
314
return 0
@@ -306,10 +325,16 @@ function _brew_install_and_cache {
306
325
307
326
local PACKAGE; PACKAGE=" ${1:? } "
308
327
local USE_BOTTLE; USE_BOTTLE=" ${2:? } "
328
+ local KEG_ONLY; KEG_ONLY=" ${3:? } "
309
329
local VERB
310
330
311
- if brew list --versions " $PACKAGE " ; then
312
- VERB=upgrade
331
+ if brew list --versions " $PACKAGE " > /dev/null; then
332
+ # Install alongside the old version to avoid to have to update "runtime dependents"
333
+ # https://discourse.brew.sh/t/can-i-install-a-new-version-without-having-to-upgrade-runtime-dependents/4443
334
+ VERB=" install --force"
335
+ if [ " $KEG_ONLY " -eq 0 ]; then
336
+ brew unlink " $PACKAGE "
337
+ fi
313
338
else
314
339
VERB=install
315
340
fi
@@ -328,8 +353,8 @@ function _brew_install_and_cache {
328
353
# doesn't seem to be a documented way to get file names
329
354
local BOTTLE; BOTTLE=$( grep -Ee ' ^./' <<< " $OUT" )
330
355
# 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
331
- brew uninstall " $PACKAGE "
332
- brew install " $BOTTLE "
356
+ brew uninstall --ignore-dependencies " $PACKAGE "
357
+ brew $VERB " $BOTTLE "
333
358
334
359
local JSON; JSON=$( sed -E ' s/bottle(.[[:digit:]]+)?\.tar\.gz$/bottle.json/' <<< " $BOTTLE" )
335
360
0 commit comments