Skip to content

Commit d1d33ba

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

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

784784
TROOT::TROOT() : TDirectory() {}
785785

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

876+
// Warn if ROOTSYS is in the environment, but it's inconsistent with what
877+
// TROOT has figured out.
878+
WarnIfInconsistentRootSys();
879+
842880
gRootDir = GetRootSys().Data();
843881

844882
TDirectory::BuildDirectory(nullptr, nullptr);

0 commit comments

Comments
 (0)