From 97aee7d1e67ee3d26d28faaf57b16ae3756b46c0 Mon Sep 17 00:00:00 2001 From: Florian Angerer <florian.angerer@oracle.com> Date: Tue, 1 Aug 2017 14:26:17 +0200 Subject: [PATCH] Resolving relative source paths to known library paths. --- .../com/oracle/truffle/r/runtime/RSource.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java index 0f9f1bcd62..5ab18442c0 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java @@ -27,12 +27,14 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.r.runtime.RSrcref.SrcrefFields; +import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.env.REnvironment; @@ -200,8 +202,18 @@ public class RSource { if (filename.isAbsolute()) { return fromFileName(filename.toString(), false); } - Path rHomePath = Paths.get(REnvVars.rHome()); - return fromFileName(rHomePath.resolve(filename).toString(), false); + Path resolved = filename; + if (!filename.isAbsolute()) { + for (String libPath : RContext.getInstance().libraryPaths) { + resolved = Paths.get(libPath).resolve(filename); + if (Files.exists(resolved)) { + break; + } + } + } else { + resolved = filename; + } + return fromFileName(resolved.toString(), false); } private static String getPath(REnvironment env, String name) { -- GitLab