Skip to content

Commit 787c45d

Browse files
Move addSymbolLibraryToSearchLibrariesEnv to utils
1 parent e2891d1 commit 787c45d

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

include/boost_plugin_loader/plugin_loader.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,6 @@ class PluginLoader
129129
*/
130130
inline std::vector<std::string> getAvailableSections(bool include_hidden = false) const;
131131

132-
/**
133-
* @brief Utility function to add library containing symbol to the search env variable
134-
*
135-
* In some cases the name and location of a library is unknown at runtime, but a symbol can
136-
* be linked at compile time. This is true for Python auditwheel distributions. This
137-
* utility function will determine the location of the library, and add it to the library search
138-
* environment variable so it can be found.
139-
*
140-
* @param symbol_ptr Pointer to the symbol to find
141-
* @param search_libraries_env The environmental variable to modify
142-
*/
143-
static inline void addSymbolLibraryToSearchLibrariesEnv(const void* symbol_ptr,
144-
const std::string& search_libraries_env);
145-
146132
/**
147133
* @brief The number of plugins stored. The size of plugins variable
148134
* @return The number of plugins.

include/boost_plugin_loader/plugin_loader.hpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
// Boost
2626
#include <boost/core/demangle.hpp>
2727
#include <boost/dll/import.hpp>
28-
#include <boost/dll/runtime_symbol_info.hpp>
2928
#include <boost/version.hpp>
3029

3130
// Boost Plugin Loader
@@ -276,37 +275,6 @@ std::vector<std::string> PluginLoader::getAvailableSections(bool include_hidden)
276275
return sections;
277276
}
278277

279-
void PluginLoader::addSymbolLibraryToSearchLibrariesEnv(const void* symbol_ptr, const std::string& search_libraries_env)
280-
{
281-
std::string env_var_str;
282-
char* env_var = std::getenv(search_libraries_env.c_str());
283-
if (env_var != nullptr)
284-
{
285-
env_var_str = env_var;
286-
}
287-
288-
const boost::filesystem::path lib_path = boost::filesystem::canonical(boost::dll::symbol_location_ptr(symbol_ptr));
289-
290-
if (env_var_str.empty())
291-
{
292-
env_var_str = lib_path.string();
293-
}
294-
else
295-
{
296-
#ifndef _WIN32
297-
env_var_str = env_var_str + ":" + lib_path.string();
298-
#else
299-
env_var_str = env_var_str + ";" + lib_path.string();
300-
#endif
301-
}
302-
303-
#ifndef _WIN32
304-
setenv(search_libraries_env.c_str(), env_var_str.c_str(), 1);
305-
#else
306-
_putenv_s(search_libraries_env.c_str(), env_var_str.c_str());
307-
#endif
308-
}
309-
310278
int PluginLoader::count() const
311279
{
312280
return static_cast<int>(getAllLibraryNames(search_libraries_env, search_libraries).size());

include/boost_plugin_loader/utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ std::set<std::string> getAllSearchPaths(const std::string& search_paths_env,
103103
std::set<std::string> getAllLibraryNames(const std::string& search_libraries_env,
104104
const std::set<std::string>& existing_search_libraries);
105105

106+
/**
107+
* @brief Utility function to add library containing symbol to the search env variable
108+
* * In some cases the name and location of a library is unknown at runtime, but a symbol can
109+
* be linked at compile time. This is true for Python auditwheel distributions. This
110+
* utility function will determine the location of the library, and add it to the library search
111+
* environment variable so it can be found.
112+
* * @param symbol_ptr Pointer to the symbol to find
113+
* @param search_libraries_env The environmental variable to modify
114+
*/
115+
void addSymbolLibraryToSearchLibrariesEnv(const void* symbol_ptr, const std::string& search_libraries_env);
116+
106117
} // namespace boost_plugin_loader
107118

108119
#endif // BOOST_PLUGIN_LOADER_UTILS_H

src/utils.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
// Boost
2121
#include <boost/dll/library_info.hpp>
22+
#include <boost/dll/runtime_symbol_info.hpp>
2223
#include <boost/dll/shared_library.hpp>
2324
#include <boost/dll/shared_library_load_mode.hpp>
2425
#include <boost/algorithm/string/constants.hpp>
2526
#include <boost/algorithm/string/split.hpp>
2627
#include <boost/algorithm/string/classification.hpp>
2728
#include <boost/filesystem/path.hpp>
29+
#include <boost/filesystem/operations.hpp>
2830
#include <boost/system/error_code.hpp>
2931

3032
// STD
@@ -159,4 +161,35 @@ std::set<std::string> getAllLibraryNames(const std::string& search_libraries_env
159161
return existing_search_libraries;
160162
}
161163

164+
void addSymbolLibraryToSearchLibrariesEnv(const void* symbol_ptr, const std::string& search_libraries_env)
165+
{
166+
std::string env_var_str;
167+
char* env_var = std::getenv(search_libraries_env.c_str());
168+
if (env_var != nullptr)
169+
{
170+
env_var_str = env_var;
171+
}
172+
173+
const boost::filesystem::path lib_path = boost::filesystem::canonical(boost::dll::symbol_location_ptr(symbol_ptr));
174+
175+
if (env_var_str.empty())
176+
{
177+
env_var_str = lib_path.string();
178+
}
179+
else
180+
{
181+
#ifndef _WIN32
182+
env_var_str = env_var_str + ":" + lib_path.string();
183+
#else
184+
env_var_str = env_var_str + ";" + lib_path.string();
185+
#endif
186+
}
187+
188+
#ifndef _WIN32
189+
setenv(search_libraries_env.c_str(), env_var_str.c_str(), 1); // NOLINT(misc-include-cleaner)
190+
#else
191+
_putenv_s(search_libraries_env.c_str(), env_var_str.c_str()); // NOLINT(misc-include-cleaner)
192+
#endif
193+
}
194+
162195
} // namespace boost_plugin_loader

test/plugin_loader_anchor_unit.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
// Boost Plugin Loader
2929
#include <boost_plugin_loader/plugin_loader.h>
3030
#include <boost_plugin_loader/plugin_loader.hpp> // NOLINT(misc-include-cleaner)
31+
#include <boost_plugin_loader/utils.h>
3132
#include "test_plugin_base.h"
3233
#include "test_plugin_multiply.h"
3334

@@ -36,7 +37,8 @@ TEST(BoostPluginLoaderAnchorUnit, LoadTestPlugin) // NOLINT
3637
using boost_plugin_loader::PluginLoader;
3738
using boost_plugin_loader::TestPluginBase;
3839

39-
PluginLoader::addSymbolLibraryToSearchLibrariesEnv(boost_plugin_loader::TestPluginMultiplyAnchor(), "UNITTESTENV");
40+
boost_plugin_loader::addSymbolLibraryToSearchLibrariesEnv(boost_plugin_loader::TestPluginMultiplyAnchor(), "UNITTESTE"
41+
"NV");
4042
PluginLoader plugin_loader;
4143
plugin_loader.search_libraries_env = "UNITTESTENV";
4244

0 commit comments

Comments
 (0)