Skip to content

Commit ef1b534

Browse files
[thisroot] resolve symbolic links
- Use dirname and realpath to resolve symbolic links of thisroot.sh to find the root installation. - Print error message if thisroot.sh is not part of a root installation - Do the same for csh and fish Fixes https://its.cern.ch/jira/browse/ROOT-10415 Co-authored-by: Stephan Hageboeck <[email protected]>
1 parent 9b7193b commit ef1b534

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

config/thisroot.csh

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,31 @@ endif
1717
set ARGS=($_)
1818

1919
set LSOF=`env PATH=/usr/sbin:${PATH} which lsof`
20-
set thisfile="`${LSOF} -w +p $$ | grep -oE '/.*thisroot.csh' `"
21-
if ( "$thisfile" == "" ) then
22-
# set thisfile=/does/not/exist
20+
set SOURCE="`${LSOF} -w +p $$ | grep -oE '/.*thisroot.csh' `"
21+
if ( "$SOURCE" == "" ) then
22+
# set SOURCE=/does/not/exist
2323
endif
24-
if ( "$thisfile" != "" && -e ${thisfile} ) then
24+
if ( "$SOURCE" != "" && -e ${SOURCE} ) then
2525
# We found it, didn't we.
26-
set thisroot="`dirname ${thisfile}`"
26+
set SOURCE=`realpath ${SOURCE}`
27+
set thisrootdir=`dirname ${SOURCE}`
2728
else if ("$ARGS" != "") then
28-
set thisroot="`dirname ${ARGS[2]}`"
29+
set SOURCE=`realpath ${ARGS[2]}`
30+
set thisrootdir="`dirname ${SOURCE}`"
2931
else
3032
# But $_ might not be set if the script is source non-interactively.
3133
# In [t]csh the sourced file is inserted 'in place' inside the
3234
# outer script, so we need an external source of information
3335
# either via the current directory or an extra parameter.
3436
if ( -e thisroot.csh ) then
35-
set thisroot=${PWD}
37+
set thisrootdir=${PWD}
3638
else if ( -e bin/thisroot.csh ) then
37-
set thisroot=${PWD}/bin
39+
set thisrootdir=${PWD}/bin
3840
else if ( "$1" != "" ) then
3941
if ( -e ${1}/bin/thisroot.csh ) then
40-
set thisroot=${1}/bin
42+
set thisrootdir=${1}/bin
4143
else if ( -e ${1}/thisroot.csh ) then
42-
set thisroot=${1}
44+
set thisrootdir=${1}
4345
else
4446
echo "thisroot.csh: ${1} does not contain a ROOT installation"
4547
endif
@@ -53,9 +55,14 @@ else
5355
endif
5456
endif
5557

56-
if ($?thisroot) then
58+
if ($?thisrootdir) then
5759

58-
setenv ROOTSYS "`(cd ${thisroot}/..;pwd)`"
60+
setenv ROOTSYS "`(dirname ${thisrootdir})`"
61+
if ( ! -f "$ROOTSYS/bin/root-config" ) then
62+
echo "ERROR: root-config not found under ROOTSYS=\"$ROOTSYS/\"" >&2
63+
set ROOTSYS =
64+
return 1
65+
endif
5966

6067
if ($?old_rootsys) then
6168
setenv PATH `set DOLLAR='$'; echo $PATH | sed -e "s;:$old_rootsys/bin:;:;g" \
@@ -232,7 +239,7 @@ else
232239
setenv JUPYTER_CONFIG_PATH ${ROOTSYS}/etc/notebook
233240
endif
234241

235-
endif # if ("$thisroot" != "")
242+
endif # if ("$thisrootdir" != "")
236243

237-
set thisroot=
244+
set thisrootdir=
238245
set old_rootsys=

config/thisroot.fish

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ end
2929

3030
set SOURCE (status -f)
3131
# normalize path
32-
set thisroot (path dirname $SOURCE)
33-
set -xg ROOTSYS (set oldpwd $PWD; cd $thisroot/.. > /dev/null;pwd;cd $oldpwd; set -e oldpwd)
32+
set thisrootdir (dirname (realpath $SOURCE))
33+
set -xg ROOTSYS (string replace -r '/[^/]*$' '' $thisrootdir)
34+
35+
if not test -f "$ROOTSYS/bin/root-config"
36+
echo "ERROR: root-config not found under ROOTSYS=\"$ROOTSYS/\"" >&2
37+
set -e ROOTSYS
38+
exit
39+
end
3440

3541
if not set -q MANPATH
3642
# Grab the default man path before setting the path to avoid duplicates

config/thisroot.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ if [ -z "${SOURCE}" ]; then
244244
return 1
245245
fi
246246
else
247-
# get param to "."
248-
thisroot="$(dirname "${SOURCE}")"
249-
ROOTSYS=$(cd "${thisroot}/.." > /dev/null && pwd); export ROOTSYS
250-
if [ -z "$ROOTSYS" ]; then
251-
echo "ERROR: \"cd ${thisroot}/..\" or \"pwd\" failed" >&2
252-
return 1
253-
fi
247+
thisrootdir=$(dirname $(realpath "${SOURCE}"))
248+
export ROOTSYS=${thisrootdir%/*}
254249
fi
255250

251+
if ! [ -f "${ROOTSYS}/bin/root-config" ] ; then
252+
echo "ERROR: root-config not found under ROOTSYS=\"${ROOTSYS}/\"" >&2
253+
ROOTSYS=; export ROOTSYS
254+
return 1
255+
fi
256256

257257
clean_environment
258258
set_environment

0 commit comments

Comments
 (0)