Skip to content

Commit

Permalink
[config,proofd] Rely on etc/gitinfo.txt to determine version info:
Browse files Browse the repository at this point in the history
This isn't needed at compiletime; using the text file prevents rebuilding /
having to maintain `RGitCommit.h`.
  • Loading branch information
Axel-Naumann committed Oct 1, 2023
1 parent 5be58e5 commit da1a28a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 55 deletions.
15 changes: 7 additions & 8 deletions config/root-config.bat.in
Expand Up @@ -112,18 +112,17 @@ for %%w in (%*) do (
set out=!out! @ROOT_VERSION@
)
if "!arg!"=="--git-revision" (
rem Output the git revision number. If RGitCommit.h can not be found, give up.
if exist !incdir!\RGitCommit.h (
for /f "tokens=2,3" %%a in (!incdir!\RGitCommit.h) do (
if "%%a"=="ROOT_GIT_COMMIT" (
set ROOT_GIT_COMMIT=%%~b
)
if exist !etcdir!\gitinfo.txt (
for /f "skip=1" %%l in (!etcdir!\gitinfo.txt) do (
set ROOT_GIT_COMMIT=%%~l
goto COMMITSET
)
set out=!out! !ROOT_GIT_COMMIT!
) else (
echo "cannot read !incdir!\RGitCommit.h"
echo "cannot read !etcdir!\gitinfo.txt"
exit /b 1
)
:COMMITSET
set out=!out! !ROOT_GIT_COMMIT!
)
if "!arg!"=="--python-version" (
set out=!out! @pythonvers@
Expand Down
8 changes: 4 additions & 4 deletions config/root-config.in
Expand Up @@ -556,11 +556,11 @@ while test $# -gt 0; do
out="$out @ROOT_VERSION@"
;;
--git-revision)
### Output the git revision number. If RGitCommit.h can not be found, give up.
if test -r "${incdir}/RGitCommit.h"; then
out="$out `sed -n 's,.*ROOT_GIT_COMMIT *\"\(.*\)\".*,\1,p' < \"${incdir}/RGitCommit.h\"`"
### Output the git revision. Give up if gitinfo.txt can not be found.
if test -r "${etcdir}/gitinfo.txt"; then
out="$out `head -m2 \"${etcdir}/gitinfo.txt\" | tail -n`"
else
echo "cannot read ${incdir}/RGitCommit.h"
echo "cannot read ${etcdir}/gitinfo.txt"
exit 1
fi
;;
Expand Down
5 changes: 4 additions & 1 deletion proof/proofd/inc/XrdROOT.h
Expand Up @@ -39,6 +39,7 @@ friend class XrdROOTMgr;
XrdOucString fDir;
XrdOucString fBinDir;
XrdOucString fDataDir;
XrdOucString fEtcDir;
XrdOucString fIncDir;
XrdOucString fLibDir;
XrdOucString fTag;
Expand All @@ -59,12 +60,14 @@ friend class XrdROOTMgr;

public:
XrdROOT(const char *dir, const char *tag, const char *bindir = 0,
const char *incdir = 0, const char *libdir = 0, const char *datadir = 0);
const char *incdir = 0, const char *libdir = 0, const char *datadir = 0,
const char *etcdir = 0);
~XrdROOT() { }

const char *Dir() const { return fDir.c_str(); }
const char *BinDir() const { return fBinDir.c_str(); }
const char *DataDir() const { return fDataDir.c_str(); }
const char *EtcDir() const { return fEtcDir.c_str(); }
const char *IncDir() const { return fIncDir.c_str(); }
const char *LibDir() const { return fLibDir.c_str(); }
const char *Export() const { return fExport.c_str(); }
Expand Down
92 changes: 50 additions & 42 deletions proof/proofd/src/XrdROOT.cxx
Expand Up @@ -20,7 +20,6 @@
//////////////////////////////////////////////////////////////////////////
#include "RConfigure.h"
#include "ROOT/RVersion.hxx"
#include "RGitCommit.h"

#include "XrdProofdPlatform.h"

Expand All @@ -36,27 +35,29 @@
// Tracing
#include "XrdProofdTrace.h"

#include <fstream>

////////////////////////////////////////////////////////////////////////////////
/// Constructor: validates 'dir', gets the version and defines the tag.

XrdROOT::XrdROOT(const char *dir, const char *tag, const char *bindir,
const char *incdir, const char *libdir, const char *datadir)
const char *incdir, const char *libdir, const char *datadir,
const char *etcdir)
{
XPDLOC(SMGR, "XrdROOT")

fStatus = -1;
fSrvProtVers = -1;
fRelease = ROOT_RELEASE;
fGitCommit = ROOT_GIT_COMMIT;
fVersionCode = ROOT_VERSION_CODE;
fVrsMajor = ROOT_VERSION_MAJOR;
fVrsMinor = ROOT_VERSION_MINOR;
fVrsPatch = ROOT_VERSION_PATCH;

// 'dir' must make sense
if (!dir || strlen(dir) <= 0)
if (!dir || !dir[0])
return;
if (tag && strlen(tag) > 0) {
if (tag && tag[0]) {
fExport = tag;
fExport += " "; fExport += dir;
} else
Expand All @@ -65,13 +66,24 @@ XrdROOT::XrdROOT(const char *dir, const char *tag, const char *bindir,
if (CheckDir(dir) != 0) return;
fDir = dir;

// Include dir
fIncDir = incdir;
if (!incdir || strlen(incdir) <= 0) {
fIncDir = fDir;
fIncDir += "/include";
}
if (CheckDir(fIncDir.c_str()) != 0) return;
auto setDir = [&](XrdOucString &target, const char *src, const char *subdir) -> bool {
target = src;
if (!src || !src[0]) {
target = fDir + subdir;
}
return CheckDir(target.c_str()) == 0;
};

if (!setDir(fIncDir, incdir, "/include"))
return;
if (!setDir(fLibDir, libdir, "/lib"))
return;
if (!setDir(fBinDir, bindir, "/bin"))
return;
if (!setDir(fDataDir, datadir, ""))
return;
if (!setDir(fEtcDir, etcdir, "/etc"))
return;

// Parse version info
if (ParseROOTVersionInfo() == -1) {
Expand All @@ -82,29 +94,6 @@ XrdROOT::XrdROOT(const char *dir, const char *tag, const char *bindir,
// Default tag is the version
fTag = (!tag || strlen(tag) <= 0) ? fRelease : tag;

// Lib dir
fLibDir = libdir;
if (!libdir || strlen(libdir) <= 0) {
fLibDir = fDir;
fLibDir += "/lib";
}
if (CheckDir(fLibDir.c_str()) != 0) return;

// Bin dir
fBinDir = bindir;
if (!bindir || strlen(bindir) <= 0) {
fBinDir = fDir;
fBinDir += "/bin";
}
if (CheckDir(fBinDir.c_str()) != 0) return;

// Data dir
fDataDir = datadir;
if (!datadir || strlen(datadir) <= 0) {
fDataDir = fDir;
}
if (CheckDir(fDataDir.c_str()) != 0) return;

// The application to be run
fPrgmSrv = fBinDir;
fPrgmSrv += "/proofserv";
Expand Down Expand Up @@ -176,15 +165,33 @@ int XrdROOT::ParseROOTVersionInfo()

// Version code must be there
if (fVersionCode < 0) {
TRACE(XERR, "incomplete info found in "<<versfile<<": version code missing or bad: "<<fVersionCode);
return rc;
TRACE(XERR, "incomplete info found: version code missing or bad: " << fVersionCode);
return -1;
}

// Release tag must be there and in the right format
if (fRelease.length() <= 0 ||
XrdROOT::ParseReleaseString(fRelease.c_str(), fVrsMajor, fVrsMinor, fVrsPatch) < 0) {
TRACE(XERR, "incomplete info found in "<<versfile<<": release tag missing or bad: "<<fRelease);
return rc;
XrdROOT::ParseReleaseString(fRelease.c_str(), fVrsMajor, fVrsMinor, fVrsPatch) < 0) {
TRACE(XERR, "incomplete info found: release tag missing or bad: " << fRelease);
return -1;
}

std::ifstream gitinfo(fEtcDir + "/gitinfo.txt");
if (!gitinfo) {
if (ROOT_VERSION_PATCH % 2 == 0) {
// A release.
fGitCommit = "v" + std::to_string(ROOT_VERSION_MAJOR)
+ "-" + std::to_string(ROOT_VERSION_MINOR)
+ "-" + std::to_string(ROOT_VERSION_PATCH);
} else {
TRACE(XERR, "incomplete info found: not a ROOT release and no " << fEtcDir + "/gitinfo.txt");
return -1;
}
} else {
std::string gitcommit;
std::getline(gitinfo, gitcommit); // "heads/master"
std::getline(gitinfo, gitcommit); // "v6-29-01-2644-g2b3dd4f1bf"
fGitCommit = gitcommit;
}

// Done
Expand Down Expand Up @@ -308,7 +315,7 @@ int XrdROOTMgr::Config(bool rcf)
} else {
// Check the ROOT dirs
if (fROOT.size() <= 0) {
XrdOucString dir, bd, ld, id, dd;
XrdOucString dir, bd, ed, ld, id, dd;
#ifdef R__HAVE_CONFIG
if (getenv("ROOTIGNOREPREFIX"))
#endif
Expand All @@ -317,6 +324,7 @@ int XrdROOTMgr::Config(bool rcf)
else {
dir = ROOTPREFIX;
bd = ROOTBINDIR;
ed = ROOTETCDIR;
ld = ROOTLIBDIR;
id = ROOTINCDIR;
dd = ROOTDATADIR;
Expand All @@ -325,7 +333,7 @@ int XrdROOTMgr::Config(bool rcf)
// None defined: use ROOTSYS as default, if any; otherwise we fail
if (dir.length() > 0) {
XrdROOT *rootc = new XrdROOT(dir.c_str(), "",
bd.c_str(), id.c_str(), ld.c_str(), dd.c_str());
bd.c_str(), id.c_str(), ld.c_str(), dd.c_str(), ed.c_str());
if (Validate(rootc, fMgr->Sched()) == 0) {
XPDFORM(msg, "ROOT dist: '%s' validated", rootc->Export());
fROOT.push_back(rootc);
Expand Down

0 comments on commit da1a28a

Please sign in to comment.