Skip to content

Commit

Permalink
[GR-19346] [GR-19295] [GR-19325] Backport fix in working directory re…
Browse files Browse the repository at this point in the history
…solution and configuration script for MacOS.

PullRequest: fastr/2214
  • Loading branch information
gilles-duboscq committed Nov 4, 2019
2 parents 359681e + a3affb2 commit d93857d
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 96 deletions.
2 changes: 1 addition & 1 deletion com.oracle.truffle.r.native/run/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ $(FASTR_BIN_DIR)/R: Makefile R.sh Rscript.sh Rscript_exec.sh Rclasspath.sh
ed Makeconf.etc < edMakeconf.etc.llvm
sed -i -e 's/-fopenmp//' Makeconf.etc
sed -i -e 's~LIBR0 =~LIBR0 = -lR~' Makeconf.etc
sed -i -e 's~LDFLAGS =~LDFLAGS = -Wl,-rpath,$$\(R_HOME\)/lib/ -L$$\(R_HOME\)/lib -lf2c~' Makeconf.etc
sed -i -e 's~LDFLAGS =~LDFLAGS = -Wl,-rpath,$$\(R_HOME\)/lib/,-rpath,$$\(R_HOME\)/../llvm/native/lib -L$$\(R_HOME\)/lib -lf2c~' Makeconf.etc
sed -i -e 's~^CXXFLAGS =\(.*\)~CXXFLAGS = \1 $(FASTR_CXXFLAGS)~g' Makeconf.etc
# A workaround for a Sulong issue: TODO: the issue ID
sed -i -e 's/-O2//' Makeconf.etc
Expand Down
250 changes: 156 additions & 94 deletions com.oracle.truffle.r.native/run/configure_fastr
Original file line number Diff line number Diff line change
Expand Up @@ -38,50 +38,52 @@ done

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

echo ""
echo "optional arguments:"
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."
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."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo ""
echo "optional arguments:"
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."
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."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo " --gcc-lib-path <path> Use the <path> to locate the required gfortran libraries."
fi
echo " --macos-no-homebrew Allows the script to proceed even if the target system does not have homebrew"
fi

echo ""
echo "examples:"
echo " * Basic FastR configuration:"
echo ""
echo " configure_fastr"
echo ""
echo " * An advanced FastR configuration with an additional configuration of the 'etc' folder except 'etc/Makefile':"
echo ""
echo " configure_fastr --configure-etc"
echo ""
echo ""
echo "examples:"
echo " * Basic FastR configuration:"
echo ""
echo " configure_fastr"
echo ""
echo " * An advanced FastR configuration with an additional configuration of the 'etc' folder except 'etc/Makefile':"
echo ""
echo " configure_fastr --configure-etc"
echo ""
if [[ "$OSTYPE" == "darwin"* ]]; then
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:"
echo ""
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/"
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:"
echo ""
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/"
else
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder:"
echo ""
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain"
fi
echo ""
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder:"
echo ""
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain"
fi
echo ""
}

GCC_LIB_PATH=""
CONFIGURE_ARGS=""
CONFIGURE_ETC=0
CONFIGURE_NATIVE_TOOLCHAIN=0
NO_BREW=0
while [[ $# -gt 0 ]]; do
case $1 in
--help)
printHelp
exit 0
printHelp
exit 0
;;
--gcc-lib-path)
shift
Expand All @@ -90,6 +92,9 @@ while [[ $# -gt 0 ]]; do
--configure-etc)
CONFIGURE_ETC=1
;;
--macos-no-homebrew)
NO_BREW=1
;;
--enable-native-compilers-toolchain)
CONFIGURE_NATIVE_TOOLCHAIN=1
CONFIGURE_ARGS="$CONFIGURE_ARGS $1"
Expand Down Expand Up @@ -147,66 +152,123 @@ fi
echo "The basic configuration of FastR was successfull."
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
cd -P "$( dirname "$source" )/../lib"
# correct paths on Mac OSX
GFORTRAN_LIBRARIES="libgfortran.3.dylib libgfortran.5.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
# This allows determining if all libraries were found after the main loop
GFORTRAN_LIBRARIES_CHECK="libgfortran libquadmath libgomp libgcc_s"
GFORTRAN_LOCATIONS="$GCC_LIB_PATH /opt/local/lib /opt/local/lib/libgcc /usr/local/gfortran/lib"
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
FOUND=""
LAST_FOUND=""
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
do
# Remove the 'dylib' extension
GFORTRAN_LIB_BASE=${GFORTRAN_LIB%.*}
# Remove the number extension
GFORTRAN_LIB_BASE=${GFORTRAN_LIB_BASE%.*}
if [ "$LAST_FOUND" = "$GFORTRAN_LIB_BASE" ] ; then
# A previous version of the current library has already been found
echo "skipping $GFORTRAN_LIB"
continue;
fi

