@@ -27,7 +27,8 @@ export HOMEBREW_NO_INSTALL_CLEANUP=1
27
27
# see https://docs.brew.sh/Manpage , "info formula" section
28
28
export HOMEBREW_NO_GITHUB_API=1
29
29
30
-
30
+ # Packages already installed in the current session to avoid checking them again
31
+ _BREW_ALREADY_INSTALLED=' $' # $ = illegal package name; a blank line would cause macos grep to swallow everything
31
32
32
33
33
34
# Public functions
@@ -37,39 +38,8 @@ function brew_install_and_cache_within_time_limit {
37
38
# use bottle if available, build and cache bottle if not.
38
39
# Terminate and exit with status 1 if this takes too long.
39
40
# Exit with status 2 on any other error.
40
- ( set -eE -o pipefail; trap ' { sleep 3; exit 2; }' ERR
41
-
42
- local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START
43
- PACKAGE=" ${1:? } " || exit 2
44
- TIME_LIMIT=${2:- $BREW_TIME_LIMIT } || exit 2
45
- TIME_HARD_LIMIT=${3:- $BREW_TIME_HARD_LIMIT } || exit 2
46
- TIME_START=${4:- $BREW_TIME_START } || exit 2
47
-
48
- local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
49
-
50
- if brew list --versions " $PACKAGE " > /dev/null && ! (brew outdated | grep -qxF " $PACKAGE " ); then
51
- echo " Already installed and the latest version: $PACKAGE "
52
- return 0
53
- fi
54
-
55
-
56
- _brew_is_bottle_available " $PACKAGE " KEG_ONLY || BUILD_FROM_SOURCE=1
57
- [ -n " $BUILD_FROM_SOURCE " ] && INCLUDE_BUILD=" --include-build" || true
58
-
59
- # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
60
- DEPS=` brew deps " $PACKAGE " $INCLUDE_BUILD ` || exit 2
61
- for dep in $DEPS ; do
62
- # 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
63
- # While we don't know that yet, we can make better use of Travis-given time with a laxer limit
64
- # We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
65
- brew_install_and_cache_within_time_limit " $dep " $(( (TIME_LIMIT+ TIME_HARD_LIMIT)/ 2 )) " $TIME_HARD_LIMIT " " $TIME_START " || exit $?
66
- done
67
-
68
- _brew_check_slow_building_ahead " $PACKAGE " " $TIME_START " " $TIME_HARD_LIMIT " || exit $?
69
- _brew_install_and_cache " $PACKAGE " " $( [[ -z " $BUILD_FROM_SOURCE " ]] && echo 1 || echo 0) " " $KEG_ONLY " || exit 2
70
- _brew_check_elapsed_build_time " $TIME_START " " $TIME_LIMIT " || exit $?
71
- ) \
72
- || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi # must run this in current process
41
+ _brew_install_and_cache_within_time_limit $@ \
42
+ || if test $? -eq 1; then brew_go_bootstrap_mode; return 1; else return 2; fi
73
43
}
74
44
75
45
function brew_add_local_bottles {
@@ -246,6 +216,46 @@ function brew_go_bootstrap_mode {
246
216
247
217
# Internal functions
248
218
219
+ function _brew_install_and_cache_within_time_limit {
220
+ # This fn is run with || so errexit can't be enabled
221
+
222
+ local PACKAGE TIME_LIMIT TIME_HARD_LIMIT TIME_START MARKED_INSTALLED
223
+ PACKAGE=" ${1:? } " || return 2
224
+ TIME_LIMIT=${2:- $BREW_TIME_LIMIT } || return 2
225
+ TIME_HARD_LIMIT=${3:- $BREW_TIME_HARD_LIMIT } || return 2
226
+ TIME_START=${4:- $BREW_TIME_START } || return 2
227
+
228
+ if grep -qxFf <( cat <<< " $_BREW_ALREADY_INSTALLED" ) <<< " $PACKAGE" ; then
229
+ MARKED_INSTALLED=1
230
+ fi
231
+
232
+ if [ -n " $MARKED_INSTALLED " ] || (brew list --versions " $PACKAGE " > /dev/null && ! (brew outdated | grep -qxF " $PACKAGE " )); then
233
+ echo " Already installed and the latest version: $PACKAGE "
234
+ if [ -z " $MARKED_INSTALLED " ]; then _brew_mark_installed " $PACKAGE " ; fi
235
+ return 0
236
+ fi
237
+
238
+ local BUILD_FROM_SOURCE INCLUDE_BUILD KEG_ONLY
239
+
240
+ _brew_is_bottle_available " $PACKAGE " KEG_ONLY || BUILD_FROM_SOURCE=1
241
+ [ -n " $BUILD_FROM_SOURCE " ] && INCLUDE_BUILD=" --include-build" || true
242
+
243
+ # Whitespace is illegal in package names so converting all whitespace into single spaces due to no quotes is okay.
244
+ DEPS=` brew deps " $PACKAGE " $INCLUDE_BUILD ` || return 2
245
+ DEPS=` grep -vxF <( cat <<< " $_BREW_ALREADY_INSTALLED" ) <<< " $DEPS" ` || test $? -eq 1 || return 2
246
+ for dep in $DEPS ; do
247
+ # 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
248
+ # While we don't know that yet, we can make better use of Travis-given time with a laxer limit
249
+ # We still can't overrun TIME_HARD_LIMIT as that would't leave time to save the cache
250
+ _brew_install_and_cache_within_time_limit " $dep " $(( (TIME_LIMIT+ TIME_HARD_LIMIT)/ 2 )) " $TIME_HARD_LIMIT " " $TIME_START " || return $?
251
+ done
252
+
253
+ _brew_check_slow_building_ahead " $PACKAGE " " $TIME_START " " $TIME_HARD_LIMIT " || return $?
254
+ _brew_install_and_cache " $PACKAGE " " $( [[ -z " $BUILD_FROM_SOURCE " ]] && echo 1 || echo 0) " " $KEG_ONLY " || return 2
255
+ _brew_check_elapsed_build_time " $TIME_START " " $TIME_LIMIT " || return $?
256
+ }
257
+
258
+
249
259
function _brew_parse_bottle_json {
250
260
# Parse JSON file resulting from `brew bottle --json`
251
261
# and save data into specified variables
@@ -386,10 +396,13 @@ function _brew_install_and_cache {
386
396
echo "$CACHED_BOTTLE " >"$BOTTLE_LINK "
387
397
388
398
fi
399
+
400
+ _brew_mark_installed "$PACKAGE "
389
401
}
390
402
391
-
392
-
403
+ function _brew_mark_installed {
404
+ _BREW_ALREADY_INSTALLED="$_BREW_ALREADY_INSTALLED "$'\n'"${1:? } "
405
+ }
393
406
394
407
function _brew_check_elapsed_build_time {
395
408
# If time limit has been reached,
0 commit comments