Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c4286d2

Browse filesBrowse files
committed
Speed up repeat checks for the same deps
1 parent e1523c8 commit c4286d2
Copy full SHA for c4286d2

File tree

Expand file treeCollapse file tree

1 file changed

+49
-36
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+49
-36
lines changed

‎travis_osx_brew_cache.sh

Copy file name to clipboardExpand all lines: travis_osx_brew_cache.sh
+49-36Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export HOMEBREW_NO_INSTALL_CLEANUP=1
2727
# see https://docs.brew.sh/Manpage , "info formula" section
2828
export HOMEBREW_NO_GITHUB_API=1
2929

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
3132

3233

3334
#Public functions
@@ -37,39 +38,8 @@ function brew_install_and_cache_within_time_limit {
3738
# use bottle if available, build and cache bottle if not.
3839
# Terminate and exit with status 1 if this takes too long.
3940
# 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
7343
}
7444

7545
function brew_add_local_bottles {
@@ -246,6 +216,46 @@ function brew_go_bootstrap_mode {
246216

247217
#Internal functions
248218

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+
249259
function _brew_parse_bottle_json {
250260
# Parse JSON file resulting from `brew bottle --json`
251261
# and save data into specified variables
@@ -386,10 +396,13 @@ function _brew_install_and_cache {
386396
echo "$CACHED_BOTTLE" >"$BOTTLE_LINK"
387397
388398
fi
399+
400+
_brew_mark_installed "$PACKAGE"
389401
}
390402
391-
392-
403+
function _brew_mark_installed {
404+
_BREW_ALREADY_INSTALLED="$_BREW_ALREADY_INSTALLED"$'\n'"${1:?}"
405+
}
393406
394407
function _brew_check_elapsed_build_time {
395408
# If time limit has been reached,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.