From fb479bb9546b56e64b48dfb4d5b21b6ee537a9b1 Mon Sep 17 00:00:00 2001 From: Mick Jordan <mick.jordan@oracle.com> Date: Thu, 16 Feb 2017 09:46:35 -0800 Subject: [PATCH] [GR-2857] Fix location of gnur Rscript under graalvm testing. --- .../r/install.cran.packages.R | 22 +++++++++++++++---- mx.fastr/mx_fastr_pkgs.py | 21 +++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/com.oracle.truffle.r.test.cran/r/install.cran.packages.R b/com.oracle.truffle.r.test.cran/r/install.cran.packages.R index a92c95ff4a..a9e905e9a5 100644 --- a/com.oracle.truffle.r.test.cran/r/install.cran.packages.R +++ b/com.oracle.truffle.r.test.cran/r/install.cran.packages.R @@ -1,5 +1,5 @@ # -# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -684,10 +684,24 @@ install.pkg <- function(pkgname) { return(rc) } +# when testing under graalvm, fastr is not built so we must use the (assumed) sibling gnur repo +check_graalvm <- function() { + if (!is.na(Sys.getenv('FASTR_GRAALVM', unset=NA)) || !is.na(Sys.getenv('GRAALVM_FASTR', unset=NA))) { + normalizePath(Sys.glob(file.path("..", 'gnur', 'gnur', 'R-*'))) + } else { + NA + } +} + gnu_rscript <- function() { - rv <- R.Version() - dirv <- paste0('R-', rv$major, '.', rv$minor) - file.path("com.oracle.truffle.r.native/gnur", dirv, 'bin/Rscript') + gnur_dir <- check_graalvm() + if (!is.na(gnur_dir)) { + file.path(gnur_dir, 'bin', 'Rscript') + } else { + rv <- R.Version() + dirv <- paste0('R-', rv$major, '.', rv$minor) + file.path("com.oracle.truffle.r.native/gnur", dirv, 'bin', 'Rscript') + } } system.install <- function(pkgname) { diff --git a/mx.fastr/mx_fastr_pkgs.py b/mx.fastr/mx_fastr_pkgs.py index 874dbf5e65..730622e8a3 100644 --- a/mx.fastr/mx_fastr_pkgs.py +++ b/mx.fastr/mx_fastr_pkgs.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2016, 2016, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ The pkgtest command operates in two modes: 1. In development mode it uses the FastR 'Rscript' command and the internal GNU R for test comparison 2. In production mode it uses the GraalVM 'Rscript' command and a GNU R loaded as a sibling suite. This is indicated -by the environment variable 'GRAALVM_FASTR' being set. +by the environment variable 'FASTR_GRAALVM' being set. (GRAALVM_FASTR is also accepted for backwards cmpatibility) Evidently in case 2, there is the potential for a version mismatch between FastR and GNU R, and this is checked. @@ -48,17 +48,28 @@ def _mx_gnur(): return mx.suite('gnur') def _gnur_rscript(): + ''' + returns path to Rscript in sibling gnur directory + ''' return _mx_gnur().extensions._gnur_rscript_path() def _graalvm_rscript(): assert graalvm is not None return join(graalvm, 'bin', 'Rscript') +def _check_graalvm(): + if os.environ.has_key('FASTR_GRAALVM'): + return os.environ['FASTR_GRAALVM'] + elif os.environ.has_key('GRAALVM_FASTR'): + return os.environ['GRAALVM_FASTR'] + else: + return None + def _graalvm(): global graalvm if graalvm is None: - if os.environ.has_key('GRAALVM_FASTR'): - graalvm = os.environ['GRAALVM_FASTR'] + graalvm = _check_graalvm() + if graalvm: # version check gnur_version = _mx_gnur().extensions.r_version().split('-')[1] graalvm_version = subprocess.check_output([_graalvm_rscript(), '--version'], stderr=subprocess.STDOUT).rstrip() @@ -106,7 +117,7 @@ def _installpkgs(args, **kwargs): ''' Runs the R script that does package/installation and testing. If we are running in a binary graalvm environment, which is indicated - by the GRAALVM_FASTR environment variable, we can't use mx to invoke + by the FASTR_GRAALVM environment variable, we can't use mx to invoke FastR, but instead have to invoke the command directly. ''' script = _installpkgs_script() -- GitLab