Skip to content

Commit ca2032f

Browse files
committed
[core] Warn if auto-determined RootSys differs from ROOTSYS env var
1 parent 6387a51 commit ca2032f

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

core/base/src/TROOT.cxx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,40 @@ Int_t gDebug;
633633

634634
TROOT::TROOT() : TDirectory() {}
635635

636+
namespace {
637+
638+
void WarnIfInconsistentRootSys()
639+
{
640+
namespace fs = std::filesystem;
641+
642+
const char *envRootSys = std::getenv("ROOTSYS");
643+
if (!envRootSys) {
644+
return;
645+
}
646+
bool isConsistent = false;
647+
// Should never throw because it's a valid path
648+
fs::path detected = fs::canonical(TROOT::GetRootSys().Data());
649+
try {
650+
fs::path fromEnv = fs::canonical(envRootSys);
651+
if (detected == fromEnv) {
652+
isConsistent = true;
653+
}
654+
} catch (const fs::filesystem_error &) {
655+
// Tappens if the path in ROOTSYS fails to canonicalize, e.g. because the
656+
// directory doesn't exist. In that case, we also print the warning.
657+
}
658+
if (isConsistent)
659+
return;
660+
Warning("TROOT",
661+
"ROOTSYS is set but inconsistent with detected ROOT installation:\n"
662+
" ROOTSYS=%s\n"
663+
" Detected=%s\n"
664+
"ROOT will use the detected installation.",
665+
envRootSys, detected.string().c_str());
666+
}
667+
668+
} // namespace
669+
636670
////////////////////////////////////////////////////////////////////////////////
637671
/// Initialize the ROOT system. The creation of the TROOT object initializes
638672
/// the ROOT system. It must be the first ROOT related action that is
@@ -689,6 +723,10 @@ TROOT::TROOT(const char *name, const char *title, VoidFuncPtr_t *initfunc) : TDi
689723
GetIconPath();
690724
GetTTFFontDir();
691725

726+
// Warn if ROOTSYS is in the environment, but it's inconsistent with what
727+
// TROOT has figured out.
728+
WarnIfInconsistentRootSys();
729+
692730
gRootDir = GetRootSys().Data();
693731

694732
TDirectory::BuildDirectory(nullptr, nullptr);

0 commit comments

Comments
 (0)