diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCmdOptions.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCmdOptions.java index fd43291f7742370fd53d4fe7945217a52a595c4c..7dede920464e9dee1ba9b5a4401f642943868fe8 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCmdOptions.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCmdOptions.java @@ -68,7 +68,6 @@ public final class RCmdOptions { HELP(RCmdOptionType.BOOLEAN, true, "h", "help", false, "Print short help message and exit"), VERSION(RCmdOptionType.BOOLEAN, true, "version", false, "Print version info and exit"), ENCODING(RCmdOptionType.STRING, false, "encoding=ENC", null, "Specify encoding to be used for stdin"), - RHOME(RCmdOptionType.BOOLEAN, true, "RHOME", false, "Print path to R home directory and exit"), SAVE(RCmdOptionType.BOOLEAN, true, "save", false, "Do save workspace at the end of the session"), NO_SAVE(RCmdOptionType.BOOLEAN, true, "no-save", false, "Don't save it"), NO_ENVIRON(RCmdOptionType.BOOLEAN, false, "no-environ", false, "Don't read the site and user environment files"), @@ -129,7 +128,7 @@ public final class RCmdOptions { this.name = null; this.suffix = null; } else { - int eqx = noPrefix(name) ? -1 : name.indexOf('='); + int eqx = name.indexOf('='); this.name = "--" + (eqx > 0 ? name.substring(0, eqx) : name); this.suffix = eqx > 0 ? name.substring(eqx) : null; } @@ -145,10 +144,6 @@ public final class RCmdOptions { this(type, Client.EITHER, implemented, null, name, defaultValue, help); } - private static boolean noPrefix(String arg) { - return arg.equals("RHOME") || arg.equals("CMD"); - } - private boolean matches(String arg) { if (shortName != null && arg.equals(shortName)) { return true; @@ -354,8 +349,6 @@ public final class RCmdOptions { printHelpAndExit(RCmdOptions.Client.R); } else if (getBoolean(VERSION)) { printVersionAndExit(); - } else if (getBoolean(RHOME)) { - printRHomeAndExit(); } } @@ -380,8 +373,4 @@ public final class RCmdOptions { System.exit(0); } - private static void printRHomeAndExit() { - System.out.println(REnvVars.rHome()); - System.exit(0); - } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java index 639567f9d1f71994c2169496a674864023cec750..671ed65ee0d590215af10854458b164329e8e6fc 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/REnvVars.java @@ -48,7 +48,7 @@ public final class REnvVars implements RContext.ContextState { String envRHomePath = envVars.get("R_HOME"); if (envRHomePath != null) { new File(envRHomePath).getAbsolutePath(); - if (!envRHomePath.equals(rHomePath)) { + if (!envRHomePath.equals(rHome)) { Utils.fail("R_HOME set to unexpected value in the environment"); } } @@ -117,29 +117,25 @@ public final class REnvVars implements RContext.ContextState { return val != null ? val : envVars.get(var.toUpperCase()); } - private static String rHomePath; - public static String rHome() { - // This can be called before initialize, "R RHOME" - if (rHomePath == null) { - String path = System.getProperty("rhome.path"); - if (path != null) { - rHomePath = path; - } else { - File file = new File(System.getProperty("user.dir")); - do { - File binR = new File(new File(file, "bin"), "R"); - if (binR.exists()) { - break; - } else { - file = file.getParentFile(); - } - } while (file != null); - if (file != null) { - rHomePath = file.getAbsolutePath(); + String rHomePath = null; + String path = System.getProperty("rhome.path"); + if (path != null) { + rHomePath = path; + } else { + File file = new File(System.getProperty("user.dir")); + do { + File binR = new File(new File(file, "bin"), "R"); + if (binR.exists()) { + break; } else { - Utils.fail("cannot find a valid R_HOME"); + file = file.getParentFile(); } + } while (file != null); + if (file != null) { + rHomePath = file.getAbsolutePath(); + } else { + Utils.fail("cannot find a valid R_HOME"); } } return rHomePath; diff --git a/mx.fastr/mx_fastr.py b/mx.fastr/mx_fastr.py index ee212a8b9c2861006053cf254cbb3faececbe1dc..01597640bbc332184d14b54f05006352597a4b92 100644 --- a/mx.fastr/mx_fastr.py +++ b/mx.fastr/mx_fastr.py @@ -20,7 +20,7 @@ # or visit www.oracle.com if you need additional information or have any # questions. # -import tempfile, platform, subprocess +import tempfile, platform, subprocess, sys from os.path import join, sep, dirname, abspath from argparse import ArgumentParser import mx @@ -188,6 +188,16 @@ def run_r(args, command, parser=None, extraVmArgs=None, jdk=None, nonZeroIsFatal if not jdk and ns.jdk: jdk = mx.get_jdk(tag=ns.jdk) + + # special cases normally handled in shell script startup + if command == 'r' and len(rargs) > 0: + if rargs[0] == 'RHOME': + print _fastr_suite.dir + sys.exit(0) + elif rargs[0] == 'CMD': + print 'CMD not implemented via mx, use: bin/R CMD ...' + sys.exit(1) + return do_run_r(rargs, command, extraVmArgs=extraVmArgs, jdk=jdk, nonZeroIsFatal=nonZeroIsFatal) def rshell(args):