Skip to content

Commit 6dde01e

Browse files
committed
[core] Warn if auto-determined RootSys differs from ROOTSYS env var
Example of how the warning looks like if it happens: ```txt [I] omen nix-shell ~/c/r/root_build > ROOTSYS=/home/rembserj/ ./bin/root Warning in <TROOT>: ROOTSYS is set but inconsistent with detected ROOT installation: ROOTSYS=/home/rembserj/ Detected=/home/rembserj/code/root/root_build ROOT will use the detected installation. ------------------------------------------------------------------ | Welcome to ROOT 6.41.01 https://root.cern | | (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers | | Built for linuxx8664gcc on Jan 01 1980, 00:00:00 | | From heads/ignoreprefix@v6-99-99-368-gd1d33ba04be | | With clang version 21.1.8 std202002 | | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' | ------------------------------------------------------------------ root [0] ```
1 parent 40c9ae3 commit 6dde01e

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+
// Happens 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)