From 91cb9e0642ad3e64360d7259f8c53c5e21930ef8 Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Wed, 10 Jul 2024 18:10:37 +0200 Subject: [PATCH 01/10] Homogenize finding our components. We currently rely on two files being present in pre-defined directories: * nrnunits.lib * libpywrapper.so (or similar) These are searched for in: * CMake's binary directory for NMODL * CMake's install directory for NMODL * The environment variable `NMODLHOME` Leading to some acrobatics to always set NMODLHOME correctly. This PR attempts to also find the above files relative to the NMODL executable, in the hope that some use cases of NMODLHOME can be removed. --- src/config/config.cpp.in | 68 ++++++++++++++++++++++++++++++++++--- src/config/config.h | 67 ++++++++++++++++++++---------------- src/main.cpp | 4 ++- src/parser/main_units.cpp | 2 +- src/pybind/pyembed.cpp | 12 ++----- src/visitors/main.cpp | 2 +- test/unit/units/parser.cpp | 2 +- test/unit/visitor/units.cpp | 2 +- 8 files changed, 111 insertions(+), 48 deletions(-) diff --git a/src/config/config.cpp.in b/src/config/config.cpp.in index 09a4da97c7..3ea8792b20 100644 --- a/src/config/config.cpp.in +++ b/src/config/config.cpp.in @@ -7,14 +7,19 @@ #include "config/config.h" +#include +#include +#include +#include + +namespace fs = std::filesystem; + /// Git version of the project const std::string nmodl::Version::GIT_REVISION = "@NMODL_GIT_REVISION@"; /// NMODL version const std::string nmodl::Version::NMODL_VERSION = "@PROJECT_VERSION@"; -const std::string nmodl::CMakeInfo::SHARED_LIBRARY_SUFFIX = "@CMAKE_SHARED_LIBRARY_SUFFIX@"; - /** * \brief Path of nrnutils.lib file * @@ -23,5 +28,60 @@ const std::string nmodl::CMakeInfo::SHARED_LIBRARY_SUFFIX = "@CMAKE_SHARED_LIBRA * from CMAKE_INSTALL_PREFIX. Note that this use of NMODL_PROJECT_BINARY_DIR * will cause ccache misses when the build prefix is changed. */ -std::vector nmodl::NrnUnitsLib::NRNUNITSLIB_PATH = - {"@CMAKE_INSTALL_PREFIX@/share/nmodl/nrnunits.lib", "@NMODL_PROJECT_BINARY_DIR@/share/nmodl/nrnunits.lib"}; +const std::vector nmodl::PathHelper::BASE_SEARCH_PATHS = + {"@CMAKE_INSTALL_PREFIX@", "@NMODL_PROJECT_BINARY_DIR@"}; + +const std::string nmodl::PathHelper::SHARED_LIBRARY_SUFFIX = "@CMAKE_SHARED_LIBRARY_SUFFIX@"; + +namespace { + +std::string maybe_from_env(const std::string& varname) { + const auto value = std::getenv(varname.c_str()); + if (value != nullptr) { + return value; + } + return ""; +} + +} + +std::string nmodl::PathHelper::nmodl_home = maybe_from_env("NMODL_HOME"); + +std::string nmodl::PathHelper::get_path(const std::string& what, bool add_library_suffix) { + std::vector search_paths = BASE_SEARCH_PATHS; + if (!get_home().empty()) { + search_paths.emplace(search_paths.begin(), get_home()); + } + + // check paths in order and return if found + for (const auto& path: search_paths) { + auto full_path = fs::path(path) / fs::path(what); + if (add_library_suffix) { + full_path += SHARED_LIBRARY_SUFFIX; + } + std::ifstream f(full_path); + if (f.good()) { + return full_path; + } + } + std::ostringstream err_msg; + err_msg << "Could not find '" << what << "' in any of:\n"; + for (const auto& path: search_paths) { + err_msg << "\t" << path << "\n"; + } + err_msg << "Please try setting the NMODLHOME environment variable\n"; + throw std::runtime_error(err_msg.str()); +} + +void nmodl::PathHelper::setup(const std::string& executable) { + // We give precedence to NMODLHOME - don't override if the home is already defined + if (nmodl_home.empty()) { + auto executable_dir = fs::canonical(fs::path(executable)).parent_path(); + if (executable_dir.filename() == "bin") { + nmodl_home = executable_dir.parent_path(); + } else { + // On Windows, we may find ourselves in the top-level directory without a bin/ + nmodl_home = executable_dir; + } + } +} diff --git a/src/config/config.h b/src/config/config.h index df5d7d379a..30de49da52 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -15,9 +15,6 @@ * \brief Version information and units file path */ -#include -#include -#include #include #include @@ -44,38 +41,48 @@ struct Version { /** * \brief Information of units database i.e. `nrnunits.lib` */ -struct NrnUnitsLib { - /// paths where nrnunits.lib can be found - static std::vector NRNUNITSLIB_PATH; +class PathHelper { + /// pre-defined paths to search for files + const static std::vector BASE_SEARCH_PATHS; + + /// suffix to use when looking for libraries + const static std::string SHARED_LIBRARY_SUFFIX; + + /// base directory of the NMODL installation + static std::string nmodl_home; /** - * Return path of units database file + * Search for a given relative file path + */ + static std::string get_path(const std::string& what, bool add_library_suffix=false); + + public: + /** + * Set the NMODL base installation directory from the executable if not defined in the + * environment + */ + static void setup(const std::string& executable); + + /** + * Return the NMODL base installation directory */ - static std::string get_path() { - // first look for NMODLHOME env variable - if (const char* nmodl_home = std::getenv("NMODLHOME")) { - auto path = std::string(nmodl_home) + "/share/nmodl/nrnunits.lib"; - NRNUNITSLIB_PATH.emplace(NRNUNITSLIB_PATH.begin(), path); - } - - // check paths in order and return if found - for (const auto& path: NRNUNITSLIB_PATH) { - std::ifstream f(path.c_str()); - if (f.good()) { - return path; - } - } - std::ostringstream err_msg; - err_msg << "Could not find nrnunits.lib in any of:\n"; - for (const auto& path: NRNUNITSLIB_PATH) { - err_msg << path << "\n"; - } - throw std::runtime_error(err_msg.str()); + static std::string get_home() { + return nmodl_home; } -}; -struct CMakeInfo { - static const std::string SHARED_LIBRARY_SUFFIX; + /** + * Return path of units database file + */ + static std::string get_units_path() { + return get_path("share/nmodl/nrnunits.lib"); + }; + + /** + * Return path of the python wrapper library + */ + static std::string get_wrapper_path() { + return get_path("lib/libpywrapper", true); + }; }; } // namespace nmodl diff --git a/src/main.cpp b/src/main.cpp index be322c0e99..8a5a06106e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,6 +62,8 @@ using nmodl::parser::NmodlDriver; // NOLINTNEXTLINE(readability-function-cognitive-complexity) int main(int argc, const char* argv[]) { + PathHelper::setup(argv[0]); + CLI::App app{fmt::format("NMODL : Source-to-Source Code Generation Framework [{}]", Version::to_string())}; @@ -142,7 +144,7 @@ int main(int argc, const char* argv[]) { std::string scratch_dir("tmp"); /// directory where units lib file is located - std::string units_dir(NrnUnitsLib::get_path()); + std::string units_dir(PathHelper::get_units_path()); /// true if ast should be converted to json bool json_ast(false); diff --git a/src/parser/main_units.cpp b/src/parser/main_units.cpp index 6c6966aae0..95ce6946ff 100644 --- a/src/parser/main_units.cpp +++ b/src/parser/main_units.cpp @@ -28,7 +28,7 @@ int main(int argc, const char* argv[]) { fmt::format("Unit-Parser : Standalone Parser for Units({})", Version::to_string())}; std::vector units_files; - units_files.push_back(NrnUnitsLib::get_path()); + units_files.push_back(PathHelper::get_units_path()); app.add_option("units_files", units_files, "One or more Units files to process"); CLI11_PARSE(app, argc, argv); diff --git a/src/pybind/pyembed.cpp b/src/pybind/pyembed.cpp index 7e4bfb8dcc..83d557e353 100644 --- a/src/pybind/pyembed.cpp +++ b/src/pybind/pyembed.cpp @@ -81,21 +81,15 @@ void EmbeddedPythonLoader::load_libraries() { assert_compatible_python_versions(); - if (std::getenv("NMODLHOME") == nullptr) { + if (PathHelper::get_home().empty()) { logger->critical("NMODLHOME environment variable must be set to load embedded python"); throw std::runtime_error("NMODLHOME not set"); } - auto pybind_wraplib_env = fs::path(std::getenv("NMODLHOME")) / "lib" / "libpywrapper"; - pybind_wraplib_env.concat(CMakeInfo::SHARED_LIBRARY_SUFFIX); - if (!fs::exists(pybind_wraplib_env)) { - logger->critical("NMODLHOME doesn't contain libpywrapper{} library", - CMakeInfo::SHARED_LIBRARY_SUFFIX); - throw std::runtime_error("NMODLHOME doesn't have lib/libpywrapper library"); - } + auto pybind_wraplib_env = PathHelper::get_wrapper_path(); pybind_wrapper_handle = dlopen(pybind_wraplib_env.c_str(), dlopen_opts); if (!pybind_wrapper_handle) { const auto errstr = dlerror(); - logger->critical("Tried but failed to load {}", pybind_wraplib_env.string()); + logger->critical("Tried but failed to load {}", pybind_wraplib_env); logger->critical(errstr); throw std::runtime_error("Failed to dlopen"); } diff --git a/src/visitors/main.cpp b/src/visitors/main.cpp index 9a6b969663..0653f866e4 100644 --- a/src/visitors/main.cpp +++ b/src/visitors/main.cpp @@ -95,7 +95,7 @@ int main(int argc, const char* argv[]) { "SympyConductanceVisitor"}, {std::make_shared(), "sympy-solve", "SympySolverVisitor"}, {std::make_shared(), "neuron-solve", "NeuronSolveVisitor"}, - {std::make_shared(NrnUnitsLib::get_path()), "units", "UnitsVisitor"}, + {std::make_shared(PathHelper::get_units_path()), "units", "UnitsVisitor"}, }; const std::vector const_visitors = { diff --git a/test/unit/units/parser.cpp b/test/unit/units/parser.cpp index 3ffd3497e1..9d17d94e44 100644 --- a/test/unit/units/parser.cpp +++ b/test/unit/units/parser.cpp @@ -33,7 +33,7 @@ bool is_valid_construct(const std::string& construct) { std::string parse_string(const std::string& unit_definition) { nmodl::parser::UnitDriver correctness_driver; - correctness_driver.parse_file(nmodl::NrnUnitsLib::get_path()); + correctness_driver.parse_file(nmodl::PathHelper::get_units_path()); correctness_driver.parse_string(unit_definition); std::stringstream ss; correctness_driver.table->print_units_sorted(ss); diff --git a/test/unit/visitor/units.cpp b/test/unit/visitor/units.cpp index 06f3865cd8..4bfcdc5544 100644 --- a/test/unit/visitor/units.cpp +++ b/test/unit/visitor/units.cpp @@ -36,7 +36,7 @@ std::tuple, std::shared_ptr> run const auto& ast = driver.get_ast(); // Parse nrnunits.lib file and the UNITS block of the mod file - const std::string units_lib_path(NrnUnitsLib::get_path()); + const std::string units_lib_path(PathHelper::get_units_path()); UnitsVisitor units_visitor = UnitsVisitor(units_lib_path); units_visitor.visit_program(*ast); From c6dbd202cffe38a9f694b922de160263dcd5bf08 Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Wed, 10 Jul 2024 18:17:49 +0200 Subject: [PATCH 02/10] =?UTF-8?q?=E2=9D=84=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/config.h b/src/config/config.h index 30de49da52..53c7257af6 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -54,7 +54,7 @@ class PathHelper { /** * Search for a given relative file path */ - static std::string get_path(const std::string& what, bool add_library_suffix=false); + static std::string get_path(const std::string& what, bool add_library_suffix = false); public: /** From 3fafed83348546a631748bfe24dbc5a82420f234 Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Wed, 10 Jul 2024 18:23:42 +0200 Subject: [PATCH 03/10] Shrink API. --- src/config/config.cpp.in | 4 ++-- src/config/config.h | 7 ------- src/pybind/pyembed.cpp | 4 ---- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/config/config.cpp.in b/src/config/config.cpp.in index 3ea8792b20..b765e8823a 100644 --- a/src/config/config.cpp.in +++ b/src/config/config.cpp.in @@ -49,8 +49,8 @@ std::string nmodl::PathHelper::nmodl_home = maybe_from_env("NMODL_HOME"); std::string nmodl::PathHelper::get_path(const std::string& what, bool add_library_suffix) { std::vector search_paths = BASE_SEARCH_PATHS; - if (!get_home().empty()) { - search_paths.emplace(search_paths.begin(), get_home()); + if (!nmodl_home.empty()) { + search_paths.emplace(search_paths.begin(), nmodl_home); } // check paths in order and return if found diff --git a/src/config/config.h b/src/config/config.h index 53c7257af6..14d896ca26 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -63,13 +63,6 @@ class PathHelper { */ static void setup(const std::string& executable); - /** - * Return the NMODL base installation directory - */ - static std::string get_home() { - return nmodl_home; - } - /** * Return path of units database file */ diff --git a/src/pybind/pyembed.cpp b/src/pybind/pyembed.cpp index 83d557e353..1c38813d88 100644 --- a/src/pybind/pyembed.cpp +++ b/src/pybind/pyembed.cpp @@ -81,10 +81,6 @@ void EmbeddedPythonLoader::load_libraries() { assert_compatible_python_versions(); - if (PathHelper::get_home().empty()) { - logger->critical("NMODLHOME environment variable must be set to load embedded python"); - throw std::runtime_error("NMODLHOME not set"); - } auto pybind_wraplib_env = PathHelper::get_wrapper_path(); pybind_wrapper_handle = dlopen(pybind_wraplib_env.c_str(), dlopen_opts); if (!pybind_wrapper_handle) { From 6441841c843f867c0469ad0cb9aa9174e75a9c1f Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Thu, 11 Jul 2024 11:28:34 +0200 Subject: [PATCH 04/10] Attempt to be more ARGV independent. --- src/config/config.cpp.in | 56 ++++++++++++++++++++++++++++------------ src/config/config.h | 8 +----- src/main.cpp | 2 -- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/config/config.cpp.in b/src/config/config.cpp.in index b765e8823a..7d4d062905 100644 --- a/src/config/config.cpp.in +++ b/src/config/config.cpp.in @@ -12,6 +12,14 @@ #include #include +#if defined(_WIN32) +#include +#elif defined(__APPLE__) +#include +#include +#else +#endif + namespace fs = std::filesystem; /// Git version of the project @@ -40,17 +48,44 @@ std::string maybe_from_env(const std::string& varname) { if (value != nullptr) { return value; } - return ""; + +#if defined(_WIN32) + std::vector buffer; + DWORD copied = 0; + do { + buffer.resize(buffer.size() + MAX_PATH); + copied = GetModuleFileName(0, &buffer.at(0), buffer.size()); + } while (copied >= buffer.size()); + buffer.resize(copied); + fs::path executable(std::wstring(buffer.begin(), buffer.end())); +#elif defined(__APPLE__) + char buffer[PATH_MAX + 1]; + uint32_t bufsize = PATH_MAX + 1; + if( _NSGetExecutablePath(buf, &bufsize) != 0) { + return ""; + } + auto executable = fs::read_symlink(buffer); +#else + auto executable = fs::read_symlink("/proc/self/exe"); +#endif + + auto executable_dir = fs::weakly_canonical(executable).parent_path(); + if (executable_dir.filename() == "bin") { + return executable_dir.parent_path(); + } else { + // On Windows, we may find ourselves in the top-level directory without a bin/ + return executable_dir; + } } } -std::string nmodl::PathHelper::nmodl_home = maybe_from_env("NMODL_HOME"); +const std::string nmodl::PathHelper::NMODL_HOME = maybe_from_env("NMODL_HOME"); std::string nmodl::PathHelper::get_path(const std::string& what, bool add_library_suffix) { std::vector search_paths = BASE_SEARCH_PATHS; - if (!nmodl_home.empty()) { - search_paths.emplace(search_paths.begin(), nmodl_home); + if (!NMODL_HOME.empty()) { + search_paths.emplace(search_paths.begin(), NMODL_HOME); } // check paths in order and return if found @@ -72,16 +107,3 @@ std::string nmodl::PathHelper::get_path(const std::string& what, bool add_librar err_msg << "Please try setting the NMODLHOME environment variable\n"; throw std::runtime_error(err_msg.str()); } - -void nmodl::PathHelper::setup(const std::string& executable) { - // We give precedence to NMODLHOME - don't override if the home is already defined - if (nmodl_home.empty()) { - auto executable_dir = fs::canonical(fs::path(executable)).parent_path(); - if (executable_dir.filename() == "bin") { - nmodl_home = executable_dir.parent_path(); - } else { - // On Windows, we may find ourselves in the top-level directory without a bin/ - nmodl_home = executable_dir; - } - } -} diff --git a/src/config/config.h b/src/config/config.h index 14d896ca26..b26f698671 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -49,7 +49,7 @@ class PathHelper { const static std::string SHARED_LIBRARY_SUFFIX; /// base directory of the NMODL installation - static std::string nmodl_home; + const static std::string NMODL_HOME; /** * Search for a given relative file path @@ -57,12 +57,6 @@ class PathHelper { static std::string get_path(const std::string& what, bool add_library_suffix = false); public: - /** - * Set the NMODL base installation directory from the executable if not defined in the - * environment - */ - static void setup(const std::string& executable); - /** * Return path of units database file */ diff --git a/src/main.cpp b/src/main.cpp index 8a5a06106e..891476389e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,8 +62,6 @@ using nmodl::parser::NmodlDriver; // NOLINTNEXTLINE(readability-function-cognitive-complexity) int main(int argc, const char* argv[]) { - PathHelper::setup(argv[0]); - CLI::App app{fmt::format("NMODL : Source-to-Source Code Generation Framework [{}]", Version::to_string())}; From 9499115b3235e62f3a5a815f150b737b1f4a59bc Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Thu, 11 Jul 2024 11:48:38 +0200 Subject: [PATCH 05/10] Fixeth for the AppleOS --- src/config/config.cpp.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/config.cpp.in b/src/config/config.cpp.in index 7d4d062905..6dd69f0537 100644 --- a/src/config/config.cpp.in +++ b/src/config/config.cpp.in @@ -61,7 +61,7 @@ std::string maybe_from_env(const std::string& varname) { #elif defined(__APPLE__) char buffer[PATH_MAX + 1]; uint32_t bufsize = PATH_MAX + 1; - if( _NSGetExecutablePath(buf, &bufsize) != 0) { + if( _NSGetExecutablePath(buffer, &bufsize) != 0) { return ""; } auto executable = fs::read_symlink(buffer); From f4863e4a04be462cf42b5bb0db3fb8f8e811bc63 Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Thu, 11 Jul 2024 13:06:21 +0200 Subject: [PATCH 06/10] More AppleOS fixes. --- src/config/config.cpp.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/config.cpp.in b/src/config/config.cpp.in index 6dd69f0537..fe1a96d3fe 100644 --- a/src/config/config.cpp.in +++ b/src/config/config.cpp.in @@ -64,7 +64,7 @@ std::string maybe_from_env(const std::string& varname) { if( _NSGetExecutablePath(buffer, &bufsize) != 0) { return ""; } - auto executable = fs::read_symlink(buffer); + auto executable = fs::path(buffer); #else auto executable = fs::read_symlink("/proc/self/exe"); #endif From c765a3a1e575827556dbae0b7c7f7c0c97b49864 Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Fri, 12 Jul 2024 15:54:54 +0200 Subject: [PATCH 07/10] Fix Windows after local reproducer. --- src/config/config.cpp.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/config.cpp.in b/src/config/config.cpp.in index fe1a96d3fe..77180f30d6 100644 --- a/src/config/config.cpp.in +++ b/src/config/config.cpp.in @@ -13,7 +13,7 @@ #include #if defined(_WIN32) -#include +#include #elif defined(__APPLE__) #include #include @@ -50,7 +50,7 @@ std::string maybe_from_env(const std::string& varname) { } #if defined(_WIN32) - std::vector buffer; + std::vector buffer; DWORD copied = 0; do { buffer.resize(buffer.size() + MAX_PATH); From fab9a4ae55aafe6010550808730cde2207ee508c Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Tue, 23 Jul 2024 10:06:33 +0200 Subject: [PATCH 08/10] Fix merge. --- src/pybind/pyembed.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pybind/pyembed.cpp b/src/pybind/pyembed.cpp index 001e72b93d..1c38813d88 100644 --- a/src/pybind/pyembed.cpp +++ b/src/pybind/pyembed.cpp @@ -82,8 +82,7 @@ void EmbeddedPythonLoader::load_libraries() { assert_compatible_python_versions(); auto pybind_wraplib_env = PathHelper::get_wrapper_path(); - std::string env_str = pybind_wraplib_env.string(); - pybind_wrapper_handle = dlopen(env_str.c_str(), dlopen_opts); + pybind_wrapper_handle = dlopen(pybind_wraplib_env.c_str(), dlopen_opts); if (!pybind_wrapper_handle) { const auto errstr = dlerror(); logger->critical("Tried but failed to load {}", pybind_wraplib_env); From 0200e0f1105cc118d99f0890ce5d2e17f33f429b Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Tue, 23 Jul 2024 11:58:22 +0200 Subject: [PATCH 09/10] Explicit conversion to string. --- src/config/config.cpp.in | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/config/config.cpp.in b/src/config/config.cpp.in index 77180f30d6..d0eee8b093 100644 --- a/src/config/config.cpp.in +++ b/src/config/config.cpp.in @@ -39,6 +39,7 @@ const std::string nmodl::Version::NMODL_VERSION = "@PROJECT_VERSION@"; const std::vector nmodl::PathHelper::BASE_SEARCH_PATHS = {"@CMAKE_INSTALL_PREFIX@", "@NMODL_PROJECT_BINARY_DIR@"}; +const std::string nmodl::PathHelper::SHARED_LIBRARY_PREFIX = "@CMAKE_SHARED_LIBRARY_PREFIX@"; const std::string nmodl::PathHelper::SHARED_LIBRARY_SUFFIX = "@CMAKE_SHARED_LIBRARY_SUFFIX@"; namespace { @@ -71,10 +72,10 @@ std::string maybe_from_env(const std::string& varname) { auto executable_dir = fs::weakly_canonical(executable).parent_path(); if (executable_dir.filename() == "bin") { - return executable_dir.parent_path(); + return executable_dir.parent_path().string(); } else { // On Windows, we may find ourselves in the top-level directory without a bin/ - return executable_dir; + return executable_dir.string(); } } @@ -82,7 +83,7 @@ std::string maybe_from_env(const std::string& varname) { const std::string nmodl::PathHelper::NMODL_HOME = maybe_from_env("NMODL_HOME"); -std::string nmodl::PathHelper::get_path(const std::string& what, bool add_library_suffix) { +std::string nmodl::PathHelper::get_path(const std::string& what, bool is_library) { std::vector search_paths = BASE_SEARCH_PATHS; if (!NMODL_HOME.empty()) { search_paths.emplace(search_paths.begin(), NMODL_HOME); @@ -90,9 +91,11 @@ std::string nmodl::PathHelper::get_path(const std::string& what, bool add_librar // check paths in order and return if found for (const auto& path: search_paths) { - auto full_path = fs::path(path) / fs::path(what); - if (add_library_suffix) { - full_path += SHARED_LIBRARY_SUFFIX; + auto full_path = fs::path(path); + if (is_library) { + full_path /= SHARED_LIBRARY_PREFIX + what + SHARED_LIBRARY_SUFFIX; + } else { + full_path /= what; } std::ifstream f(full_path); if (f.good()) { From 62a5a497577e3af480c4ae5f81a4739bf0c7cf0c Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Tue, 23 Jul 2024 14:07:18 +0200 Subject: [PATCH 10/10] Forgotten header modifications. --- src/config/config.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config/config.h b/src/config/config.h index b26f698671..40310adc83 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -45,6 +45,9 @@ class PathHelper { /// pre-defined paths to search for files const static std::vector BASE_SEARCH_PATHS; + /// prefix to use when looking for libraries + const static std::string SHARED_LIBRARY_PREFIX; + /// suffix to use when looking for libraries const static std::string SHARED_LIBRARY_SUFFIX; @@ -54,7 +57,7 @@ class PathHelper { /** * Search for a given relative file path */ - static std::string get_path(const std::string& what, bool add_library_suffix = false); + static std::string get_path(const std::string& what, bool is_library = false); public: /**