Skip to content

Commit 6c6dee9

Browse files
committed
[core] Warn if auto-determined RootSys differs from ROOTSYS env var
1 parent 015731f commit 6c6dee9

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
@@ -789,6 +789,40 @@ Int_t gDebug;
789789

790790
TROOT::TROOT() : TDirectory() {}
791791

792+
namespace {
793+
794+
void WarnIfInconsistentRootSys()
795+
{
796+
namespace fs = std::filesystem;
797+
798+
const char *envRootSys = std::getenv("ROOTSYS");
799+
if (!envRootSys) {
800+
return;
801+
}
802+
bool isConsistent = false;
803+
// Should never throw because it's a valid path
804+
fs::path detected = fs::canonical(TROOT::GetRootSys().Data());
805+
try {
806+
fs::path fromEnv = fs::canonical(envRootSys);
807+
if (detected == fromEnv) {
808+
isConsistent = true;
809+
}
810+
} catch (const fs::filesystem_error &) {
811+
// Tappens if the path in ROOTSYS fails to canonicalize, e.g. because the
812+
// directory doesn't exist. In that case, we also print the warning.
813+
}
814+
if (isConsistent)
815+
return;
816+
Warning("TROOT",
817+
"ROOTSYS is set but inconsistent with detected ROOT installation:\n"
818+
" ROOTSYS=%s\n"
819+
" Detected=%s\n"
820+
"ROOT will use the detected installation.",
821+
envRootSys, detected.string().c_str());
822+
}
823+
824+
} // namespace
825+
792826
////////////////////////////////////////////////////////////////////////////////
793827
/// Initialize the ROOT system. The creation of the TROOT object initializes
794828
/// the ROOT system. It must be the first ROOT related action that is
@@ -845,6 +879,10 @@ TROOT::TROOT(const char *name, const char *title, VoidFuncPtr_t *initfunc) : TDi
845879
GetIconPath();
846880
GetTTFFontDir();
847881

882+
// Warn if ROOTSYS is in the environment, but it's inconsistent with what
883+
// TROOT has figured out.
884+
WarnIfInconsistentRootSys();
885+
848886
gRootDir = GetRootSys().Data();
849887

850888
TDirectory::BuildDirectory(nullptr, nullptr);

0 commit comments

Comments
 (0)