30 std::cout <<
"Already loaded handle " <<
fHandle << std::endl;
35 if(libraryPath.empty()) {
36 std::ostringstream str;
37 str <<
DRED <<
"No data frame library provided! Please provided the location of the data frame library on the command line." <<
RESET_COLOR;
38 throw std::runtime_error(str.str());
43 size_t dot = libraryPath.find_last_of(
'.');
44 size_t slash = libraryPath.find_last_of(
'/');
45 if(dot != std::string::npos && (dot > slash || slash == std::string::npos) && libraryPath.substr(dot) ==
".cxx") {
47 Compile(libraryPath, dot, slash);
49 libraryPath.replace(dot, std::string::npos,
".so");
53 std::ostringstream str;
54 str <<
DRED <<
"Library '" << libraryPath <<
"' does not exist or we do not have permissions to access it!" <<
RESET_COLOR;
55 throw std::runtime_error(str.str());
58 fHandle = dlopen(libraryPath.c_str(), RTLD_LAZY);
60 std::ostringstream str;
61 str <<
DRED <<
"Failed to open data frame library '" << libraryPath <<
"': " << dlerror() <<
"!" <<
RESET_COLOR;
62 std::cout <<
"dlerror: '" << dlerror() <<
"'" << std::endl;
63 throw std::runtime_error(str.str());
66#pragma GCC diagnostic push
67#pragma GCC diagnostic ignored "-Wcast-function-type"
70#pragma GCC diagnostic pop
73 std::ostringstream str;
74 str <<
DRED <<
"Failed to find CreateHelper, and/or DestroyHelper functions in library '" << libraryPath <<
"'!" <<
RESET_COLOR;
75 throw std::runtime_error(str.str());
77 std::cout <<
"\tUsing library " << libraryPath << std::endl;
96 std::string sourceFile = path;
97 std::string headerFile = path.replace(dot, std::string::npos,
".hh");
98 std::string sharedLibrary = path.replace(dot, std::string::npos,
".so");
100 struct stat sourceStat{};
101 if(stat(sourceFile.c_str(), &sourceStat) != 0) {
102 std::ostringstream str;
103 str <<
"Unable to access stat of source file " << sourceFile << std::endl;
104 throw std::runtime_error(str.str());
106 struct stat headerStat{};
107 if(stat(headerFile.c_str(), &headerStat) != 0) {
108 std::ostringstream str;
109 str <<
"Unable to access stat of header file " << headerFile << std::endl;
110 throw std::runtime_error(str.str());
112 struct stat frameLibStat{};
116 std::ostringstream str;
117 str <<
"Unable to find location of DummyFunctionToLocateTGRSIFrameLibrary" << std::endl;
118 throw std::runtime_error(str.str());
120 if(stat(info.dli_fname, &frameLibStat) != 0) {
121 std::ostringstream str;
122 str <<
"Unable to access stat of " << info.dli_fname << std::endl;
123 throw std::runtime_error(str.str());
125 struct stat sharedLibStat{};
126 if(stat(sharedLibrary.c_str(), &sharedLibStat) == 0 &&
127 sharedLibStat.st_atime > sourceStat.st_atime &&
128 sharedLibStat.st_atime > headerStat.st_atime &&
129 sharedLibStat.st_atime > frameLibStat.st_atime) {
130 std::cout <<
DCYAN <<
"shared library " << sharedLibrary <<
" exists and is newer than " << sourceFile <<
", " << headerFile <<
", and $GRSISYS/lib/libTGRSIFrame.so" <<
RESET_COLOR << std::endl;
134 std::string includePath =
".";
135 if(slash != std::string::npos) {
136 includePath = path.substr(0, slash);
138 std::cout <<
DCYAN <<
"---------- starting compilation of user code ----------" <<
RESET_COLOR << std::endl;
142 std::string parserLibraryName = parserLibraryPath.substr(parserLibraryPath.find_last_of(
'/') + 4, parserLibraryPath.find_last_of(
'.') - parserLibraryPath.find_last_of(
'/') - 4);
143 std::string objectFile = path.replace(dot, std::string::npos,
".o");
144 std::ostringstream command;
145 command <<
"g++ -c -fPIC -g $(grsi-config --cflags --" << parserLibraryName <<
"-cflags) $(root-config --cflags) -I" << includePath;
147 command <<
" -I/opt/local/include ";
149 command <<
" -o " << objectFile <<
" " << sourceFile;
150 if(std::system(command.str().c_str()) != 0) {
151 std::ostringstream str;
152 str <<
"Unable to compile source file " << sourceFile <<
" using " <<
DBLUE <<
"'" << command.str() <<
"'" <<
RESET_COLOR << std::endl;
153 throw std::runtime_error(str.str());
155 std::cout <<
DCYAN <<
"---------- starting linking user code -----------------" <<
RESET_COLOR << std::endl;
156 std::ostringstream().swap(command);
157 command <<
"g++ -fPIC -g -shared $(grsi-config --libs --" << parserLibraryName <<
"-libs) $(root-config --glibs) -o " << sharedLibrary <<
" " << objectFile;
158 if(std::system(command.str().c_str()) != 0) {
159 std::ostringstream str;
160 str <<
"Unable to link shared object library " << sharedLibrary <<
" using " <<
DBLUE <<
"'" << command.str() <<
"'" <<
RESET_COLOR << std::endl;
161 throw std::runtime_error(str.str());
163 std::cout <<
DCYAN <<
"---------- done compiling user code -------------------" <<
RESET_COLOR << std::endl;