futher Linux Python auto-configuration improvements

metadata
Wenzel Jakob 2012-10-20 18:08:36 -04:00
parent 131ae05f3e
commit d161aa6490
3 changed files with 30 additions and 22 deletions

View File

@ -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('<path to mitsuba directory>')
# Register the search path needed to load scene resources
# Register any searchs path needed to load scene resources (optional)
fileResolver.appendPath('<path to scene directory>')
# Optional: supply parameters that can be accessed

View File

@ -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!");

View File

@ -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; i<imageCount; ++i) {
const char *imageName = _dyld_get_image_name(i);
if (boost::ends_with(imageName, "mitsuba.so"))
sharedLibraryPath = fs::path(imageName);
basePath = fs::path(imageName).parent_path().parent_path().parent_path();
}
#endif
if (!sharedLibraryPath.empty())
Thread::getThread()->getFileResolver()->prependPath(
sharedLibraryPath.parent_path().parent_path().parent_path());
if (!basePath.empty())
Thread::getThread()->getFileResolver()->prependPath(basePath);
}
void shutdownFramework() {