Commit 121105ad authored by Didier WECKMANN's avatar Didier WECKMANN
Browse files

fix(core): broken library path on external projects when using '.local' in installation paths

The deduction of the library path failed when share was already present in the main module path. The problem already occurred with module paths themselves, so the regex is now shared between these two places.


Merge branch '761-core-broken-library-path-on-external-projects-when-using-local-in-installation-paths' into 'dev'
Closes #761
See merge request sight/sight!614
parents 60a298a9 cd3a8613
......@@ -70,13 +70,12 @@ Module::Module(
// Post-condition.
SIGHT_ASSERT("Invalid module location.", m_resourcesLocation.is_absolute() == true);
#ifdef WIN32
static const std::regex expr("share(?!.*share)\\\\.*");
#else
static const std::regex expr("share(?!.*share)/.*");
#endif
const auto locationNormalized = std::filesystem::weakly_canonical(location);
const auto strLocation = std::regex_replace(locationNormalized.string(), expr, MODULE_LIB_PREFIX);
const auto strLocation = std::regex_replace(
locationNormalized.string(),
Runtime::s_MATCH_MODULE_PATH,
MODULE_LIB_PREFIX
);
// This may fail if the module does not contain any library, so we ignore the returned error
m_libraryLocation = std::filesystem::weakly_canonical(std::filesystem::path(strLocation));
......
......@@ -23,6 +23,7 @@
#pragma once
#include "core/runtime/detail/dl/Library.hpp"
#include "core/runtime/detail/Runtime.hpp"
#include "core/runtime/Module.hpp"
#include <core/base.hpp>
......
......@@ -44,6 +44,12 @@ namespace sight::core::runtime
namespace detail
{
#ifdef WIN32
const std::regex Runtime::s_MATCH_MODULE_PATH("share(?!.*share)\\\\.*");
#else
const std::regex Runtime::s_MATCH_MODULE_PATH("share(?!.*share)/.*");
#endif
//------------------------------------------------------------------------------
std::shared_ptr<Runtime> Runtime::m_instance;
......@@ -124,8 +130,11 @@ void Runtime::addModules(const std::filesystem::path& repository)
{
const auto modules = core::runtime::detail::io::ModuleDescriptorReader::createModules(repository);
std::for_each(modules.begin(), modules.end(), std::bind(&Runtime::addModule, this, std::placeholders::_1));
static const std::regex expr("share[\\\\/]\\w*");
const auto libRepoStr = std::regex_replace(repository.string(), expr, MODULE_LIB_PREFIX);
const auto libRepoStr = std::regex_replace(
repository.lexically_normal().string(),
s_MATCH_MODULE_PATH,
MODULE_LIB_PREFIX
);
m_repositories.push_back(
std::make_pair(
std::filesystem::weakly_canonical(std::filesystem::path(libRepoStr)),
......
......@@ -25,6 +25,8 @@
#include "core/config.hpp"
#include "core/runtime/Runtime.hpp"
#include <regex>
namespace sight::core::runtime
{
......@@ -45,6 +47,9 @@ public:
/// Defines the module container type.
typedef std::set<std::shared_ptr<Module> > ModuleContainer;
/// Regex used in different places to find the module part in a path
static const std::regex s_MATCH_MODULE_PATH;
/**
* @brief Retrieves the default runtime instance.
*/
......
......@@ -85,7 +85,7 @@ void init(const std::filesystem::path& directory)
// Load default modules
core::runtime::Runtime* rntm = core::runtime::Runtime::getDefault();
const auto location = rntm->getWorkingPath() / MODULE_RC_PREFIX;
const auto location = (rntm->getWorkingPath() / MODULE_RC_PREFIX).lexically_normal();
SIGHT_INFO("Launching Sight runtime in: " + location.string());
auto profile = std::make_shared<detail::profile::Profile>();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment