Skip to content

Commit d93857d

Browse files
[GR-19346] [GR-19295] [GR-19325] Backport fix in working directory resolution and configuration script for MacOS.
PullRequest: fastr/2214
2 parents 359681e + a3affb2 commit d93857d

File tree

3 files changed

+158
-96
lines changed

3 files changed

+158
-96
lines changed

com.oracle.truffle.r.native/run/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ $(FASTR_BIN_DIR)/R: Makefile R.sh Rscript.sh Rscript_exec.sh Rclasspath.sh
109109
ed Makeconf.etc < edMakeconf.etc.llvm
110110
sed -i -e 's/-fopenmp//' Makeconf.etc
111111
sed -i -e 's~LIBR0 =~LIBR0 = -lR~' Makeconf.etc
112-
sed -i -e 's~LDFLAGS =~LDFLAGS = -Wl,-rpath,$$\(R_HOME\)/lib/ -L$$\(R_HOME\)/lib -lf2c~' Makeconf.etc
112+
sed -i -e 's~LDFLAGS =~LDFLAGS = -Wl,-rpath,$$\(R_HOME\)/lib/,-rpath,$$\(R_HOME\)/../llvm/native/lib -L$$\(R_HOME\)/lib -lf2c~' Makeconf.etc
113113
sed -i -e 's~^CXXFLAGS =\(.*\)~CXXFLAGS = \1 $(FASTR_CXXFLAGS)~g' Makeconf.etc
114114
# A workaround for a Sulong issue: TODO: the issue ID
115115
sed -i -e 's/-O2//' Makeconf.etc

com.oracle.truffle.r.native/run/configure_fastr

Lines changed: 156 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,52 @@ done
3838

3939
function printHelp {
4040
if [[ "$OSTYPE" == "darwin"* ]]; then
41-
echo "usage: configure_fastr [--help] [--configure-etc [--enable-native-compilers-toolchain]] [--gcc-lib-path <path>]"
41+
echo "usage: configure_fastr [--help] [--configure-etc [--enable-native-compilers-toolchain]] [--gcc-lib-path <path>]"
4242
else
43-
echo "usage: configure_fastr [--help] [--configure-etc [--enable-native-compilers-toolchain]]"
44-
fi
43+
echo "usage: configure_fastr [--help] [--configure-etc [--enable-native-compilers-toolchain]]"
44+
fi
4545

46-
echo ""
47-
echo "optional arguments:"
48-
echo " --configure-etc Configure the files in the 'etc' folder. Unless '--enable-native-compilers-toolchain' is specified, the configuration will not affect the 'etc/Makeconf' file to preserve the original compilers toolchain configuration."
49-
echo " --enable-native-compilers-toolchain Include the 'etc/Makefile' file into the configuration. It will replace the original compiler toolchain configuration in 'etc/Makefile' with the native compilers toolchain."
50-
if [[ "$OSTYPE" == "darwin"* ]]; then
46+
echo ""
47+
echo "optional arguments:"
48+
echo " --configure-etc Configure the files in the 'etc' folder. Unless '--enable-native-compilers-toolchain' is specified, the configuration will not affect the 'etc/Makeconf' file to preserve the original compilers toolchain configuration."
49+
echo " --enable-native-compilers-toolchain Include the 'etc/Makefile' file into the configuration. It will replace the original compiler toolchain configuration in 'etc/Makefile' with the native compilers toolchain."
50+
if [[ "$OSTYPE" == "darwin"* ]]; then
5151
echo " --gcc-lib-path <path> Use the <path> to locate the required gfortran libraries."
52-
fi
52+
echo " --macos-no-homebrew Allows the script to proceed even if the target system does not have homebrew"
53+
fi
5354

54-
echo ""
55-
echo "examples:"
56-
echo " * Basic FastR configuration:"
57-
echo ""
58-
echo " configure_fastr"
59-
echo ""
60-
echo " * An advanced FastR configuration with an additional configuration of the 'etc' folder except 'etc/Makefile':"
61-
echo ""
62-
echo " configure_fastr --configure-etc"
63-
echo ""
55+
echo ""
56+
echo "examples:"
57+
echo " * Basic FastR configuration:"
58+
echo ""
59+
echo " configure_fastr"
60+
echo ""
61+
echo " * An advanced FastR configuration with an additional configuration of the 'etc' folder except 'etc/Makefile':"
62+
echo ""
63+
echo " configure_fastr --configure-etc"
64+
echo ""
6465
if [[ "$OSTYPE" == "darwin"* ]]; then
65-
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder. It also specifies the GCC path to locate the required libraries:"
66-
echo ""
67-
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain --gcc-lib-path /usr/local/Cellar/gcc\@4.9/4.9.4_1/lib/gcc/4.9/"
66+
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder. It also specifies the GCC path to locate the required libraries:"
67+
echo ""
68+
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain --gcc-lib-path /usr/local/Cellar/gcc\@4.9/4.9.4_1/lib/gcc/4.9/"
6869
else
69-
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder:"
70-
echo ""
71-
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain"
72-
fi
73-
echo ""
70+
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder:"
71+
echo ""
72+
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain"
73+
fi
74+
echo ""
7475
}
7576

