Skip to content

Commit

Permalink
#5200: Change the IApplicationContext::getLibraryPaths() interface to…
Browse files Browse the repository at this point in the history
… return a collection of paths.
  • Loading branch information
codereader committed Aug 30, 2020
1 parent 18061fe commit 48d2d05
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 20 deletions.
5 changes: 3 additions & 2 deletions include/imodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ class IApplicationContext
virtual std::string getApplicationPath() const = 0;

/**
* Return the application library path, containing modules and plugins.
* Return the application library paths, each of these is searched
* for any libraries containing modules and/or plugins.
*
* On Windows this is most likely the same as the application path. On
* Linux it might be a hard-coded path like /usr/lib/darkradiant, or a
* relocatable relative path like ../lib
*/
virtual std::string getLibraryPath() const = 0;
virtual std::vector<std::string> getLibraryPaths() const = 0;

/**
* Return the toplevel path contaning runtime data files, such as the GL
Expand Down
14 changes: 9 additions & 5 deletions libs/module/ApplicationContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ std::string ApplicationContextBase::getApplicationPath() const
return _appPath;
}

std::string ApplicationContextBase::getLibraryPath() const
std::vector<std::string> ApplicationContextBase::getLibraryPaths() const
{
std::vector<std::string> libPaths;

#if defined(__APPLE__)
return _appPath;
libPaths.push_back(_appPath);
#elif defined(POSIX)
# if defined(PKGLIBDIR) && !defined(ENABLE_RELOCATION)
return PKGLIBDIR;
libPaths.push_back(PKGLIBDIR);
# else
return _appPath + "../lib/darkradiant/";
libPaths.push_back(_appPath + "../lib/darkradiant/");
# endif
#else // !defined(POSIX)
return _appPath;
libPaths.push_back(_appPath);
#endif

return libPaths;
}

std::string ApplicationContextBase::getRuntimeDataPath() const
Expand Down
2 changes: 1 addition & 1 deletion libs/module/ApplicationContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ApplicationContextBase :

/* ApplicationContext implementation */
virtual std::string getApplicationPath() const override;
virtual std::string getLibraryPath() const override;
virtual std::vector<std::string> getLibraryPaths() const override;
virtual std::string getRuntimeDataPath() const override;
virtual std::string getHTMLPath() const override;
virtual std::string getSettingsPath() const override;
Expand Down
35 changes: 24 additions & 11 deletions libs/module/CoreModule.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "CoreModule.h"

#include "DynamicLibrary.h"
#include "string/join.h"

// In Linux the CORE_MODULE_LIBRARY symbol is defined in config.h
#ifdef HAVE_CONFIG_H
Expand All @@ -15,17 +16,9 @@ namespace module
CoreModule::CoreModule(IApplicationContext& context) :
_instance(nullptr)
{
std::string coreModuleFile = std::string(CORE_MODULE_LIBRARY) + MODULE_FILE_EXTENSION;

fs::path coreModulePath = context.getLibraryPath();
coreModulePath /= coreModuleFile;

if (!fs::exists(coreModulePath))
{
throw FailureException("Cannot find the main module " + coreModulePath.string());
}

_coreModuleLibrary.reset(new DynamicLibrary(coreModulePath.string()));
auto coreModulePath = findCoreModule(context);

_coreModuleLibrary.reset(new DynamicLibrary(coreModulePath));

if (_coreModuleLibrary->failed())
{
Expand All @@ -50,6 +43,26 @@ CoreModule::~CoreModule()
destroy();
}

std::string CoreModule::findCoreModule(IApplicationContext& context)
{
std::string coreModuleFile = std::string(CORE_MODULE_LIBRARY) + MODULE_FILE_EXTENSION;
auto libraryPaths = context.getLibraryPaths();

for (auto libPath : libraryPaths)
{
fs::path coreModulePath = libPath;
coreModulePath /= coreModuleFile;

if (fs::exists(coreModulePath))
{
return coreModulePath.string();
}
}

throw FailureException("Cannot find the main module in any of the paths: " +
string::join(libraryPaths, "; "));
}

radiant::IRadiant* CoreModule::get()
{
return _instance;
Expand Down
1 change: 1 addition & 0 deletions libs/module/CoreModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CoreModule
radiant::IRadiant* get();

private:
std::string findCoreModule(IApplicationContext& context);
void destroy();
};

Expand Down
1 change: 1 addition & 0 deletions libs/module/DynamicLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const char* const MODULE_FILE_EXTENSION = ".so";
*/
#if defined(WIN32)

#define NOMINMAX
#include <windows.h>

namespace module
Expand Down
6 changes: 5 additions & 1 deletion radiantcore/modulesystem/ModuleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ void ModuleRegistry::loadAndInitialiseModules()
rMessage() << "ModuleRegistry Compatibility Level is " << getCompatibilityLevel() << std::endl;

// Invoke the ModuleLoad routine to load the DLLs from modules/ and plugins/
_loader->loadModules(_context.getLibraryPath());
auto libraryPaths = _context.getLibraryPaths();
for (auto path : libraryPaths)
{
_loader->loadModules(path);
}

_progress = 0.1f;
_sigModuleInitialisationProgress.emit(_("Initialising Modules"), _progress);
Expand Down

0 comments on commit 48d2d05

Please sign in to comment.