3 #include "boost/filesystem.hpp" 4 #include "boost/regex.hpp" 10 #include "cetlib_except/demangle.h" 11 #include "cetlib_except/exception.h" 23 std::string const default_pattern_stem{
"(?:[A-Za-z0-9\\-]*_)*[A-Za-z0-9]+_"};
48 std::vector<std::string>
matches;
55 std::for_each(matches.rbegin(), matches.rend(), [
this](
auto const& match) {
98 std::pair<std::string, std::string>
102 std::pair<std::string, std::string>
result;
104 auto const& spec = maybe_trim_shlib_prefix(
entry.
first);
105 auto const& paths =
entry.second;
107 auto const path_iter = paths.
find(lib_loc);
108 if (path_iter != paths.end()) {
109 if (spec.find(
"/") != std::string::npos)
110 result.second = spec;
114 if (!result.first.empty() && !result.second.empty())
127 <<
"Unable to load requested library " << lib.second <<
"\n" 128 << demangle_message(dlerror()) <<
"\n";
145 if (path == lib.second) {
155 lib_loc_map_[boost::filesystem::path(path).filename().native()] = path;
160 lib_loc_map_t::value_type
const&
entry)
164 boost::match_results<std::string::const_iterator> match_results;
165 if (boost::regex_search(entry.first, match_results,
e)) {
169 <<
"Internal error in spec_trans_map_inserter for entry " << entry.first
170 <<
" with pattern " <<
e.str();
173 std::ostringstream lib_name;
174 std::ostream_iterator<char, char> oi{lib_name};
175 boost::regex_replace(oi,
178 boost::regex{
"(_+)"},
180 boost::match_default | boost::format_all);
181 boost::regex
const stripper{
"^lib(.*)/" +
lib_type_ +
"\\..*$"};
183 if (boost::regex_search(lib_name_str, match_results, stripper)) {
187 <<
"Internal error in spec_trans_map_inserter stripping " 194 spec_trans_map_t::value_type
const&
entry)
196 if (entry.second.size() == 1) {
205 if (it ==
lib_ptr_map_.cend() || it->second ==
nullptr) {
207 void* ptr = dlopen(lib_loc.c_str(), RTLD_LAZY | RTLD_GLOBAL);
217 bool should_throw_on_dlsym)
const 219 if (libspec.find(
"_") != std::string::npos) {
221 throw exception(
"LogicError",
"IllegalUnderscore.")
222 <<
"Library specification \"" << libspec
223 <<
"\" contains an illegal underscore.\n" 224 <<
"The class name and path to it may not contain an underscore. " 225 <<
"If this is a configuration error, plase correct it; " 226 <<
"if the module's class name or its location within its " 227 <<
"enclosing package really do have an underscore this situation " 228 <<
"must be rectified.\n";
233 std::ostringstream error_msg;
234 error_msg <<
"Library specification \"" << libspec <<
"\"";
237 error_msg <<
" corresponds to multiple libraries:\n";
239 std::ostream_iterator<std::string>(error_msg,
"\n"));
242 error_msg <<
" does not correspond to any library";
243 if (!path_name.empty()) {
244 error_msg <<
" in " << path_name;
246 error_msg <<
" of type \"" <<
lib_type_ <<
"\"\n";
248 throw exception(
"Configuration") << error_msg.str();
256 bool should_throw_on_dlsym)
const 260 if (lib_ptr ==
nullptr) {
262 <<
"Unable to load requested library " << lib_loc <<
"\n" 263 << demangle_message(dlerror()) <<
"\n";
266 result = dlsym(lib_ptr, sym_name.c_str());
267 char const*
error = dlerror();
268 if (error !=
nullptr) {
270 if (should_throw_on_dlsym) {
272 <<
"Unable to load requested symbol " << demangle_symbol(sym_name)
273 <<
" from library " << lib_loc <<
"\n" 274 << demangle_message(error) <<
"\n";
void spec_trans_map_inserter(lib_loc_map_t::value_type const &entry)
size_t getLoadedLibraries(std::vector< std::string > &list) const
size_t getValidLibspecs(std::vector< std::string > &list) const
void * getSymbolByLibspec_(std::string const &libspec, std::string const &sym_name, bool should_throw_on_dlsym=true) const
bool libraryIsLoadable(std::string const &path) const
std::string const & showenv() const
void * getSymbolByPath_(std::string const &lib_loc, std::string const &sym_name, bool should_throw_on_dlsym=true) const
void lib_loc_map_inserter(std::string const &path)
LibraryManager(cet::search_path search_path, std::string lib_type)
cet::search_path const search_path_
int find(const type *d) const
std::string const pattern_stem_
std::string shlib_prefix()
QCollection::Item first()
constexpr char const * plugin_libpath()
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
static std::string dllExtPattern()
spec_trans_map_t spec_trans_map_
std::pair< std::string, std::string > getSpecsByPath(std::string const &lib_loc) const
good_spec_trans_map_t good_spec_trans_map_
std::size_t find_files(std::string const &filename_pattern, std::vector< std::string > &result) const
size_t getLoadableLibraries(std::vector< std::string > &list) const
void loadAllLibraries() const
void good_spec_trans_map_inserter(spec_trans_map_t::value_type const &entry)
bool libraryIsLoaded(std::string const &path) const
lib_ptr_map_t lib_ptr_map_
auto copy_all(FwdCont &, FwdIter)
search_path plugin_search_path()
void * get_lib_ptr(std::string const &lib_loc) const
std::string const lib_type_
lib_loc_map_t lib_loc_map_
cet::coded_exception< error, detail::translate > exception