From 42ae344aa8f10663760dd498abb7e3bda19c0020 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 3 Feb 2021 06:04:28 -0800 Subject: [PATCH] Mac: use recollhelperpath config variable to set the PATH for the .app, cant find a way with launchd --- src/common/rclinit.cpp | 75 +++++++++++++++++++++++--------------- src/sampleconf/recoll.conf | 4 +- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/common/rclinit.cpp b/src/common/rclinit.cpp index e2d7395e..edd55977 100644 --- a/src/common/rclinit.cpp +++ b/src/common/rclinit.cpp @@ -273,35 +273,6 @@ RclConfig *recollinit(int flags, if (cleanup) atexit(cleanup); -#ifdef __APPLE__ - // The MACPORTS and HOMEBREW flags are set by the resp. portfile - // and recipee - - // Apple keeps changing the way to set the environment (PATH) for - // a desktop app (started by launchd or whatever). Life is too - // short. - const char *cp = getenv("PATH"); - if (!cp) //?? - cp = ""; - string PATH(cp); -#if defined(MACPORTS) - PATH = string("/opt/local/bin/") + ":" + PATH; -#elif defined(HOMEBREW) - PATH = string("/usr/local/bin/") + ":" + PATH; -#else - // Native qt build. Add our own directory to the path so that - // recoll finds recollindex pkgdatadir: - // /Applications/recoll.app/Contents/Resources - // - // NOTE: This does not work when running from a mounted dmg - // because the location contains colons:/Volumes/:Users:dockes:Recoll:... - // which messes with the PATH colon separators of course. - std::string exedir = path_cat(path_getfather(path_pkgdatadir()), "MacOS"); - PATH = exedir + ":" + PATH; -#endif - setenv("PATH", PATH.c_str(), 1); -#endif /* __APPLE__ */ - // Make sure the locale is set. This is only for converting file names // to utf8 for indexing. setlocale(LC_CTYPE, ""); @@ -321,6 +292,52 @@ RclConfig *recollinit(int flags, return 0; } +#ifdef __APPLE__ + // Setting the PATH for a desktop app + // + // Apple keeps changing the way to set the environment (PATH) for + // a desktop app (started by launchd or whatever). Life is too + // short. + // + // The MACPORTS and HOMEBREW flags are set by the resp. portfile + // and recipee. The hard-coded values of paths added for MACPORTS + // and HOMEBREW could be replaced with recollhelperpath use. Kept + // to minimize disturbance. + + const char *cp = getenv("PATH"); + if (!cp) //?? + cp = ""; + string PATH(cp); + +#if defined(MACPORTS) + PATH = string("/opt/local/bin/") + ":" + PATH; +#elif defined(HOMEBREW) + PATH = string("/usr/local/bin/") + ":" + PATH; +#else + // Native qt build. Add our own directory to the path so that + // recoll finds recollindex pkgdatadir: + // /Applications/recoll.app/Contents/Resources + // + // NOTE: This does not work when running from a mounted dmg + // because the location contains colons:/Volumes/:Users:dockes:Recoll:... + // which messes with the PATH colon separators of course. + // + // Also, as far as I can see launchd actually includes the + // directory in the PATH, so this is redundant. Otoh, launchd + // changes a lot... + std::string exedir = path_cat(path_getfather(path_pkgdatadir()), "MacOS"); + PATH = exedir + ":" + PATH; +#endif + + std::string rhpp + if (config->getConfParam("recollhelperpath", rhpp) && !rhpp.empty()) { + PATH = rhpp + ":" + PATH; + } + + setenv("PATH", PATH.c_str(), 1); + LOGDEB("Rclinit: PATH [" << getenv("PATH") << "]\n"); +#endif /* __APPLE__ */ + TextSplit::staticConfInit(config); // Retrieve the log file name and level. Daemon and batch indexing diff --git a/src/sampleconf/recoll.conf b/src/sampleconf/recoll.conf index 99f1335b..1a9462aa 100644 --- a/src/sampleconf/recoll.conf +++ b/src/sampleconf/recoll.conf @@ -732,7 +732,9 @@ checkneedretryindexscript = rclcheckneedretry.sh # # # Additional places to search for helper executables. -# This is only used on Windows for now. +# This is used on Windows by the Python code, and on Mac OS by +# the bundled recoll.app (because I could find no reliable way to tell +# launchd to set the PATH. The example below is for Windows. #recollhelperpath = c:/someprog/bin;c:/someotherprog/bin #