Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use patched ffmpeg formula in OSX #146

Merged
merged 7 commits into from Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 48 additions & 1 deletion .travis.yml
Expand Up @@ -25,6 +25,17 @@ dist: trusty
git:
submodules: false

# https://docs.travis-ci.com/user/caching
cache:
directories:
# https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
- $HOME/Library/Caches/Homebrew
- /usr/local/Homebrew/
# used in OSX custom build script dealing with local bottle caching
- $HOME/local_bottle_metadata
# `cache: ccache: true` has no effect if `language:` is not `c` or `cpp`
- $HOME/.ccache

matrix:
fast_finish: true
include:
Expand Down Expand Up @@ -513,6 +524,21 @@ before_install: |
source multibuild_customize.sh
echo $ENABLE_CONTRIB > contrib.enabled
echo $ENABLE_HEADLESS > headless.enabled

if [ -n "$IS_OSX" ]; then
TAPS="$(brew --repository)/Library/Taps"
if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
rm -rf "$TAPS/caskroom/homebrew-cask"
fi
find "$TAPS" -type d -name .git -exec \
bash -xec '
cd $(dirname '\''{}'\'')
git clean -fxd
git status' \;

brew_cache_cleanup
fi

before_install
# Not interested in travis internal scripts' output
set +x
Expand All @@ -526,9 +552,30 @@ install: |
script: |
# Install and run tests
set -x
install_run $PLAT
install_run $PLAT && rc=$? || rc=$?
set +x

#otherwise, Travis logic terminates prematurely
#https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
trap ERR

test "$rc" -eq 0

before_cache: |
# Cleanup dirs to be cached
set -x
if [ -n "$IS_OSX" ]; then

# When Taps is cached, this dir causes "Error: file exists" on `brew update`
if [ -e "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask" ]; then
rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
fi

brew_cache_cleanup

fi
set +x

after_success: |
# Upload wheels to pypi if requested
if [ -n "$TRAVIS_TAG" ]; then
Expand Down
95 changes: 82 additions & 13 deletions config.sh
Expand Up @@ -20,32 +20,101 @@ function bdist_wheel_cmd {

if [ -n "$IS_OSX" ]; then
echo " > OSX environment "
export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
else
echo " > Linux environment "
export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
fi

if [ -n "$IS_OSX" ]; then

source travis_osx_brew_cache.sh

BREW_SLOW_BUILIDING_PACKAGES=$(printf '%s\n' \
"x265 20" \
"cmake 15" \
"ffmpeg_opencv 10" \
)

#Contrib adds significantly to project's build time
if [ "$ENABLE_CONTRIB" -eq 1 ]; then
BREW_TIME_LIMIT=$((BREW_TIME_LIMIT - 10*60))
fi

function generate_ffmpeg_formula {
local FF="ffmpeg"
local LFF="ffmpeg_opencv"
local FF_FORMULA; FF_FORMULA=$(brew formula "$FF")
local LFF_FORMULA; LFF_FORMULA="$(dirname "$FF_FORMULA")/${LFF}.rb"

local REGENERATE
if [ -f "$LFF_FORMULA" ]; then
local UPSTREAM_VERSION VERSION
_brew_parse_package_info "$FF" " " UPSTREAM_VERSION _ _
_brew_parse_package_info "$LFF" " " VERSION _ _ || REGENERATE=1
#`rebuild` clause is ignored on `brew bottle` and deleted
# from newly-generated formula on `brew bottle --merge` for some reason
# so can't compare rebuild numbers
if [ "$UPSTREAM_VERSION" != "$VERSION" ]; then
REGENERATE=1
fi
else
REGENERATE=1
fi
if [ -n "$REGENERATE" ]; then
echo "Regenerating custom ffmpeg formula"
# Bottle block syntax: https://docs.brew.sh/Bottles#bottle-dsl-domain-specific-language
perl -wpe 'BEGIN {our ($found_blank, $bottle_block);}
if (/(^class )(Ffmpeg)(\s.*)/) {$_=$1.$2."Opencv".$3."\n"; next;}
if (!$found_blank && /^$/) {$_.="conflicts_with \"ffmpeg\"\n\n"; $found_blank=1; next;}
if (!$bottle_block && /^\s*bottle do$/) { $bottle_block=1; next; }
if ($bottle_block) { if (/^\s*end\s*$/) { $bottle_block=0} elsif (/^\s*sha256\s/) {$_=""} next; }
if (/^\s*depends_on "(x264|x265|xvid)"$/) {$_=""; next;}
if (/^\s*--enable-(gpl|libx264|libx265|libxvid)$/) {$_=""; next;}
' <"$FF_FORMULA" >"$LFF_FORMULA"
diff -u "$FF_FORMULA" "$LFF_FORMULA" || test $? -le 1

( cd "$(dirname "$LFF_FORMULA")"
# This is the official way to add a formula
# https://docs.brew.sh/Formula-Cookbook#commit
git add "$(basename "$LFF_FORMULA")"
git commit -m "add/update custom ffmpeg ${VERSION}"
)
fi
}

fi

function pre_build {
echo "Starting pre-build"
set -e
set -e -o pipefail

if [ -n "$IS_OSX" ]; then
echo "Running for OSX"

brew update --merge
brew_add_local_bottles

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

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

echo 'Installing QT4'
brew tap | grep -qxF cartr/qt4 || brew tap -v cartr/qt4
brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin -v cartr/qt4
brew list --versions qt@4 || brew install -v qt@4
echo '-----------------'
echo '-----------------'
brew tap | grep -qxF cartr/qt4 || brew tap cartr/qt4
brew tap --list-pinned | grep -qxF cartr/qt4 || brew tap-pin cartr/qt4
brew_install_and_cache_within_time_limit qt@4 || { [ $? -gt 1 ] && return 2 || return 0; }

echo 'Installing FFmpeg'
# brew install does produce output regularly on a regular MacOS,
# but Travis doesn't see it for some reason
brew list --versions ffmpeg || \
travis_wait brew install -v ffmpeg --without-x264 --without-xvid --without-gpl
brew info ffmpeg
echo '-----------------'

generate_ffmpeg_formula
brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }

else
echo "Running for linux"
Expand Down