1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
// @(#)root/reflex:$Id: Class.cxx 20883 2007-11-19 11:52:08Z rdm $
// Include files----------------------------------------------------------------
#include "Reflex/Reflex.h"
#include "Reflex/PluginService.h"
#include "Reflex/SharedLibrary.h"
#include "../dir_manip.h"
#include <cstdlib>
#include <set>
#include <ctime>
#include <cerrno>
#include <fstream>
#include <iostream>
#include <exception>
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
using namespace std;
using namespace ROOT::Reflex;
class mapGenerator {
fstream m_out;
string m_lib;
public:
mapGenerator(const string& file, const string& lib):
m_out(file.c_str(), std::ios_base::out | std::ios_base::trunc),
m_lib(lib) {}
bool
good() const { return m_out.good(); }
void genHeader();
void genFactory(const string& name,
const string& type);
void genTrailer();
};
static string
currpath(string lib) {
char buff[PATH_MAX];
if (!::getcwd(buff, sizeof(buff))) {
// coverity[secure_coding] - PATH_MAX is > 2
strcpy(buff, ".");
}
string tmp = buff;
tmp += "/" + lib;
return tmp;
}
static int
help(const char* cmd) {
cout << cmd << ": Allowed options" << endl
<< " -help produce this help message" << endl
<< " -debug increase verbosity level" << endl
<< " -input-library library to extract the plugins" << endl
<< " -output-file output file. default <input-library>.rootmap" << endl;
return 1;
}
//--- Command main program------------------------------------------------------
int
main(int argc,
char** argv) {
struct stat buf;
bool deb = false;
string rootmap, lib, err, out;
string::size_type idx;
for (int i = 1; i < argc; ++i) {
const char* opt = argv[i], * val = 0;
if (*opt == '/' || *opt == '-') {
if (*++opt == '/' || *opt == '-') {
++opt;
}
val = (opt[1] != '=') ? ++i < argc ? argv[i] : 0 : opt + 2;
switch (::toupper(opt[0])) {
case 'D':
deb = true;
--i;
break;
case 'I':
lib = val;
break;
case 'O':
rootmap = val;
break;
default:
return help(argv[0]);
}
}
}
if (lib.empty()) {
cout << "ERROR occurred: input library required" << endl;
return help(argv[0]);
}
if (rootmap.empty()) {
string flib = lib;
while ((idx = flib.find("\\")) != string::npos)
flib.replace(idx, 1, "/");
#ifdef _WIN32
if (flib[1] != ':' && flib[0] != '/') {
#else
if (!(flib[0] == '/' || flib.find('/') != string::npos)) {
#endif
flib = currpath(flib);
}
rootmap = ::dirnameEx(flib);
rootmap += "/";
string tmp = ::basenameEx(lib);
if (tmp.rfind('.') == std::string::npos) {
rootmap += tmp + ".rootmap";
} else if (tmp.find("/") != std::string::npos && tmp.rfind(".") < tmp.rfind("/")) {
rootmap += tmp + ".rootmap";
} else {
rootmap += tmp.substr(0, tmp.rfind('.')) + ".rootmap";
}
}
if (deb) {
cout << "Input Library: '" << lib << "'" << endl;
cout << "ROOT Map file: '" << rootmap << "'" << endl;
}
if (::stat(rootmap.c_str(), &buf) == -1 && errno == ENOENT) {
string dir = ::dirnameEx(rootmap);
if (deb) {
cout << "Output directory:" << dir << "'" << endl;
}
if (!dir.empty()) {
if (::mkdir(dir.c_str(), S_IRWXU | S_IRGRP | S_IROTH) != 0 && errno != EEXIST) {
cout << "ERR0R: error creating directory: '" << dir << "'" << endl;
return 1;
}
}
}
out = rootmap;
//--- Load the library -------------------------------------------------
SharedLibrary sl(lib);
if (!sl.Load()) {
cout << "ERR0R: error loading library: '" << lib << "'" << endl
<< sl.Error() << endl;
return 1;
}
mapGenerator map_gen(rootmap.c_str(), lib);
if (!map_gen.good()) {
cout << "ERR0R: cannot open output file: '" << rootmap << "'" << endl
<< sl.Error() << endl;
return 1;
}
//--- Iterate over component factories ---------------------------------------
Scope factories = Scope::ByName(PLUGINSVC_FACTORY_NS);
if (factories) {
map_gen.genHeader();
set<string> used_names;
try {
for (Member_Iterator it = factories.FunctionMember_Begin();
it != factories.FunctionMember_End(); ++it) {
//string cname = it->Properties().PropertyAsString("name");
string cname = it->Name();
if (used_names.insert(cname).second) {
map_gen.genFactory(cname, "");
}
}
map_gen.genTrailer();
return 0;
}
catch (std::exception& e) {
cerr << "GENMAP: error creating map " << rootmap << ": "
<< e.what() << endl;
}
return 1;
}
cout << "library does not contain plugin factories" << endl;
return 0;
} // main
//------------------------------------------------------------------------------
void
mapGenerator::genHeader() {
//------------------------------------------------------------------------------
time_t rawtime;
time(&rawtime);
m_out << "# ROOT map file generated automatically by genmap on " << ctime(&rawtime) << endl;
}
//------------------------------------------------------------------------------
void
mapGenerator::genFactory(const string& name,
const string& /* type */) {
//------------------------------------------------------------------------------
string mapname = string(PLUGINSVC_FACTORY_NS) + "@@" + PluginService::FactoryName(name);
// for ( string::const_iterator i = name.begin(); i != name.end(); i++) {
// switch(*i) {
// case ':': { newname += '@'; break; }
// case ' ': { break; }
// default: { newname += *i; break; }
// }
// }
m_out << "Library." << mapname << ": " << m_lib << endl;
}
//------------------------------------------------------------------------------
void
mapGenerator::genTrailer() {
//------------------------------------------------------------------------------
}
|