7677
GCC_LIB_PATH=""
7778
CONFIGURE_ARGS=""
7879
CONFIGURE_ETC=0
7980
CONFIGURE_NATIVE_TOOLCHAIN=0
81+
NO_BREW=0
8082
while [[ $# -gt 0 ]]; do
8183
case $1 in
8284
--help)
83-
printHelp
84-
exit 0
85+
printHelp
86+
exit 0
8587
;;
8688
--gcc-lib-path)
8789
shift
@@ -90,6 +92,9 @@ while [[ $# -gt 0 ]]; do
9092
--configure-etc)
9193
CONFIGURE_ETC=1
9294
;;
95+
--macos-no-homebrew)
96+
NO_BREW=1
97+
;;
9398
--enable-native-compilers-toolchain)
9499
CONFIGURE_NATIVE_TOOLCHAIN=1
95100
CONFIGURE_ARGS="$CONFIGURE_ARGS $1"
@@ -147,66 +152,123 @@ fi
147152
echo "The basic configuration of FastR was successfull."
148153
fi
149154
elif [[ "$OSTYPE" == "darwin"* ]]; then
150-
cd -P "$( dirname "$source" )/../lib"
151-
# correct paths on Mac OSX
152-
GFORTRAN_LIBRARIES="libgfortran.3.dylib libgfortran.5.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
153-
# This allows determining if all libraries were found after the main loop
154-
GFORTRAN_LIBRARIES_CHECK="libgfortran libquadmath libgomp libgcc_s"
155-
GFORTRAN_LOCATIONS="$GCC_LIB_PATH /opt/local/lib /opt/local/lib/libgcc /usr/local/gfortran/lib"
156-
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
157-
FOUND=""
158-
LAST_FOUND=""
159-
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
160-
do
161-
# Remove the 'dylib' extension
162-
GFORTRAN_LIB_BASE=${GFORTRAN_LIB%.*}
163-
# Remove the number extension
164-
GFORTRAN_LIB_BASE=${GFORTRAN_LIB_BASE%.*}
165-
if [ "$LAST_FOUND" = "$GFORTRAN_LIB_BASE" ] ; then
166-
# A previous version of the current library has already been found
167-
echo "skipping $GFORTRAN_LIB"
168-
continue;
169-
fi
170-
171-
for LOCATION in $GFORTRAN_LOCATIONS
172-
do
173-
if test -f "${LOCATION}/${GFORTRAN_LIB}"; then
174-
LIB_LOCATION="${LOCATION}/${GFORTRAN_LIB}"
175-
FOUND="$FOUND $GFORTRAN_LIB_BASE"
176-
LAST_FOUND=$GFORTRAN_LIB_BASE
177-
178-
echo "${GFORTRAN_LIB} found at ${LIB_LOCATION}"
179-
for TARGET_LIB in $TARGET_LIBRARIES
180-
do
181-
# don't look at symlinks
182-
if [ ! -L "${TARGET_LIB}" ] ; then
183-
# grep for the current path of this gfortran library in this library's linking info
184-
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB_BASE}[^ ]*"`
185-
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
186-
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
187-
# change to the new location
188-
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
189-
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
190-
fi
191-
fi
192-
fi
193-
done
194155