for LOCATION in $GFORTRAN_LOCATIONS
do
if test -f "${LOCATION}/${GFORTRAN_LIB}"; then
LIB_LOCATION="${LOCATION}/${GFORTRAN_LIB}"
FOUND="$FOUND $GFORTRAN_LIB_BASE"
LAST_FOUND=$GFORTRAN_LIB_BASE

echo "${GFORTRAN_LIB} found at ${LIB_LOCATION}"
for TARGET_LIB in $TARGET_LIBRARIES
do
# don't look at symlinks
if [ ! -L "${TARGET_LIB}" ] ; then
# grep for the current path of this gfortran library in this library's linking info
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB_BASE}[^ ]*"`
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
# change to the new location
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
fi
fi
fi
done

break
if which brew; then
GCC_DARWIN_HOME=/usr/local/Cellar/gcc@4.9/4.9.4_1/lib/gcc/4.9

if [ -d "$GCC_DARWIN_HOME" ] ; then
echo "gcc 4.9 installation found."

cd -P "$( dirname "$source" )/../lib"
# correct paths on Mac OSX
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
do
LIB_LOCATION="${GCC_DARWIN_HOME}/${GFORTRAN_LIB}"
for TARGET_LIB in $TARGET_LIBRARIES
do
# don't look at symlinks
if [ ! -L "${TARGET_LIB}" ] ; then
# grep for the current path of this gfortran library in this library's linking info
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB}"`
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
# change to the new location
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
fi
fi
fi
done
done
else
echo "No Homebrew gcc 4.9 installation found."
echo "Please ensure that you have gcc installed on your system using the homebrew command:"
echo " brew install gcc@4.9"

HOMEBREW_PREFIX_OUT=`brew config | grep HOMEBREW_PREFIX`
HOMEBREW_PREFIX=${HOMEBREW_PREFIX_OUT##*: }
if [[ "$HOMEBREW_PREFIX" != "/usr/local" ]]; then
echo "Your Homebrew uses other than the default installation directory prefix (i.e. /usr/local)."\
"Since FastR assumes the default prefix, use the following command to create a symbolic link to your Homebrew installations:"
echo " sudo ln -s $HOMEBREW_PREFIX/Cellar /usr/local/Cellar"
fi

exit 1
fi
else # not "which brew"
if [ $NO_BREW = 0 ]; then
echo "FastR depends on GFortran 3 runtime libraries."
echo "It appears that this system does not use the homebrew package manager."
echo "We suggest to use homebrew and install the necessary dependencies with:"
echo " brew install gcc@4.9"
echo "If you want to use another installation of GFortran 3 libraries, re-run this script with '--macos-no-homebrew'."
exit 2
fi

cd -P "$( dirname "$source" )/../lib"
# correct paths on Mac OSX
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
# This allows determining if all libraries were found after the main loop
GFORTRAN_LIBRARIES_CHECK="libgfortran libquadmath libgomp libgcc_s"
GFORTRAN_LOCATIONS="$GCC_LIB_PATH /opt/local/lib /opt/local/lib/libgcc /usr/local/gfortran/lib"
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
FOUND=""
FOUND_FULL=""
LAST_FOUND=""
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
do
# Remove the 'dylib' extension
GFORTRAN_LIB_BASE=${GFORTRAN_LIB%.*}
# Remove the number extension
GFORTRAN_LIB_BASE=${GFORTRAN_LIB_BASE%.*}
if [ "$LAST_FOUND" = "$GFORTRAN_LIB_BASE" ] ; then
# A previous version of the current library has already been found
echo "skipping $GFORTRAN_LIB"
continue;
fi
for LOCATION in $GFORTRAN_LOCATIONS
do
if test -f "${LOCATION}/${GFORTRAN_LIB}"; then
LIB_LOCATION="${LOCATION}/${GFORTRAN_LIB}"
FOUND="$FOUND $GFORTRAN_LIB_BASE"
LAST_FOUND=$GFORTRAN_LIB_BASE
echo "${GFORTRAN_LIB} found at ${LIB_LOCATION}"
for TARGET_LIB in $TARGET_LIBRARIES
do
# don't look at symlinks
if [ ! -L "${TARGET_LIB}" ] ; then
# grep for the current path of this gfortran library in this library's linking info
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB_BASE}[^ ]*"`
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
# change to the new location
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
FOUND_FULL="${FOUND_FULL}\n ${LIB_LOCATION}"
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
fi
fi
fi
done
break
fi
done
done
done

