From abd23b0b7bcebbac5aac2538d7f3ac9d4d1c8cff Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Thu, 27 Oct 2016 09:19:29 -0700
Subject: [PATCH] refactor REnvVars for substitution in AOT environment

---
 .../src/com/oracle/truffle/r/runtime/REnvVars.java       | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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 5afd1a8ca0..f7a95a1b4b 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
@@ -161,7 +161,7 @@ public final class REnvVars implements RContext.ContextState {
                  * The only time this can happen legitimately is when run under the graalvm shell,
                  * which does not execute the shell script that normally sets R_HOME.
                  */
-                rHomePath = Paths.get(REnvVars.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent();
+                rHomePath = getRHomePath();
             } else {
                 rHomePath = Paths.get(rHome);
             }
@@ -175,6 +175,13 @@ public final class REnvVars implements RContext.ContextState {
         return rHome;
     }
 
+    /**
+     * Separated for substitution in AOT environment.
+     */
+    private static Path getRHomePath() {
+        return Paths.get(REnvVars.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent();
+    }
+
     private void checkRHome() {
         String envRHome = envVars.get(R_HOME);
         if (envRHome == null) {
-- 
GitLab