From a287b7efc40cf0da4af8245c09dfc369a836b7e9 Mon Sep 17 00:00:00 2001 From: Mick Jordan <mick.jordan@oracle.com> Date: Thu, 17 Mar 2016 14:11:10 -0700 Subject: [PATCH] sync mx_fastr.rtestgen up with FASTR_TESTGEN_GNUR option; allow latter to specify a specific R home --- .../truffle/r/runtime/RVersionNumber.java | 1 + .../r/test/generate/GnuROneShotRSession.java | 25 ++++++++++---- mx.fastr/mx_fastr.py | 33 ++++++++++++++----- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RVersionNumber.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RVersionNumber.java index 7bb6438454..55e87678b8 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RVersionNumber.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RVersionNumber.java @@ -40,6 +40,7 @@ public class RVersionNumber { public static final String MAJOR_MINOR = MAJOR + "." + MINOR; public static final String MINOR_PATCH = MINOR + "." + PATCH; public static final String FULL = MAJOR + "." + MINOR + "." + PATCH; + public static final String R_HYPHEN_FULL = "R-" + FULL; public static final String RELEASE_YEAR = "2016"; public static final String RELEASE_MONTH = "03"; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/GnuROneShotRSession.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/GnuROneShotRSession.java index f42d927c67..c23ac7cdce 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/GnuROneShotRSession.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/GnuROneShotRSession.java @@ -38,13 +38,14 @@ import com.oracle.truffle.r.test.TestBase; * currently some differences in behavior (TBD). Which R is used is controlled by the environment * variable {@code FASTR_TESTGEN_GNUR}. If unset, we take the default, which is currently the system * installed version (more precisely whatever "R" resolves to on the PATH). If - * {@code FASTR_TESTGEN_GNUR} is set to {@code internal}, we use the internally built GnuR. Any - * other value behaves as if it was unset. {@code PATH}. + * {@code FASTR_TESTGEN_GNUR} is set to {@code internal} or the empty string, we use the internally + * built GnuR. Any other value is treated as a path to a directory assumed to contain an R HOME, i.e + * the executable used is {@code $FASTR_TESTGEN_GNUR/bin/R}. */ public class GnuROneShotRSession implements RSession { private static final String[] GNUR_COMMANDLINE = new String[]{"R", "--vanilla", "--slave", "--silent"}; - private static final String SYSTEM_GNUR_ENV = "FASTR_TESTGEN_GNUR"; + private static final String FASTR_TESTGEN_GNUR = "FASTR_TESTGEN_GNUR"; private static final String NATIVE_PROJECT = "com.oracle.truffle.r.native"; //@formatter:off @@ -61,10 +62,15 @@ public class GnuROneShotRSession implements RSession { protected static byte[] QUIT = "q()\n".getBytes(); protected Process createGnuR() throws IOException { - String testGenGnuR = System.getenv(SYSTEM_GNUR_ENV); - if (testGenGnuR != null && testGenGnuR.equals("internal")) { - Path gnuRPath = FileSystems.getDefault().getPath(REnvVars.rHome(), NATIVE_PROJECT, "gnur", "R-" + RVersionNumber.FULL, "bin", "R"); - GNUR_COMMANDLINE[0] = gnuRPath.toString(); + String testGenGnuR = System.getenv(FASTR_TESTGEN_GNUR); + if (testGenGnuR != null) { + if (testGenGnuR.length() == 0 || testGenGnuR.equals("internal")) { + Path gnuRPath = FileSystems.getDefault().getPath(REnvVars.rHome(), NATIVE_PROJECT, "gnur", RVersionNumber.R_HYPHEN_FULL, "bin", "R"); + GNUR_COMMANDLINE[0] = gnuRPath.toString(); + } else { + GNUR_COMMANDLINE[0] = FileSystems.getDefault().getPath(testGenGnuR, "bin", "R").toString(); + } + } ProcessBuilder pb = new ProcessBuilder(GNUR_COMMANDLINE); // fix time zone to "CET" (to create consistent expected output) @@ -114,4 +120,9 @@ public class GnuROneShotRSession implements RSession { public String name() { return "GnuR one-shot"; } + + public static void main(String[] args) { + String testGenGnuR = System.getenv(FASTR_TESTGEN_GNUR); + System.out.printf("%s='%s'%n", FASTR_TESTGEN_GNUR, testGenGnuR); + } } diff --git a/mx.fastr/mx_fastr.py b/mx.fastr/mx_fastr.py index 88ca3bf219..dd060c203f 100644 --- a/mx.fastr/mx_fastr.py +++ b/mx.fastr/mx_fastr.py @@ -436,14 +436,31 @@ def testgen(args): # check we are in the home directory if os.getcwd() != _fastr_suite.dir: mx.abort('must run rtestgen from FastR home directory') - # check the version of GnuR against FastR - try: - fastr_version = subprocess.check_output([mx.get_jdk().java, '-cp', mx.classpath('com.oracle.truffle.r.runtime'), 'com.oracle.truffle.r.runtime.RVersionNumber']) - gnur_version = subprocess.check_output(['R', '--version']) - if not gnur_version.startswith(fastr_version): - mx.abort('R version is incompatible with FastR, please update to ' + fastr_version) - except subprocess.CalledProcessError: - mx.abort('RVersionNumber.main failed') + + def need_version_check(): + vardef = os.environ.has_key('FASTR_TESTGEN_GNUR') + varval = os.environ['FASTR_TESTGEN_GNUR'] if vardef else None + version_check = not vardef or varval != 'internal' + if version_check: + if vardef and varval != 'internal': + rpath = join(varval, 'bin', 'R') + else: + rpath = 'R' + else: + rpath = None + return version_check, rpath + + version_check, rpath = need_version_check() + if version_check: + # check the version of GnuR against FastR + try: + fastr_version = subprocess.check_output([mx.get_jdk().java, '-cp', mx.classpath('com.oracle.truffle.r.runtime'), 'com.oracle.truffle.r.runtime.RVersionNumber']) + gnur_version = subprocess.check_output([rpath, '--version']) + if not gnur_version.startswith(fastr_version): + mx.abort('R version is incompatible with FastR, please update to ' + fastr_version) + except subprocess.CalledProcessError: + mx.abort('RVersionNumber.main failed') + # clean the test project to invoke the test analyzer AP testOnly = ['--projects', 'com.oracle.truffle.r.test'] mx.clean(['--no-dist', ] + testOnly) -- GitLab