From 23c2776cb483bddcc7532fc62a797cb8cd300d7b Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Thu, 9 Apr 2020 10:26:04 +0100 Subject: [PATCH] Recoll Python module build with msvc. Help the module find the datadir. --- src/python/recoll/pyrclextract.cpp | 2 -- src/python/recoll/pyrecoll.cpp | 2 -- src/python/recoll/recoll/rclconfig.py | 9 ++++- src/utils/rclutil.cpp | 48 +++++++++++++++++++-------- src/windows/mkinstdir.sh | 47 ++++++++++++++++++-------- 5 files changed, 77 insertions(+), 31 deletions(-) diff --git a/src/python/recoll/pyrclextract.cpp b/src/python/recoll/pyrclextract.cpp index 34dc3a71..fe1982e8 100644 --- a/src/python/recoll/pyrclextract.cpp +++ b/src/python/recoll/pyrclextract.cpp @@ -20,8 +20,6 @@ #include #include -#include - #include #include diff --git a/src/python/recoll/pyrecoll.cpp b/src/python/recoll/pyrecoll.cpp index fac7f037..bbe02b9f 100644 --- a/src/python/recoll/pyrecoll.cpp +++ b/src/python/recoll/pyrecoll.cpp @@ -19,8 +19,6 @@ #include #include -#include - #include #include #include diff --git a/src/python/recoll/recoll/rclconfig.py b/src/python/recoll/recoll/rclconfig.py index 67d8661a..cf256e8d 100644 --- a/src/python/recoll/recoll/rclconfig.py +++ b/src/python/recoll/recoll/rclconfig.py @@ -54,7 +54,14 @@ class RclConfig: self.datadir = os.environ["RECOLL_DATADIR"] else: if platsys == "Windows": - self.datadir = os.path.join(os.path.dirname(sys.argv[0]), "..") + dirs = (os.path.join(os.path.dirname(sys.argv[0]), "..", ".."), + "C:/Program Files (X86)/Recoll/", + "C:/Program Files/Recoll/", + "C:/install/recoll/") + for dir in dirs: + if os.path.exists(os.path.join(dir, "Share")): + self.datadir = os.path.join(dir, "Share") + break else: dirs = ("/opt/local", "/usr", "/usr/local") for dir in dirs: diff --git a/src/utils/rclutil.cpp b/src/utils/rclutil.cpp index cb0049cf..953a9af9 100644 --- a/src/utils/rclutil.cpp +++ b/src/utils/rclutil.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "rclutil.h" #include "pathut.h" @@ -193,23 +194,44 @@ string path_defaultrecollconfsubdir() #endif } -// Location for sample config, filters, etc. (e.g. /usr/share/recoll/) +// Location for sample config, filters, etc. E.g. /usr/share/recoll/ on linux +// or c:/program files (x86)/recoll/share on Windows const string& path_pkgdatadir() { static string datadir; - if (datadir.empty()) { -#ifdef _WIN32 - datadir = path_cat(path_thisexecpath(), "Share"); -#else - const char *cdatadir = getenv("RECOLL_DATADIR"); - if (cdatadir == 0) { - // If not in environment, use the compiled-in constant. - datadir = RECOLL_DATADIR; - } else { - datadir = cdatadir; - } -#endif + if (!datadir.empty()) { + return datadir; } + const char *cdatadir = getenv("RECOLL_DATADIR"); + if (nullptr != cdatadir) { + datadir = cdatadir; + return datadir; + } + +#ifdef _WIN32 + // Try a path relative with the exec. This works if we are + // recoll/recollindex etc. + // But maybe we are the python module, and execpath is the python + // exe which could be anywhere. Try the default installation + // directory, else tell the user to set the environment + // variable. + vector paths{path_thisexecpath(), "c:/program files (x86)/recoll", + "c:/program files/recoll"}; + for (const auto& path : paths) { + datadir = path_cat(path, "Share"); + if (path_exists(datadir)) { + return datadir; + } + } + // Not found + std::cerr << "Could not find the recoll installation data. It is usually " + "a subfolder of the installation directory. \n" + "Please set the RECOLL_DATADIR environment variable to point to it\n" + "(e.g. setx RECOLL_DATADIR \"C:/Program Files (X86)/Recoll/Share)\"\n"; +#else + // If not in environment, use the compiled-in constant. + datadir = RECOLL_DATADIR; +#endif return datadir; } diff --git a/src/windows/mkinstdir.sh b/src/windows/mkinstdir.sh index 0c1b3b6a..b5b99240 100644 --- a/src/windows/mkinstdir.sh +++ b/src/windows/mkinstdir.sh @@ -22,14 +22,14 @@ test -d $DESTDIR || mkdir $DESTDIR || fatal cant create $DESTDIR ################################ # Local values (to be adjusted) -#BUILD=MSVC -BUILD=MINGW +BUILD=MSVC +#BUILD=MINGW if test $BUILD = MSVC ; then # Recoll src tree RCL=c:/users/bill/documents/recoll/src/ # Recoll dependancies - RCLDEPS=c:/users/bill/documents/recolldeps/ + RCLDEPS=/c/users/bill/documents/recolldeps/ QTA=Desktop_Qt_5_14_1_MSVC2017_32bit-Release/release LIBXML=${RCLDEPS}/msvc/libxml2/libxml2-2.9.4+dfsg1/win32/bin.msvc/libxml2.dll LIBXSLT=${RCLDEPS}/msvc/libxslt/libxslt-1.1.29/win32/bin.msvc/libxslt.dll @@ -37,6 +37,7 @@ if test $BUILD = MSVC ; then ZLIB=${RCLDEPS}/msvc/zlib-1.2.11 QTBIN=C:/Qt/5.14.1/msvc2017/bin MINGWBIN=c:/Qt/5.14.1/mingw73_32/bin/ + PYRECOLL=${RCL}/python/recoll/ else # Recoll src tree RCL=c:/recoll/src/ @@ -45,7 +46,6 @@ else QTA=Desktop_Qt_5_8_0_MinGW_32bit-Release/release LIBXAPIAN=${RCLDEPS}/mingw/xapian-core-1.4.11/.libs/libxapian-30.dll ZLIB=${RCLDEPS}/mingw/zlib-1.2.8 - ASPELL=${RCLDEPS}/mingw/aspell-0.60.7/aspell-installed QTGCCBIN=C:/qt/Qt5.8.0/Tools/mingw530_32/bin/ QTBIN=C:/Qt/Qt5.8.0/5.8/mingw53_32/bin MINGWBIN=$QTBIN @@ -53,6 +53,11 @@ else export PATH fi +# We use the mingw-compiled aspell program in both cases. When +# compiling with msvc, we copy the msvc dll to the recoll top dir (and +# don't use the exec, we keep the already tested mingw one). +ASPELL=${RCLDEPS}/mingw/aspell-0.60.7/aspell-installed + # Where to find libgcc_s_dw2-1.dll et all for progs compiled with # c:/MinGW (as opposed to the mingw bundled with qt). This is the same # for either a msvc or mingw build of recoll itself. @@ -128,7 +133,7 @@ copyqt() copypython() { mkdir -p $DESTDIR/Share/filters/python - cp -rp $PYTHON/* $DESTDIR/Share/filters/python + rsync -av $PYTHON/* $DESTDIR/Share/filters/python chkcp $PYTHON/python.exe $DESTDIR/Share/filters/python/python.exe chkcp $MISC/hwp5html $FILTERS } @@ -170,6 +175,7 @@ copyrecoll() chkcp $RCLDEPS/rclimg/rclimg.exe $FILTERS chkcp $RCL/qtgui/mtpics/* $DESTDIR/Share/images chkcp $RCL/qtgui/i18n/*.qm $DESTDIR/Share/translations + chkcp $RCL/desktop/recoll.ico $DESTDIR/Share } copyantiword() @@ -285,13 +291,27 @@ copypff() copyaspell() { DEST=$FILTERS - if test $BUILD = MINGW ; then - cp -rp $ASPELL $DEST || fatal "can't copy $ASPELL" - DEST=$DEST/aspell-installed/mingw32/bin - # Check that we do have an aspell.exe. - chkcp $ASPELL/mingw32/bin/aspell.exe $DEST - chkcp $MINGWBIN/libgcc_s_dw2-1.dll $DEST - chkcp $MINGWBIN/libstdc++-6.dll $DEST + cp -rp $ASPELL $DEST || fatal "can't copy $ASPELL" + DEST=$DEST/aspell-installed/mingw32/bin + # Check that we do have an aspell.exe. + chkcp $ASPELL/mingw32/bin/aspell.exe $DEST + chkcp $MINGWBIN/libgcc_s_dw2-1.dll $DEST + chkcp $MINGWBIN/libstdc++-6.dll $DEST + chkcp $MINGWBIN/libwinpthread-1.dll $DEST + if test $BUILD = MSVC ; then + chkcp $RCLDEPS/mingw/build-libaspell-Desktop_Qt_5_14_1_MSVC2017_32bit-Release/release/aspell.dll $DESTDIR/libaspell-15.dll + fi +} + +# Recoll python package. Only when compiled with msvc as this is what +# the standard Python dist is built with +copypyrecoll() +{ + if test $BUILD = MSVC ; then + PYRCLWHEEL=${PYRECOLL}/dist/Recoll-${VERSION}-cp37-cp37m-win32.whl + DEST=${DESTDIR}/Share/dist + test -d $DEST || mkdir $DEST || fatal cant create $DEST + chkcp ${PYRCLWHEEL} $DEST fi } @@ -312,10 +332,11 @@ for d in doc examples filters images translations; do fatal mkdir $d failed done -copyaspell # copyrecoll must stay before copyqt so that windeployqt can do its thing copyrecoll +copypyrecoll copyqt +copyaspell copypyxslt copypoppler copyantiword