SDK: Support DYLD_LIBRARY_PATH from parent env in sdk::DDSEnv

Fixes #235
This commit is contained in:
Dennis Klein 2020-02-13 12:09:53 +01:00 committed by Dennis Klein
parent 278cd62049
commit 3785fd9ff9

View File

@ -55,12 +55,17 @@ struct DDSEnvironment::Impl
setenv("HOME", fConfigHome.c_str(), 1); setenv("HOME", fConfigHome.c_str(), 1);
} }
std::istringstream cmd; std::stringstream cmd;
cmd.str("DDS_CFG=`dds-user-defaults --ignore-default-sid -p`\n" #ifdef __APPLE__
// On macOS System Integrity Protection might filter out the DYLD_LIBRARY_PATH, so we pass it
// through explicitely here.
cmd << "export " << fgLdVar << "=" << GetEnv(fgLdVar) << "\n";
#endif
cmd << "DDS_CFG=`dds-user-defaults --ignore-default-sid -p`\n"
"if [ -z \"$DDS_CFG\" ]; then\n" "if [ -z \"$DDS_CFG\" ]; then\n"
" mkdir -p \"$HOME/.DDS\"\n" " mkdir -p \"$HOME/.DDS\"\n"
" dds-user-defaults --ignore-default-sid -d -c \"$HOME/.DDS/DDS.cfg\"\n" " dds-user-defaults --ignore-default-sid -d -c \"$HOME/.DDS/DDS.cfg\"\n"
"fi"); "fi\n";
std::system(cmd.str().c_str()); std::system(cmd.str().c_str());
} }
@ -72,20 +77,23 @@ struct DDSEnvironment::Impl
setenv("PATH", path.c_str(), 1); setenv("PATH", path.c_str(), 1);
} }
auto SetupDynamicLoader() -> void auto GenerateDDSLibDir() const -> Path
{ {
#ifdef __APPLE__ return {(fLocation == DDSInstallPrefix) ? DDSLibraryDir : fLocation / Path("lib")};
std::string ldVar("DYLD_LIBRARY_PATH");
#else
std::string ldVar("LD_LIBRARY_PATH");
#endif
std::string ld(GetEnv(ldVar));
Path ddsLibDir = (fLocation == DDSInstallPrefix) ? DDSLibraryDir : fLocation / Path("lib");
ld = ddsLibDir.string() + std::string(":") + ld;
setenv(ldVar.c_str(), ld.c_str(), 1);
} }
auto GetEnv(const std::string& key) -> std::string auto SetupDynamicLoader() -> void
{
std::string ld(GetEnv(fgLdVar));
if (ld.empty()) {
ld = GenerateDDSLibDir().string();
} else {
ld = GenerateDDSLibDir().string() + std::string(":") + ld;
}
setenv(fgLdVar.c_str(), ld.c_str(), 1);
}
auto GetEnv(const std::string& key) const -> std::string
{ {
auto value = std::getenv(key.c_str()); auto value = std::getenv(key.c_str());
if (value) { if (value) {
@ -100,6 +108,11 @@ struct DDSEnvironment::Impl
Path fLocation; Path fLocation;
Path fConfigHome; Path fConfigHome;
#ifdef __APPLE__
std::string const fgLdVar = "DYLD_LIBRARY_PATH";
#else
std::string const fgLdVar = "LD_LIBRARY_PATH";
#endif
}; };
DDSEnvironment::DDSEnvironment() DDSEnvironment::DDSEnvironment()