diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/EagerResourceHandlerFactory.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/EagerResourceHandlerFactory.java index a9e8526f52283062b09dea5a4f1a1e95e6547f38..039455b5ba9d9b3f5ea6971b8594bcbe0cf9a8cb 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/EagerResourceHandlerFactory.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/EagerResourceHandlerFactory.java @@ -1,5 +1,5 @@ /* - * 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; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRHelp.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRHelp.java index 527e6e9b7b4746d7444d3e9b385738ab418d729d..4f0b1b556ea0b1cf38d57e052541a02c2e824dbc 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRHelp.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRHelp.java @@ -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(); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/LazyResourceHandlerFactory.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/LazyResourceHandlerFactory.java index 649c8a0e75539d024400ba2656fed85353fe6ad6..800c0766252977ae0b60142035f71a557b82add2 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/LazyResourceHandlerFactory.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/LazyResourceHandlerFactory.java @@ -1,5 +1,5 @@ /* - * 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; } } diff --git a/mx.fastr/native-image.properties b/mx.fastr/native-image.properties new file mode 100644 index 0000000000000000000000000000000000000000..bc39dee0193ce6fe9ee71b3c8f9ccdab91df0961 --- /dev/null +++ b/mx.fastr/native-image.properties @@ -0,0 +1,13 @@ +# 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 diff --git a/mx.fastr/suite.py b/mx.fastr/suite.py index 36c3ba4f598bd9f0a2ef12b38b8783792ecd9311..cb8a7898625867f2a0a30956c90839d35fc7779e 100644 --- a/mx.fastr/suite.py +++ b/mx.fastr/suite.py @@ -70,7 +70,7 @@ suite = { "sha1" : "0baa82bff19059401e90e1b90020beb9c96305d7", "maven" : { "groupId" : "org.antlr", - "artifactId" : "antlr", + "artifactId" : "antlr-runtime", "version" : "3.5", }, },