Skip to content

Commit c148de2

Browse files
committed
Make library for auto building and caching Homebrew bottles
cache Homebrew
1 parent 77a3278 commit c148de2

File tree

3 files changed

+447
-12
lines changed

3 files changed

+447
-12
lines changed

.travis.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ dist: trusty
2525
git:
2626
submodules: false
2727

28+
# https://docs.travis-ci.com/user/caching
29+
cache:
30+
directories:
31+
# https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
32+
- $HOME/Library/Caches/Homebrew
33+
- /usr/local/Homebrew/
34+
# used in OSX custom build script dealing with local bottle caching
35+
- $HOME/local_bottle_metadata
36+
2837
matrix:
2938
fast_finish: true
3039
include:
@@ -526,9 +535,36 @@ install: |
526535
script: |
527536
# Install and run tests
528537
set -x
529-
install_run $PLAT
538+
install_run $PLAT && rc=$? || rc=$?
530539
set +x
531540
541+
#otherwise, Travis logic terminates prematurely
542+
#https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
543+
trap ERR
544+
545+
test "$rc" -eq 0
546+
547+
before_cache: |
548+
# Cleanup dirs to be cached
549+
set -x
550+
if [ -n "$IS_OSX" ]; then
551+
552+
# When Taps is cached, this dir causes "Error: file exists" on `brew update`
553+
rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
554+
find "$(brew --repository)/Library/Taps" -type d -name .git -exec \
555+
bash -xec '
556+
cd $(dirname '\''{}'\'')
557+
git status
558+
# https://stackoverflow.com/questions/8296710/how-to-ignore-xargs-commands-if-stdin-input-is-empty/19038748#19038748
559+
git ls-files --other -z | xargs -0 -n100 git add
560+
git commit -a -m "Travis auto changes"
561+
[[ -n $(git stash list) ]] && git stash drop' \;
562+
563+
brew_cache_cleanup
564+
565+
fi
566+
set +x
567+
532568
after_success: |
533569
# Upload wheels to pypi if requested
534570
if [ -n "$TRAVIS_TAG" ]; then

config.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,46 @@ else
2424
echo " > Linux environment "
2525
fi
2626

27+
if [ -n "$IS_OSX" ]; then
28+
29+
source travis_osx_brew_cache.sh
30+
31+
BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
32+
"x265 20" \
33+
"cmake 15" \
34+
"ffmpeg 10" \
35+
)
36+
37+
#Contrib adds significantly to project's build time
38+
if [ "$ENABLE_CONTRIB" -eq 1 ]; then
39+
BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
40+
fi
41+
42+
fi
43+
2744
function pre_build {
2845
echo "Starting pre-build"
29-
set -e
46+
set -e -o pipefail
3047

3148
if [ -n "$IS_OSX" ]; then
3249
echo "Running for OSX"
50+
51+
brew update --merge
52+
brew_add_local_bottles
3353

34-
brew update
54+
# Don't query analytical info online on `brew info`,
55+
# this takes several seconds and we don't need it
56+
# see https://docs.brew.sh/Manpage , "info formula" section
57+
export HOMEBREW_NO_GITHUB_API=1
3558

3659
echo 'Installing QT4'
3760
brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
3861
brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
39-
brew list --versions qt@4 || brew install -v qt@4
40-
echo '-----------------'
41-
echo '-----------------'
62+
brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
63+
4264
echo 'Installing FFmpeg'
43-
# brew install does produce output regularly on a regular MacOS,
44-
# but Travis doesn't see it for some reason
45-
brew list --versions ffmpeg || \
46-
travis_wait brew install -v ffmpeg --without-x264 --without-xvid --without-gpl
47-
brew info ffmpeg
48-
echo '-----------------'
65+
66+
brew_install_and_cache_within_time_limit ffmpeg || { [ $? -gt 1 ] && return 2 || return 0; }
4967

5068
else
5169
echo "Running for linux"

0 commit comments

Comments
 (0)