195-
break
156+
if which brew; then
157+
GCC_DARWIN_HOME=/usr/local/Cellar/gcc@4.9/4.9.4_1/lib/gcc/4.9
158+
159+
if [ -d "$GCC_DARWIN_HOME" ] ; then
160+
echo "gcc 4.9 installation found."
161+
162+
cd -P "$( dirname "$source" )/../lib"
163+
# correct paths on Mac OSX
164+
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
165+
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
166+
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
167+
do
168+
LIB_LOCATION="${GCC_DARWIN_HOME}/${GFORTRAN_LIB}"
169+
for TARGET_LIB in $TARGET_LIBRARIES
170+
do
171+
# don't look at symlinks
172+
if [ ! -L "${TARGET_LIB}" ] ; then
173+
# grep for the current path of this gfortran library in this library's linking info
174+
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB}"`
175+
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
176+
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
177+
# change to the new location
178+
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
179+
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
180+
fi
181+
fi
182+
fi
183+
done
184+
done
185+
else
186+
echo "No Homebrew gcc 4.9 installation found."
187+
echo "Please ensure that you have gcc installed on your system using the homebrew command:"
188+
echo " brew install gcc@4.9"
189+
190+
HOMEBREW_PREFIX_OUT=`brew config | grep HOMEBREW_PREFIX`
191+
HOMEBREW_PREFIX=${HOMEBREW_PREFIX_OUT##*: }
192+
if [[ "$HOMEBREW_PREFIX" != "/usr/local" ]]; then
193+
echo "Your Homebrew uses other than the default installation directory prefix (i.e. /usr/local)."\
194+
"Since FastR assumes the default prefix, use the following command to create a symbolic link to your Homebrew installations:"
195+
echo " sudo ln -s $HOMEBREW_PREFIX/Cellar /usr/local/Cellar"
196+
fi
196197

198+
exit 1
199+
fi
200+
else # not "which brew"
201+
if [ $NO_BREW = 0 ]; then
202+
echo "FastR depends on GFortran 3 runtime libraries."
203+
echo "It appears that this system does not use the homebrew package manager."
204+
echo "We suggest to use homebrew and install the necessary dependencies with:"
205+
echo " brew install gcc@4.9"
206+
echo "If you want to use another installation of GFortran 3 libraries, re-run this script with '--macos-no-homebrew'."
207+
exit 2
208+
fi
209+
210+
cd -P "$( dirname "$source" )/../lib"
211+
# correct paths on Mac OSX
212+
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
213+
# This allows determining if all libraries were found after the main loop
214+
GFORTRAN_LIBRARIES_CHECK="libgfortran libquadmath libgomp libgcc_s"
215+
GFORTRAN_LOCATIONS="$GCC_LIB_PATH /opt/local/lib /opt/local/lib/libgcc /usr/local/gfortran/lib"
216+
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
217+
FOUND=""
218+
FOUND_FULL=""
219+
LAST_FOUND=""
220+
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
221+
do
222+
# Remove the 'dylib' extension
223+
GFORTRAN_LIB_BASE=${GFORTRAN_LIB%.*}
224+
# Remove the number extension
225+
GFORTRAN_LIB_BASE=${GFORTRAN_LIB_BASE%.*}
226+
if [ "$LAST_FOUND" = "$GFORTRAN_LIB_BASE" ] ; then
227+
# A previous version of the current library has already been found
228+
echo "skipping $GFORTRAN_LIB"
229+
continue;
197230
fi
231+
for LOCATION in $GFORTRAN_LOCATIONS
232+
do
233+
if test -f "${LOCATION}/${GFORTRAN_LIB}"; then
234+
LIB_LOCATION="${LOCATION}/${GFORTRAN_LIB}"
235+
FOUND="$FOUND $GFORTRAN_LIB_BASE"
236+
LAST_FOUND=$GFORTRAN_LIB_BASE
237+
echo "${GFORTRAN_LIB} found at ${LIB_LOCATION}"
238+
for TARGET_LIB in $TARGET_LIBRARIES
239+
do
240+
# don't look at symlinks
241+
if [ ! -L "${TARGET_LIB}" ] ; then
242+
# grep for the current path of this gfortran library in this library's linking info
243+
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB_BASE}[^ ]*"`
244+
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
245+
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
246+
# change to the new location
247+
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
248+
FOUND_FULL="${FOUND_FULL}\n ${LIB_LOCATION}"
249+
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
250+
fi
251+
fi
252+
fi
253+
done
254+
break
255+
fi
256+
done
198257
done
199-
done
200-
201-
if [ "$FOUND" != " $GFORTRAN_LIBRARIES_CHECK" ] ; then
202-
echo "From expected libraries '$GFORTRAN_LIBRARIES_CHECK' found only '$FOUND'."
203-
echo "Please ensure that you have gcc installed on your system, e.g., using homebrew or MacPorts (brew install gcc)."
204-
echo "If it is installed in a non-standard location, you can specify its location using the '--gcc-lib-path' parameter."
205-
echo ""
206-
printHelp
207-
exit 1
208-
fi
209258

