Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:26

0001 // This macro parses the rebuild.info file which is written by our build script
0002 // it extracts in a crude way the build and the git tags for the repos which
0003 // went into this build and sets stringflags. This even allows us to
0004 // reproduce new builds
0005 
0006 #include <phool/recoConsts.h>
0007 
0008 R__LOAD_LIBRARY(libphool.so)
0009 
0010 void SaveGitTags();
0011 void SetGitTagsFromFile(const std::string &filename);
0012 
0013 void SaveGitTags(const std::string &commitid)
0014 {
0015   recoConsts *rc = recoConsts::instance();
0016   rc->set_StringFlag("MDC2_GITTAG", commitid);
0017   SaveGitTags();
0018 }
0019 
0020 // build the filename from rebuild.info under $OFFLINE_MAIN
0021 void SaveGitTags()
0022 {
0023   char filename[200];
0024   const char *offline = getenv("OFFLINE_MAIN");
0025   string rebuildinfo = string(offline) + string("/rebuild.info");
0026   sprintf(filename, "%s/rebuild.info", offline);
0027   SetGitTagsFromFile(rebuildinfo);
0028   return;
0029 }
0030 
0031 void SetGitTagsFromFile(const std::string &filename)
0032 {
0033   recoConsts *rc = recoConsts::instance();
0034   std::ifstream file(filename);
0035   std::string line;
0036   if (file.is_open())
0037   {
0038     while (std::getline(file, line))
0039     {
0040       if (line.find("install") != string::npos)
0041       {
0042         int res = 0;
0043         int foundlast = 0;
0044         while ((res = line.find('/', res + 1)) !=
0045                string::npos)
0046         {
0047           foundlast = res;
0048         }
0049         foundlast++;
0050         std::string build = line.substr(foundlast, line.length() - foundlast);
0051         rc->set_StringFlag("build", build);
0052       }
0053       int repoline = 0;
0054       if (line.find("git repo ") != string::npos)
0055       {
0056         int start = string(" git repo ").length();
0057         int res = line.find(',');
0058         string reponame = line.substr(start, res - start);
0059         res = line.find(':');
0060         string repotag = line.substr(res + 2, line.length() - (res + 2));
0061         rc->set_StringFlag(reponame, repotag);
0062       }
0063     }
0064     file.close();
0065   }
0066   else
0067   {
0068     std::cout << "Error: Could not open file." << std::endl;
0069   }
0070   return;
0071 }