Skip to content

Commit 3d8a1e9

Browse files
authored
Merge pull request opencv#144 from native-api/remove_ffmpeg_options
Cache locally-built Homebrew bottles in OSX builds
2 parents dabae8a + d364ab3 commit 3d8a1e9

File tree

3 files changed

+476
-14
lines changed

3 files changed

+476
-14
lines changed

.travis.yml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ dist: trusty
2323
git:
2424
submodules: false
2525

26+
# https://docs.travis-ci.com/user/caching
27+
cache:
28+
directories:
29+
# https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
30+
- $HOME/Library/Caches/Homebrew
31+
- /usr/local/Homebrew/
32+
# used in OSX custom build script dealing with local bottle caching
33+
- $HOME/local_bottle_metadata
34+
# `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
35+
- $HOME/.ccache
36+
2637
matrix:
2738
fast_finish: true
2839
include:
@@ -511,6 +522,21 @@ before_install: |
511522
source multibuild_customize.sh
512523
echo $ENABLE_CONTRIB > contrib.enabled
513524
echo $ENABLE_HEADLESS > headless.enabled
525+
526+
if [ -n "$IS_OSX" ]; then
527+
TAPS="$(brew --repository)/Library/Taps"
528+
if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
529+
rm -rf "$TAPS/caskroom/homebrew-cask"
530+
fi
531+
find "$TAPS" -type d -name .git -exec \
532+
bash -xec '
533+
cd $(dirname '\''{}'\'')
534+
git clean -fxd
535+
git status' \;
536+
537+
brew_cache_cleanup
538+
fi
539+
514540
before_install
515541
# Not interested in travis internal scripts' output
516542
set +x
@@ -524,9 +550,30 @@ install: |
524550
script: |
525551
# Install and run tests
526552
set -x
527-
install_run $PLAT
553+
install_run $PLAT && rc=$? || rc=$?
528554
set +x
529555
556+
#otherwise, Travis logic terminates prematurely
557+
#https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
558+
trap ERR
559+
560+
test "$rc" -eq 0
561+
562+
before_cache: |
563+
# Cleanup dirs to be cached
564+
set -x
565+
if [ -n "$IS_OSX" ]; then
566+
567+
# When Taps is cached, this dir causes "Error: file exists" on `brew update`
568+
if [ -e "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask" ]; then
569+
rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
570+
fi
571+
572+
brew_cache_cleanup
573+
574+
fi
575+
set +x
576+
530577
after_success: |
531578
# Upload wheels to pypi if requested
532579
if [ -n "$TRAVIS_TAG" ]; then

config.sh

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,58 @@ function bdist_wheel_cmd {
2020

2121
if [ -n "$IS_OSX" ]; then
2222
echo " > OSX environment "
23+
export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
2324
else
2425
echo " > Linux environment "
26+
export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
27+
fi
28+
29+
if [ -n "$IS_OSX" ]; then
30+
31+
source travis_osx_brew_cache.sh
32+
33+
BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
34+
"x265 20" \
35+
"cmake 15" \
36+
"ffmpeg 10" \
37+
)
38+
39+
#Contrib adds significantly to project's build time
40+
if [ "$ENABLE_CONTRIB" -eq 1 ]; then
41+
BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
42+
fi
43+
2544
fi
2645

2746
function pre_build {
2847
echo "Starting pre-build"
29-
set -e
48+
set -e -o pipefail
3049

3150
if [ -n "$IS_OSX" ]; then
3251
echo "Running for OSX"
52+
53+
brew update --merge
54+
brew_add_local_bottles
55+
56+
# Don't query analytical info online on `brew info`,
57+
# this takes several seconds and we don't need it
58+
# see https://docs.brew.sh/Manpage , "info formula" section
59+
export HOMEBREW_NO_GITHUB_API=1
3360

34-
brew update
61+
# https://docs.travis-ci.com/user/caching/#ccache-cache
62+
# No need to allow rc 1 -- if this triggers a timeout,
63+
# something is clearly wrong
64+
brew_install_and_cache_within_time_limit ccache
65+
export PATH="/usr/local/opt/ccache/libexec:$PATH"
3566

3667
echo 'Installing QT4'
37-
brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
38-
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 '-----------------'
68+
brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
69+
brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
70+
brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }
71+
4272
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 '-----------------'
73+
74+
brew_install_and_cache_within_time_limit ffmpeg || { [ $? -gt 1 ] && return 2 || return 0; }
4975

5076
else
5177
echo "Running for linux"

0 commit comments

Comments
 (0)