259+
if [ "$FOUND" != " $GFORTRAN_LIBRARIES_CHECK" ] ; then
260+
echo "From expected libraries '$GFORTRAN_LIBRARIES_CHECK' found only '$FOUND'."
261+
echo "Please ensure that you have GFortran 3 installed on your system."
262+
echo "We suggest to use homebrew and install the necessary dependencies with:"
263+
echo " brew install gcc@4.9"
264+
echo "If the GFortran 3 runtime libraries are installed in a non-standard location, you can specify that location using the '--gcc-lib-path' parameter."
265+
exit 1
266+
else
267+
echo "Succesfully updated FastR installation to use the GFortran 3 system libraries."
268+
FASTR_HOME=$(cd ..; pwd -P )
269+
echo "The fortran compiler flags in $FASTR_HOME/etc/Makeconf (variable FLIBS) were not updated and must be adjusted manually!"
270+
fi
271+
fi # which brew
210272
else
211273
echo "Unknown operating system."
212274
echo "FastR may still work."
@@ -221,16 +283,16 @@ fi
221283
res=$?
222284
if [[ $res != 0 ]]; then
223285
echo "The configuration step failed."
224-
echo "The log was saved into ${PWD}/configure.log"
225-
echo "FastR may still work, but compilation of some R packages may fail"
226-
exit 1
227-
fi
228-
ed Makeconf < edMakeconf.etc > /dev/null 2>/dev/null
229-
export R_DEFAULT_PACKAGES=base
230-
R_LIBS_USER=`"../bin/R" --slave -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))'`
231-
echo "Creating user specific library directory: $R_LIBS_USER"
232-
mkdir -p "$R_LIBS_USER"
233-
echo "DONE"
286+
echo "The log was saved into ${PWD}/configure.log"
287+
echo "FastR may still work, but compilation of some R packages may fail"
288+
exit 1
289+
fi
290+
ed Makeconf < edMakeconf.etc > /dev/null 2>/dev/null
291+
export R_DEFAULT_PACKAGES=base
292+
R_LIBS_USER=`"../bin/R" --slave -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))'`
293+
echo "Creating user specific library directory: $R_LIBS_USER"
294+
mkdir -p "$R_LIBS_USER"
295+
echo "DONE"
234296
fi
235297

236298
)

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public static String tildeExpand(String path, boolean keepRelative) {
342342
if (path.length() == 0) {
343343
return keepRelative ? path : wdState().getCurrentPath().getPath();
344344
} else {
345-
TruffleFile p = FileSystemUtils.getSafeTruffleFile(RContext.getInstance().getEnv(), path);
345+
TruffleFile p = RContext.getInstance().getEnv().getInternalTruffleFile(path);
346346
if (p.isAbsolute()) {
347347
return path;
348348
} else {

0 commit comments

Comments
 (0)