ropensci / opencv

R bindings for OpenCV
https://docs.ropensci.org/opencv
Other
137 stars 27 forks source link

.autobrew #30

Closed jwijffels closed 3 years ago

jwijffels commented 3 years ago

I'm using the same configure script in the R package image.textlinedetector https://github.com/DIGI-VUB/image.textlinedetector to use a limited set of facilities from opencv. Got this message from CRAN.

On macOS, a large number of files are being abandoned in a .autobrew
subdirectory of the directory from which source packages are being
installed during automated checking

When looking at https://github.com/ropensci/opencv/blob/master/configure#L49 It points to the following code at https://github.com/jeroen/autobrew/blob/master/opencv

if [ $(arch | grep arm) ]; then
echo "Could not find '$PKG_BREW_NAME' library for `arch`"
else

export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_AUTO_UPDATE=1

# Use the OpenCV4 name
PKG_CONFIG_NAME="opencv4"

# Offical Homebrew no longer supports El-Capitain
UPSTREAM_ORG="autobrew"

if [ "$DISABLE_AUTOBREW" ]; then return 0; fi
AUTOBREW="$(dirname `pwd`)/.autobrew"
export HOMEBREW_TEMP="$AUTOBREW/hbtmp"
BREWDIR="$AUTOBREW/build-$PKG_BREW_NAME"
BREW="$BREWDIR/bin/brew"
rm -Rf $BREWDIR
mkdir -p $BREWDIR
echo "$(date): Auto-brewing $PKG_BREW_NAME in $BREWDIR..."
curl -fsSL https://github.com/$UPSTREAM_ORG/brew/tarball/master | tar xz --strip 1 -C $BREWDIR

# Do not build pkg-config from source, so need to override hardcoded paths
export HOMEBREW_CACHE="$AUTOBREW"
$BREW install --force-bottle pkg-config 2>&1 | perl -pe 's/Warning/Note/gi'
PKG_CONFIG="$BREWDIR/opt/pkg-config/bin/pkg-config"
PC_PATH=$($PKG_CONFIG --variable pc_path pkg-config)
PC_PATH=$(echo $PC_PATH | perl -pe "s#/usr/local/Homebrew#${BREWDIR}#gi") #HOMEBREW_LIBRARY
PC_PATH=$(echo $PC_PATH | perl -pe "s#/usr/local#${BREWDIR}#gi") #HOMEBREW_PREFIX

# Install binary builds
BREW_DEPS=$($BREW deps -n $PKG_BREW_NAME 2>/dev/null)
$BREW install --force-bottle $BREW_DEPS $PKG_BREW_NAME  2>&1 | perl -pe 's/Warning/Note/gi'

# Set flags manually 
export PKG_CONFIG_PATH=$PC_PATH
export PKG_CONFIG_LIBDIR=$PC_PATH
PKG_CFLAGS=$($PKG_CONFIG --cflags $PKG_CONFIG_NAME)
PKG_LIBS=$($PKG_CONFIG --libs --static ${PKG_CONFIG_NAME})

# Prevent CRAN builder from linking against old libs in /usr/local/lib
for FILE in $BREWDIR/Cellar/*/*/lib/*.a; do
  BASENAME=`basename $FILE`
  LIBNAME=`echo "${BASENAME%.*}" | cut -c4-`
  cp -f $FILE $BREWDIR/lib/libbrew$LIBNAME.a
  echo "created $BREWDIR/lib/libbrew$LIBNAME.a"
  PKG_LIBS=`echo $PKG_LIBS | sed "s/-l$LIBNAME /-lbrew$LIBNAME /g"`
done
rm -f $BREWDIR/lib/*.dylib
rm -f $BREWDIR/Cellar/*/*/lib/*.dylib
PKG_LIBS="-L$BREWDIR/lib $PKG_LIBS"

# Copy share files
mkdir -p inst/share
cp -r $BREWDIR/opt/opencv/share/opencv4/haarcascades inst/share/
cp -r $BREWDIR/opt/opencv/share/opencv4/lbpcascades inst/share/

# Cleanup detritus
rm -Rf $BREWDIR/Library
echo "rm -Rf $AUTOBREW" >> cleanup
chmod +x cleanup

# Not ARM
fi

Is this something that can be fixed on https://github.com/jeroen/autobrew/blob/master/opencv or something that should be fixed on https://github.com/ropensci/opencv/blob/master/configure

jeroen commented 3 years ago

It is something that should be fixed in https://github.com/jeroen/autobrew/blob/master/opencv. I'll look into this asap.

jwijffels commented 3 years ago

I've got this note when trying to release R package image.textlinedetector to CRAN, which uses practically the same configure script as the one from opencv

* checking top-level files ... NOTE
‘configure’: ‘env bash’ is not portable as bash need not be installed
jeroen commented 3 years ago

Yes BDR changed the rules again. You're no longer allowed to use bash, and now required to use backticks instead of $() in configure scripts. I've fixed it here: https://github.com/ropensci/opencv/commit/7ddecfb369f38c0606afb0f1352a42c1b1ef7b41

jwijffels commented 3 years ago

Thanks. I'll try again with that new configure script.

jeroen commented 3 years ago

OK let me know if it works :D

jwijffels commented 3 years ago

Got the following from the automatic CRAN test system

* checking top-level files ... NOTE
  possible bashism in configure line 42 ($(OS|MACH)TYPE):
    case "$OSTYPE" in "darwin"*)
  possible bashism in configure line 50 (should be '.', not 'source'):
      source autobrew
jeroen commented 3 years ago

Ah right. One sec let me fix that

jeroen commented 3 years ago

I pushed another update, can you try again?

jwijffels commented 3 years ago

That seems to have fixed it. No more issues related to the configure script. Thanks!