25 #define GAUDI_PLUGIN_SERVICE_V2
29 void help( std::string argv0 ) {
30 std::cout <<
"Usage: " << argv0
31 <<
" [option] library1 [library2 ...]\n"
32 "\n list the component factories present in the given libraries\n\n"
34 " -h, --help show this help message and exit\n"
35 " -o OUTPUT, --output OUTPUT\n"
36 " write the list of factories on the file OUTPUT, use - for\n"
37 " standard output (default)\n"
41 void usage( std::string argv0 ) {
42 std::cout <<
"Usage: " << argv0
43 <<
" [option] library1 [library2 ...]\n"
45 << argv0 <<
" -h' for more information.\n"
49 int main(
int argc,
char* argv[] ) {
50 auto& reg2 = Gaudi::PluginService::v2::Details::Registry::instance();
53 using key_type = Gaudi::PluginService::v2::Details::Registry::KeyType;
56 std::map<key_type, std::string> loaded;
58 for (
const auto& name : reg2.loadedFactoryNames() ) loaded.emplace( name,
"<preloaded>" );
59 for (
const auto& name : reg1.loadedFactoryNames() ) loaded.emplace( name,
"<preloaded>" );
62 std::list<char*> libs;
63 std::string output_opt(
"-" );
65 std::string argv0( argv[0] );
67 auto i = argv0.rfind(
'/' );
68 if ( i != std::string::npos ) argv0 = argv0.substr( i + 1 );
73 const std::string arg( argv[i] );
74 if ( arg ==
"-o" || arg ==
"--output" ) {
78 std::cerr <<
"ERROR: missing argument for option " << arg << std::endl;
79 std::cerr <<
"See `" << argv0 <<
" -h' for more details." << std::endl;
82 }
else if ( arg ==
"-h" || arg ==
"--help" ) {
86 libs.push_back( argv[i] );
91 usage( std::move(argv0) );
97 std::unique_ptr<std::ostream> output_file;
98 if ( output_opt !=
"-" ) { output_file.reset(
new std::ofstream{output_opt} ); }
99 std::ostream& output = ( output_file ? *output_file : std::cout );
101 auto dump_from = [&output, &loaded](
auto& reg,
const char* lib,
const char* prefix ) {
102 for (
const auto& factoryName : reg.loadedFactoryNames() ) {
103 auto f = loaded.find( factoryName );
104 if ( f == loaded.end() ) {
105 output << prefix <<
"::" << lib <<
":" << factoryName << std::endl;
106 loaded.emplace( factoryName, lib );
108 std::cerr <<
"WARNING: factory '" << factoryName <<
"' already found in " << f->second << std::endl;
113 for (
const char* aLib : libs ) {
114 if ( dlopen( aLib, RTLD_LAZY | RTLD_LOCAL ) ) {
115 dump_from( reg2, aLib,
"v2" );
116 dump_from( reg1, aLib,
"v1" );
118 std::cerr <<
"ERROR: failed to load " << aLib <<
": " << dlerror() << std::endl;