futher Linux Python auto-configuration improvements
parent
131ae05f3e
commit
d161aa6490
|
@ -66,10 +66,7 @@ from mitsuba.render import SceneHandler
|
||||||
# Get a reference to the thread's file resolver
|
# Get a reference to the thread's file resolver
|
||||||
fileResolver = Thread.getThread().getFileResolver()
|
fileResolver = Thread.getThread().getFileResolver()
|
||||||
|
|
||||||
# Register the search path needed to load plugins
|
# Register any searchs path needed to load scene resources (optional)
|
||||||
fileResolver.appendPath('<path to mitsuba directory>')
|
|
||||||
|
|
||||||
# Register the search path needed to load scene resources
|
|
||||||
fileResolver.appendPath('<path to scene directory>')
|
fileResolver.appendPath('<path to scene directory>')
|
||||||
|
|
||||||
# Optional: supply parameters that can be accessed
|
# Optional: supply parameters that can be accessed
|
||||||
|
|
|
@ -10,16 +10,19 @@ MTS_NAMESPACE_BEGIN
|
||||||
FileResolver::FileResolver() {
|
FileResolver::FileResolver() {
|
||||||
m_paths.push_back(fs::current_path());
|
m_paths.push_back(fs::current_path());
|
||||||
#if defined(__LINUX__)
|
#if defined(__LINUX__)
|
||||||
char exePath[PATH_MAX];
|
char exePathTemp[PATH_MAX];
|
||||||
memset(exePath, 0, PATH_MAX);
|
memset(exePathTemp, 0, PATH_MAX);
|
||||||
if (readlink("/proc/self/exe", exePath, PATH_MAX) != -1) {
|
if (readlink("/proc/self/exe", exePathTemp, PATH_MAX) != -1) {
|
||||||
const fs::path exeParentPath = fs::path(exePath).parent_path();
|
fs::path exePath(exePathTemp);
|
||||||
prependPath(exeParentPath);
|
|
||||||
// Handle local installs: ~/local/bin/:~/local/share/mitsuba/*
|
/* Make sure that we're not running inside a Python interpreter */
|
||||||
fs::path sharedDir = exeParentPath.parent_path();
|
if (exePath.filename().string().find("python") == std::string::npos) {
|
||||||
sharedDir /= fs::path("share/mitsuba");
|
prependPath(exePath.parent_path());
|
||||||
if (fs::exists(sharedDir)) {
|
// Handle local installs: ~/local/bin/:~/local/share/mitsuba/*
|
||||||
prependPath(sharedDir);
|
fs::path sharedDir = exePath.parent_path().parent_path()
|
||||||
|
/ fs::path("share") / fs::path("mitsuba");
|
||||||
|
if (fs::exists(sharedDir))
|
||||||
|
prependPath(sharedDir);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log(EError, "Could not detect the executable path!");
|
Log(EError, "Could not detect the executable path!");
|
||||||
|
|
|
@ -47,26 +47,34 @@ void initializeFramework() {
|
||||||
SHVector::staticInitialization();
|
SHVector::staticInitialization();
|
||||||
SceneHandler::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__)
|
#if defined(__LINUX__)
|
||||||
Dl_info info;
|
Dl_info info;
|
||||||
dladdr((void *) &initializeFramework, &info);
|
dladdr((void *) &initializeFramework, &info);
|
||||||
if (info.dli_fname)
|
if (info.dli_fname) {
|
||||||
sharedLibraryPath = fs::path(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__)
|
#elif defined(__OSX__)
|
||||||
uint32_t imageCount = _dyld_image_count();
|
uint32_t imageCount = _dyld_image_count();
|
||||||
for (uint32_t i=0; i<imageCount; ++i) {
|
for (uint32_t i=0; i<imageCount; ++i) {
|
||||||
const char *imageName = _dyld_get_image_name(i);
|
const char *imageName = _dyld_get_image_name(i);
|
||||||
if (boost::ends_with(imageName, "mitsuba.so"))
|
if (boost::ends_with(imageName, "mitsuba.so"))
|
||||||
sharedLibraryPath = fs::path(imageName);
|
basePath = fs::path(imageName).parent_path().parent_path().parent_path();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!sharedLibraryPath.empty())
|
if (!basePath.empty())
|
||||||
Thread::getThread()->getFileResolver()->prependPath(
|
Thread::getThread()->getFileResolver()->prependPath(basePath);
|
||||||
sharedLibraryPath.parent_path().parent_path().parent_path());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdownFramework() {
|
void shutdownFramework() {
|
||||||
|
|
Loading…
Reference in New Issue