if [ "$FOUND" != " $GFORTRAN_LIBRARIES_CHECK" ] ; then
echo "From expected libraries '$GFORTRAN_LIBRARIES_CHECK' found only '$FOUND'."
echo "Please ensure that you have gcc installed on your system, e.g., using homebrew or MacPorts (brew install gcc)."
echo "If it is installed in a non-standard location, you can specify its location using the '--gcc-lib-path' parameter."
echo ""
printHelp
exit 1
fi

if [ "$FOUND" != " $GFORTRAN_LIBRARIES_CHECK" ] ; then
echo "From expected libraries '$GFORTRAN_LIBRARIES_CHECK' found only '$FOUND'."
echo "Please ensure that you have GFortran 3 installed on your system."
echo "We suggest to use homebrew and install the necessary dependencies with:"
echo " brew install gcc@4.9"
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."
exit 1
else
echo "Succesfully updated FastR installation to use the GFortran 3 system libraries."
FASTR_HOME=$(cd ..; pwd -P )
echo "The fortran compiler flags in $FASTR_HOME/etc/Makeconf (variable FLIBS) were not updated and must be adjusted manually!"
fi
fi # which brew
else
echo "Unknown operating system."
echo "FastR may still work."
Expand All @@ -221,16 +283,16 @@ fi
res=$?
if [[ $res != 0 ]]; then
echo "The configuration step failed."
echo "The log was saved into ${PWD}/configure.log"
echo "FastR may still work, but compilation of some R packages may fail"
exit 1
fi
ed Makeconf < edMakeconf.etc > /dev/null 2>/dev/null
export R_DEFAULT_PACKAGES=base
R_LIBS_USER=`"../bin/R" --slave -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))'`
echo "Creating user specific library directory: $R_LIBS_USER"
mkdir -p "$R_LIBS_USER"
echo "DONE"
echo "The log was saved into ${PWD}/configure.log"
echo "FastR may still work, but compilation of some R packages may fail"
exit 1
fi
ed Makeconf < edMakeconf.etc > /dev/null 2>/dev/null
export R_DEFAULT_PACKAGES=base
R_LIBS_USER=`"../bin/R" --slave -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))'`
echo "Creating user specific library directory: $R_LIBS_USER"
mkdir -p "$R_LIBS_USER"
echo "DONE"
fi

)
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public static String tildeExpand(String path, boolean keepRelative) {
if (path.length() == 0) {
return keepRelative ? path : wdState().getCurrentPath().getPath();
} else {
TruffleFile p = FileSystemUtils.getSafeTruffleFile(RContext.getInstance().getEnv(), path);
TruffleFile p = RContext.getInstance().getEnv().getInternalTruffleFile(path);
if (p.isAbsolute()) {
return path;
} else {
Expand Down

0 comments on commit d93857d

Please sign in to comment.