From d161aa6490d874d20f46d28f1df410e4b11fcd8c Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sat, 20 Oct 2012 18:08:36 -0400 Subject: [PATCH] futher Linux Python auto-configuration improvements --- doc/python.tex | 5 +---- src/libcore/fresolver.cpp | 23 +++++++++++++---------- src/libpython/core.cpp | 24 ++++++++++++++++-------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/doc/python.tex b/doc/python.tex index 51d15c63..594a494c 100644 --- a/doc/python.tex +++ b/doc/python.tex @@ -66,10 +66,7 @@ from mitsuba.render import SceneHandler # Get a reference to the thread's file resolver fileResolver = Thread.getThread().getFileResolver() -# Register the search path needed to load plugins -fileResolver.appendPath('') - -# Register the search path needed to load scene resources +# Register any searchs path needed to load scene resources (optional) fileResolver.appendPath('') # Optional: supply parameters that can be accessed diff --git a/src/libcore/fresolver.cpp b/src/libcore/fresolver.cpp index d66444f8..80cf0ba4 100644 --- a/src/libcore/fresolver.cpp +++ b/src/libcore/fresolver.cpp @@ -10,16 +10,19 @@ MTS_NAMESPACE_BEGIN FileResolver::FileResolver() { m_paths.push_back(fs::current_path()); #if defined(__LINUX__) - char exePath[PATH_MAX]; - memset(exePath, 0, PATH_MAX); - if (readlink("/proc/self/exe", exePath, PATH_MAX) != -1) { - const fs::path exeParentPath = fs::path(exePath).parent_path(); - prependPath(exeParentPath); - // Handle local installs: ~/local/bin/:~/local/share/mitsuba/* - fs::path sharedDir = exeParentPath.parent_path(); - sharedDir /= fs::path("share/mitsuba"); - if (fs::exists(sharedDir)) { - prependPath(sharedDir); + char exePathTemp[PATH_MAX]; + memset(exePathTemp, 0, PATH_MAX); + if (readlink("/proc/self/exe", exePathTemp, PATH_MAX) != -1) { + fs::path exePath(exePathTemp); + + /* Make sure that we're not running inside a Python interpreter */ + if (exePath.filename().string().find("python") == std::string::npos) { + prependPath(exePath.parent_path()); + // Handle local installs: ~/local/bin/:~/local/share/mitsuba/* + fs::path sharedDir = exePath.parent_path().parent_path() + / fs::path("share") / fs::path("mitsuba"); + if (fs::exists(sharedDir)) + prependPath(sharedDir); } } else { Log(EError, "Could not detect the executable path!"); diff --git a/src/libpython/core.cpp b/src/libpython/core.cpp index 8c0ad7c9..3c6ca52b 100644 --- a/src/libpython/core.cpp +++ b/src/libpython/core.cpp @@ -47,26 +47,34 @@ void initializeFramework() { SHVector::staticInitialization(); SceneHandler::staticInitialization(); - fs::path sharedLibraryPath; + fs::path basePath; - /* Try to detect the python plugin path */ + /* Try to detect the base path of the Mitsuba installation */ #if defined(__LINUX__) Dl_info info; dladdr((void *) &initializeFramework, &info); - if (info.dli_fname) - sharedLibraryPath = fs::path(info.dli_fname); + if (info.dli_fname) { + /* Try to detect a few default setups */ + if (boost::starts_with(info.dli_fname, "/usr/lib")) { + basePath = fs::path("/usr/share/mitsuba"); + } else if (boost::starts_with(info.dli_fname, "/usr/local/lib")) { + basePath = fs::path("/usr/local/share/mitsuba"); + } else { + /* This is a locally-compiled repository */ + basePath = fs::path(info.dli_fname).parent_path().parent_path().parent_path(); + } + } #elif defined(__OSX__) uint32_t imageCount = _dyld_image_count(); for (uint32_t i=0; igetFileResolver()->prependPath( - sharedLibraryPath.parent_path().parent_path().parent_path()); + if (!basePath.empty()) + Thread::getThread()->getFileResolver()->prependPath(basePath); } void shutdownFramework() {