Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
g4lbne
generateVersionAndContext.cc
Go to the documentation of this file.
1
#include <iostream>
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <unistd.h>
5
#include <fstream>
6
#include <ctime>
7
8
int
main
(
int
argc,
char
*
argv
[])
9
{
10
11
if
(argc != 2) {
12
std::cerr <<
" usage: generateVersionAndContext <cmake source directory> "
<<
std::endl
;
13
return
1;
14
}
15
16
FILE *fp;
17
char
gitRes[1035];
18
std::string
cMakeDirectoryStr(argv[1]);
19
char
*g4lbneDirChr =
getenv
(
"G4LBNE_DIR"
);
20
if
(g4lbneDirChr == 0) {
21
std::cerr <<
" Environment variable G4LBNE_DIR not set.... "
<<
std::endl
;
22
return
1;
23
}
24
// std::string g4lbneDirStr(g4lbneDirChr);
25
chdir(g4lbneDirChr);
26
std::string
g4lbneDirStr(g4lbneDirChr);
27
if
(cMakeDirectoryStr != g4lbneDirStr) {
28
std::cerr <<
" Possible confusion on where the source was installed, CMake src "
<<
29
cMakeDirectoryStr <<
" env. var. from setup "
<< g4lbneDirStr <<
std::endl
;
30
}
31
/* Open the command for reading. */
32
fp = popen(
"git describe --all"
,
"r"
);
33
if
(fp == 0) {
34
std::cerr <<
"Failed to run the git command"
<<
std::endl
;
35
exit(1);
36
}
37
fgets(gitRes,
sizeof
(gitRes)-1, fp);
38
// remove the last character,
39
std::string
gitResStr(gitRes);
40
gitResStr = gitResStr.substr(0, gitResStr.length()-1);
41
std::cerr <<
" git version.. "
<< gitResStr <<
std::endl
;
42
43
std::ofstream fOutCC(
"./VersionAndContext.cc"
);
44
fOutCC <<
"#include <iostream>"
<<
std::endl
;
45
fOutCC <<
"#include <stdlib.h>"
<<
std::endl
;
46
fOutCC <<
"#include <stdio.h>"
<<
std::endl
;
47
fOutCC <<
"#include <unistd.h>"
<<
std::endl
;
48
fOutCC <<
"#include <fstream>"
<< std::endl <<
std::endl
;
49
fOutCC <<
"#include \"VersionAndContext.hh\" "
<< std::endl <<
std::endl
;
50
fOutCC <<
"VersionAndContext::VersionAndContext():"
<<
std::endl
;
51
fOutCC <<
" gitDescription(\""
<< gitResStr <<
"\"),"
<<
std::endl
;
52
fOutCC <<
" g4lbnfDir(\""
<< g4lbneDirStr <<
"\"),"
<<
std::endl
;
53
time_t t =
time
(0);
// get time now
54
struct
tm *
now
= localtime( & t );
55
char
bufTime[80];
56
// Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
57
// for more information about date/time format
58
strftime(bufTime,
sizeof
(bufTime),
"%Y-%m-%d.%X"
, now);
59
fOutCC <<
" buildTimeStamp(\""
<<
std::string
(bufTime)
60
<<
"\") "
<<
std::endl
;
61
62
fOutCC <<
" { ; } "
<< std::endl <<
std::endl
;
63
fOutCC <<
"VersionAndContext* VersionAndContext::fInstance = 0; "
<< std::endl <<
std::endl
;
64
fOutCC <<
"VersionAndContext* VersionAndContext::Instance() { "
<<
std::endl
;
65
fOutCC <<
" if (fInstance == 0) fInstance = new VersionAndContext(); "
<<
std::endl
;
66
fOutCC <<
" return fInstance; } "
<<
std::endl
;
67
68
fOutCC.close();
69
return
0;
70
}
71
main
int main(int argc, char *argv[])
Definition:
generateVersionAndContext.cc:8
string
std::string string
Definition:
nybbler.cc:12
freeze_graph.argv
argv
Definition:
freeze_graph.py:218
time
cet::getenv
std::string getenv(std::string const &name)
Definition:
getenv.cc:15
submit_mcc.now
now
Definition:
submit_mcc.py:14
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Generated by
1.8.11