@@ -24,6 +24,11 @@ BREW_TIME_LIMIT=$((30*60))
2424BREW_TIME_HARD_LIMIT=$(( 40 * 60 ))
2525
2626
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+
2732
2833# Public functions
2934
@@ -34,34 +39,34 @@ function brew_install_and_cache_within_time_limit {
3439 # Exit with status 2 on any other error.
3540 ( eval " $_BREW_ERREXIT "
3641
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
4146
42- local BUILD_FROM_SOURCE INCLUDE_BUILD
47+ local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
4348
4449 if brew list --versions " $PACKAGE " && ! (brew outdated | grep -qx " $PACKAGE " ); then
4550 echo " Already installed and the latest version: $PACKAGE "
4651 return 0
4752 fi
4853
4954
50- _brew_is_bottle_available " $PACKAGE " || BUILD_FROM_SOURCE=1
55+ _brew_is_bottle_available " $PACKAGE " KEG_ONLY || BUILD_FROM_SOURCE=1
5156 [ -n " $BUILD_FROM_SOURCE " ] && INCLUDE_BUILD=" --include-build" || true
5257
5358 # 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
5560 for dep in $DEPS ; do
5661 # 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
5762 # While we don't know that yet, we can make better use of Travis-given time with a laxer limit
5863 # 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 $?
6065 done
6166
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 $?
6570 ) \
6671 || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi # must run this in current process
6772}
@@ -288,8 +293,22 @@ function _brew_parse_package_info {
288293function _brew_is_bottle_available {
289294
290295 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+
293312 if grep -qwF ' (bottled)' <<< " $INFO" ; then
294313 echo " Bottle available: $INFO "
295314 return 0
@@ -306,10 +325,16 @@ function _brew_install_and_cache {
306325
307326 local PACKAGE; PACKAGE=" ${1:? } "
308327 local USE_BOTTLE; USE_BOTTLE=" ${2:? } "
328+ local KEG_ONLY; KEG_ONLY=" ${3:? } "
309329 local VERB
310330
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
313338 else
314339 VERB=install
315340 fi
@@ -328,8 +353,8 @@ function _brew_install_and_cache {
328353 # doesn't seem to be a documented way to get file names
329354 local BOTTLE; BOTTLE=$( grep -Ee ' ^./' <<< " $OUT" )
330355 # 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 "
333358
334359 local JSON; JSON=$( sed -E ' s/bottle(.[[:digit:]]+)?\.tar\.gz$/bottle.json/' <<< " $BOTTLE" )
335360
0 commit comments