Skip to content

Commit

Permalink
#5200: Move the core module to the modules/ folder. Let the applicati…
Browse files Browse the repository at this point in the history
…on context produce the list of library paths to search.

Fix a warning in ApplicationContextBase about converting wide strings to narrow ones.
  • Loading branch information
codereader committed Aug 30, 2020
1 parent 48d2d05 commit 19d2192
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 29 deletions.
42 changes: 30 additions & 12 deletions libs/module/ApplicationContextBase.cpp
Expand Up @@ -8,16 +8,22 @@
#include "os/fs.h"
#include "os/path.h"
#include "os/dir.h"
#if 0
#include "log/PopupErrorHandler.h"
#endif
#if defined(WIN32)
#include "string/encoding.h"

#ifdef WIN32
#define NOMINMAX
#include <windows.h>
#endif

namespace radiant
{

namespace
{
const std::string PLUGINS_DIR = "plugins/"; ///< name of plugins directory
const std::string MODULES_DIR = "modules/"; ///< name of modules directory
}

/**
* Return the application path of the current Radiant instance.
*/
Expand All @@ -28,21 +34,33 @@ std::string ApplicationContextBase::getApplicationPath() const

std::vector<std::string> ApplicationContextBase::getLibraryPaths() const
{
std::vector<std::string> libPaths;
auto libBasePath = os::standardPathWithSlash(getLibraryBasePath());

#if defined(__APPLE__) && defined(DR_MODULES_NEXT_TO_APP)
// Xcode output goes to the application folder right now
return { libBasePath };
#else
return
{
libBasePath + MODULES_DIR,
libBasePath + PLUGINS_DIR
};
#endif
}

std::string ApplicationContextBase::getLibraryBasePath() const
{
#if defined(__APPLE__)
libPaths.push_back(_appPath);
return _appPath;
#elif defined(POSIX)
# if defined(PKGLIBDIR) && !defined(ENABLE_RELOCATION)
libPaths.push_back(PKGLIBDIR);
return PKGLIBDIR;
# else
libPaths.push_back(_appPath + "../lib/darkradiant/");
return _appPath + "../lib/darkradiant/";
# endif
#else // !defined(POSIX)
libPaths.push_back(_appPath);
return _appPath;
#endif

return libPaths;
}

std::string ApplicationContextBase::getRuntimeDataPath() const
Expand Down Expand Up @@ -263,7 +281,7 @@ void ApplicationContextBase::initialise(int argc, char* argv[])

// convert to std::string
std::wstring wide(filename);
std::string appPathNarrow(wide.begin(), wide.end());
std::string appPathNarrow = string::unicode_to_mb(wide);

// Make sure we have forward slashes
_appPath = os::standardPath(appPathNarrow);
Expand Down
3 changes: 3 additions & 0 deletions libs/module/ApplicationContextBase.h
Expand Up @@ -45,6 +45,9 @@ class ApplicationContextBase :
protected:
void setErrorHandlingFunction(const ErrorHandlingFunction& function);

// The platform-specific path where any library folders like modules/ and plugins/ are stored
std::string getLibraryBasePath() const;

private:
// Sets up the bitmap path and settings path
void initPaths();
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/Makefile.am
@@ -1,4 +1,4 @@
libradiantcoredir = $(pkglibdir)
libradiantcoredir = $(pkglibdir)/modules
libradiantcore_LTLIBRARIES = libradiantcore.la

libradiantcore_la_CPPFLAGS = -DPKGLIBDIR='"$(pkglibdir)"' \
Expand Down
15 changes: 8 additions & 7 deletions radiantcore/modulesystem/ModuleLoader.cpp
Expand Up @@ -16,9 +16,6 @@ namespace module

namespace
{
const std::string PLUGINS_DIR = "plugins/"; ///< name of plugins directory
const std::string MODULES_DIR = "modules/"; ///< name of modules directory

// This is the name of the entry point symbol in the module
const char* const SYMBOL_REGISTER_MODULE = "RegisterModule";

Expand Down Expand Up @@ -91,10 +88,11 @@ void ModuleLoader::processModuleFile(const fs::path& file)
}
}

void ModuleLoader::loadModules(const std::string& root)
#if 0
void ModuleLoader::loadModules(const std::string& libraryPath)
{
// Get standardised paths
std::string stdRoot = os::standardPathWithSlash(root);
std::string stdRoot = os::standardPathWithSlash(libraryPath);

#if defined(DR_MODULES_NEXT_TO_APP)
// Xcode output goes to the application folder right now
Expand All @@ -105,7 +103,7 @@ void ModuleLoader::loadModules(const std::string& root)
std::string pluginsPath = stdRoot + PLUGINS_DIR;
#endif

rConsole() << "ModuleLoader: loading modules from " << root << std::endl;
rConsole() << "ModuleLoader: loading modules from " << libraryPath << std::endl;

// Load modules first, then plugins
loadModulesFromPath(modulesPath);
Expand All @@ -116,13 +114,16 @@ void ModuleLoader::loadModules(const std::string& root)
loadModulesFromPath(pluginsPath);
}
}
#endif

void ModuleLoader::loadModulesFromPath(const std::string& path)
{
rConsole() << "ModuleLoader: loading modules from " << path << std::endl;

// In case the folder is non-existent, catch the exception
try
{
os::foreachItemInDirectory(path, [&](const fs::path& file)
os::foreachItemInDirectory(os::standardPathWithSlash(path), [&](const fs::path& file)
{
processModuleFile(file);
});
Expand Down
6 changes: 2 additions & 4 deletions radiantcore/modulesystem/ModuleLoader.h
Expand Up @@ -27,15 +27,13 @@ class ModuleLoader
public:
ModuleLoader(IModuleRegistry& registry);

// Load algorithm, searches plugins/ and modules/ for .dll/.so files
void loadModules(const std::string& root);
// Load algorithm, searches the given folder for .dll/.so files
void loadModulesFromPath(const std::string& path);

// Frees the list of DLLs
void unloadModules();

private:
void loadModulesFromPath(const std::string& path);

// File functor, gets called with each file's name in the searched folder
void processModuleFile(const fs::path& fileName);
};
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/modulesystem/ModuleRegistry.cpp
Expand Up @@ -165,7 +165,7 @@ void ModuleRegistry::loadAndInitialiseModules()
auto libraryPaths = _context.getLibraryPaths();
for (auto path : libraryPaths)
{
_loader->loadModules(path);
_loader->loadModulesFromPath(path);
}

_progress = 0.1f;
Expand Down
8 changes: 4 additions & 4 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -1105,16 +1105,16 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)\..\..\install\</OutDir>
<OutDir>$(SolutionDir)\..\..\install\modules\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)\..\..\install\</OutDir>
<OutDir>$(SolutionDir)\..\..\install\modules\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)\..\..\install\</OutDir>
<OutDir>$(SolutionDir)\..\..\install\modules\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)\..\..\install\</OutDir>
<OutDir>$(SolutionDir)\..\..\install\modules\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand Down

0 comments on commit 19d2192

Please sign in to comment.