Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:05

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