Skip to content
Snippets Groups Projects
Commit d231a024 authored by Stepan Sindelar's avatar Stepan Sindelar
Browse files

[GR-7027] Fix FastRHelp and add native-image configuration.

PullRequest: fastr/1366
parents 81520125 6ad1891f
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
......@@ -80,7 +80,6 @@ public class EagerResourceHandlerFactory extends ResourceHandlerFactory implemen
String fileName = Paths.get(name).getFileName().toString();
FileInfo fileInfo = files.get(fileName);
if (fileInfo == null || fileInfo.data == null) {
RInternalError.shouldNotReachHere("getResourceAsStream: failed to find resource: " + name);
return null;
} else {
return new ByteArrayInputStream(fileInfo.data);
......@@ -92,23 +91,6 @@ public class EagerResourceHandlerFactory extends ResourceHandlerFactory implemen
return this;
}
public static boolean addResource(@SuppressWarnings("unused") Class<?> accessor, String name, String path, boolean capture) {
byte[] bytes = null;
if (capture) {
try {
bytes = Files.readAllBytes(Paths.get(path));
} catch (IOException ex) {
return false;
}
}
try {
files.put(name, new FileInfo(name, new URL("file://" + path), bytes));
} catch (MalformedURLException ex) {
RInternalError.shouldNotReachHere("addResource " + ex.getMessage());
}
return true;
}
private static void gatherResources() {
CodeSource source = RBuiltinPackage.class.getProtectionDomain().getCodeSource();
try {
......@@ -118,7 +100,7 @@ public class EagerResourceHandlerFactory extends ResourceHandlerFactory implemen
while (iter.hasMoreElements()) {
JarEntry entry = iter.nextElement();
String name = entry.getName();
if (name.endsWith(".R") || name.endsWith("CONTRIBUTORS")) {
if (name.endsWith(".R") || name.endsWith("CONTRIBUTORS") || name.endsWith(".Rd")) {
int size = (int) entry.getSize();
byte[] buf = new byte[size];
InputStream is = fastrJar.getInputStream(entry);
......@@ -142,9 +124,10 @@ public class EagerResourceHandlerFactory extends ResourceHandlerFactory implemen
public Map<String, String> getRFiles(Class<?> accessor, String pkgName) {
Map<String, String> result = new HashMap<>();
for (Map.Entry<String, FileInfo> entry : files.entrySet()) {
if (entry.getValue().url.toString().contains(pkgName + "/R")) {
String url = entry.getValue().url.toString();
if (url.endsWith(".R") && url.contains(pkgName + "/R")) {
String content = new String(entry.getValue().data);
result.put(entry.getValue().url.toString(), content);
result.put(url, content);
}
}
return result;
......
......@@ -32,6 +32,8 @@ import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.runtime.RError;
import static com.oracle.truffle.r.runtime.RVisibility.ON;
import com.oracle.truffle.r.runtime.ResourceHandlerFactory;
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.data.RNull;
import java.io.BufferedReader;
......@@ -53,12 +55,11 @@ public class FastRHelp {
@TruffleBoundary
public Object helpPath(String builtinName) {
String path = "/com/oracle/truffle/r/nodes/builtin/base/Rd/" + builtinName + ".Rd";
try (InputStream in = getClass().getResourceAsStream(path)) {
try (InputStream in = ResourceHandlerFactory.getHandler().getResourceAsStream(getClass(), path)) {
if (in != null) {
return path;
}
} catch (IOException ex) {
}
return RNull.instance;
}
......@@ -75,7 +76,7 @@ public class FastRHelp {
@Specialization()
@TruffleBoundary
public Object getHelpRdPath(String path) {
try (InputStream in = getClass().getResourceAsStream(path)) {
try (InputStream in = ResourceHandlerFactory.getHandler().getResourceAsStream(getClass(), path)) {
if (in != null) {
try (BufferedReader r = new BufferedReader(new InputStreamReader(in))) {
StringBuilder sb = new StringBuilder();
......
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2018, 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
......@@ -105,7 +105,7 @@ class LazyResourceHandlerFactory extends ResourceHandlerFactory implements Handl
}
return result;
} catch (Exception ex) {
Utils.rSuicide(ex.getMessage());
Utils.rSuicide(ex, "Could not load R files from resources. Details: " + ex.getMessage());
return null;
}
}
......
# This file contains native-image arguments needed to fastr
#
ImageName = R
Requires = Tool:nfi
JavaArgs = \
-Dfastr.resource.factory.class=com.oracle.truffle.r.nodes.builtin.EagerResourceHandlerFactory \
-Dfastr.internal.grid.awt.support=false \
-Xmx6G
Args = -H:Class=com.oracle.truffle.r.launcher.RCommand
......@@ -70,7 +70,7 @@ suite = {
"sha1" : "0baa82bff19059401e90e1b90020beb9c96305d7",
"maven" : {
"groupId" : "org.antlr",
"artifactId" : "antlr",
"artifactId" : "antlr-runtime",
"version" : "3.5",
},
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment