Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cfa4f8a6dc13
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a9cda0978d0b
Choose a head ref
  • 6 commits
  • 10 files changed
  • 1 contributor

Commits on Nov 11, 2016

  1. Copy the full SHA
    42de769 View commit details
  2. [Truffle] Fix if $0 == __FILE__ for the nth time...

    * For the main Source, getName() is just the path passed to ruby:
      $ ruby ./foo/bar.rb => "./foo/bar.rb"
      and getPath() is the expanded path.
      For other files, both are the expanded path.
    eregon committed Nov 11, 2016
    Copy the full SHA
    ea9e268 View commit details
  3. Copy the full SHA
    924cd41 View commit details
  4. Copy the full SHA
    2eb0766 View commit details
  5. [Truffle] Fix some bad code.

    * Source can never be null with the new API.
    eregon committed Nov 11, 2016
    Copy the full SHA
    224fe53 View commit details
  6. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a9cda09 View commit details
1 change: 0 additions & 1 deletion spec/truffle/tags/language/predefined_tags.txt
Original file line number Diff line number Diff line change
@@ -6,4 +6,3 @@ slow:The predefined global constant ARGV contains Strings encoded in locale Enco
linux:Global variable $0 actually sets the program name
slow:Global variable $0 is the path given as the main script and the same as __FILE__
slow:Global variable $? is thread-local
fails:Global variable $0 is the path given as the main script and the same as __FILE__
24 changes: 20 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/RubyContext.java
Original file line number Diff line number Diff line change
@@ -115,8 +115,8 @@ public class RubyContext extends ExecutionContext {

public RubyContext(RubyInstanceConfig instanceConfig, TruffleLanguage.Env env) {
this.instanceConfig = instanceConfig;
jrubyHome = findJRubyHome();
this.env = env;
this.jrubyHome = setupJRubyHome();
this.currentDirectory = System.getProperty("user.dir");

if (options.CALL_GRAPH) {
@@ -207,6 +207,12 @@ public RubyContext(RubyInstanceConfig instanceConfig, TruffleLanguage.Env env) {
}
}

private String setupJRubyHome() {
String jrubyHome = findJRubyHome();
instanceConfig.setJRubyHome(jrubyHome);
return jrubyHome;
}

private String findJRubyHome() {
if (!TruffleOptions.AOT && System.getenv("JRUBY_HOME") == null && System.getProperty("jruby.home") == null) {
// Set JRuby home automatically for GraalVM
@@ -220,10 +226,20 @@ private String findJRubyHome() {
}

if (currentJarFile.getName().equals("ruby.jar")) {
String jarDir = currentJarFile.getParent();
File jarDir = currentJarFile.getParentFile();

// GraalVM
if (new File(jarDir, "lib").isDirectory()) {
instanceConfig.setJRubyHome(jarDir);
return jarDir;
return jarDir.getPath();
}

// mx: mxbuild/dists/ruby.jar
if (jarDir.getName().equals("dists") && jarDir.getParentFile().getName().equals("mxbuild")) {
String mxbuildDir = currentJarFile.getParentFile().getParent();
File mxJRubyHome = new File(mxbuildDir, "ruby-zip-extracted");
if (mxJRubyHome.isDirectory()) {
return mxJRubyHome.getPath();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1495,13 +1495,7 @@ private String getFullPath(final String featureString) {
featurePath = featureString;
} else {
final Source source = getContext().getCallStack().getCallerFrameIgnoringSend().getCallNode().getEncapsulatingSourceSection().getSource();
String result;
if (source.getName() == null) {
result = null;
} else {
result = source.getName();
}
final String sourcePath = result;
final String sourcePath = source.getPath();

if (sourcePath == null) {
throw new RaiseException(coreExceptions().loadError("cannot infer basepath", featureString, this));
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.builtins.CoreClass;
@@ -26,8 +27,7 @@
@CoreClass("Thread::Backtrace::Location")
public class ThreadBacktraceLocationNodes {

@CoreMethod(names = { "absolute_path", "path" })
// TODO (eregon, 8 July 2015): these two methods are slightly different (path can be relative if it is the main script)
@CoreMethod(names = "absolute_path")
public abstract static class AbsolutePathNode extends UnaryCoreMethodNode {

@TruffleBoundary
@@ -40,14 +40,43 @@ public DynamicObject absolutePath(DynamicObject threadBacktraceLocation) {
}

final SourceSection sourceSection = activation.getCallNode().getEncapsulatingSourceSection();
final Source source = sourceSection.getSource();
if (source == null) {
return coreStrings().UNKNOWN.createInstance();
}

if (sourceSection.getSource() == null) {
return createString(StringOperations.encodeRope(String.format("%s:%d", sourceSection.getSource().getName(), sourceSection.getStartLine()), UTF8Encoding.INSTANCE));
// Get absolute path
final String path = source.getPath();

if (path == null) {
return coreStrings().UNKNOWN.createInstance();
} else {
return createString(getContext().getRopeTable().getRope(path));
}
}

}

@CoreMethod(names = "path")
public abstract static class PathNode extends UnaryCoreMethodNode {

@TruffleBoundary
@Specialization
public DynamicObject path(DynamicObject threadBacktraceLocation) {
final Activation activation = ThreadBacktraceLocationLayoutImpl.INSTANCE.getActivation(threadBacktraceLocation);

if (activation.getCallNode() == null) {
return coreStrings().BACKTRACE_OMITTED_LIMIT.createInstance();
}

// TODO CS 30-Apr-15: not absolute - not sure how to solve that
final SourceSection sourceSection = activation.getCallNode().getEncapsulatingSourceSection();
final Source source = sourceSection.getSource();
if (source == null) {
return coreStrings().UNKNOWN.createInstance();
}

final String path = sourceSection.getSource().getName();
// Get file path except for the main script
final String path = source.getName();

if (path == null) {
return coreStrings().UNKNOWN.createInstance();
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public Object execute(VirtualFrame frame) {
final Object data = snippetNode.execute(frame,
"Truffle.get_data(file, offset)",
"file", StringOperations.createString(getContext(),
ByteListUtils.create(getEncapsulatingSourceSection().getSource().getName())),
ByteListUtils.create(getEncapsulatingSourceSection().getSource().getPath())),
"offset", endPosition);

Layouts.MODULE.getFields(coreLibrary().getObjectClass()).setConstant(getContext(), null, "DATA", data);
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ public Object main(VirtualFrame frame, @Cached("create()") IndirectCallNode call

final Source source;
try {
source = getContext().getSourceCache().getSource(inputFile);
source = getContext().getSourceCache().getMainSource(inputFile);
} catch (IOException e) {
throw new JavaException(e);
}
Original file line number Diff line number Diff line change
@@ -151,8 +151,6 @@ public String formatLine(List<Activation> activations, int n, DynamicObject exce

if (reportedSourceSection == null) {
builder.append("???");
} else if (reportedSourceSection.getSource() == null) {
builder.append(String.format("%s:%d", reportedSourceSection.getSource().getName(), reportedSourceSection.getStartLine()));
} else {
builder.append(reportedSourceSection.getSource().getName());
builder.append(":");
@@ -214,8 +212,8 @@ private SourceSection nextUserSourceSection(List<Activation> activations, int n)
return null;
}

public static boolean isJavaCore(SourceSection sourceSection) {
return sourceSection != null && sourceSection.getSource() == null;
public boolean isJavaCore(SourceSection sourceSection) {
return sourceSection == context.getCoreLibrary().getSourceSection();
}

public static boolean isCore(RubyContext context, SourceSection sourceSection) {
@@ -267,19 +265,16 @@ private String formatForeign(Node callNode) {
if (sourceSection != null) {
final String shortDescription = String.format("%s:%d", sourceSection.getSource().getName(), sourceSection.getStartLine());

if (shortDescription.trim().equals(":")) {
throw new UnsupportedOperationException();
} else {
builder.append(shortDescription);

final RootNode rootNode = callNode.getRootNode();
final String identifier = rootNode.getName();
builder.append(shortDescription);

if (identifier != null && !identifier.isEmpty()) {
builder.append(":in `");
builder.append(identifier);
builder.append("'");
}
final RootNode rootNode = callNode.getRootNode();
final String identifier = rootNode.getName();

if (identifier != null && !identifier.isEmpty()) {
builder.append(":in `");
builder.append(identifier);
builder.append("'");
}
} else {
builder.append(getRootOrTopmostNode(callNode).getClass().getSimpleName());
Original file line number Diff line number Diff line change
@@ -29,6 +29,13 @@ public SourceCache(SourceLoader loader) {
this.loader = loader;
}

@TruffleBoundary
public synchronized Source getMainSource(String path) throws IOException {
Source mainSource = loader.loadMain(path);
sources.put(path, mainSource);
return mainSource;
}

@TruffleBoundary
public synchronized Source getSource(String canonicalPath) throws IOException {
Source source = sources.get(canonicalPath);
Original file line number Diff line number Diff line change
@@ -38,17 +38,25 @@ public SourceLoader(RubyContext context) {
}

@TruffleBoundary
public Source load(String canonicalPath) throws IOException {
if (canonicalPath.equals("-e")) {
public Source loadMain(String path) throws IOException {
if (path.equals("-e")) {
return loadFragment(new String(context.getInstanceConfig().inlineScript(), StandardCharsets.UTF_8), "-e");
} else if (canonicalPath.startsWith(TRUFFLE_SCHEME) || canonicalPath.startsWith(JRUBY_SCHEME)) {
} else {
final File file = new File(path).getCanonicalFile();
ensureReadable(path, file);

// The main source file *must* be named as it's given for __FILE__
return Source.newBuilder(file).name(path).mimeType(RubyLanguage.MIME_TYPE).build();
}
}

@TruffleBoundary
public Source load(String canonicalPath) throws IOException {
if (canonicalPath.startsWith(TRUFFLE_SCHEME) || canonicalPath.startsWith(JRUBY_SCHEME)) {
return loadResource(canonicalPath);
} else {
final File file = new File(canonicalPath).getCanonicalFile();

if (!file.canRead()) {
throw new IOException("Can't read file " + canonicalPath);
}
ensureReadable(canonicalPath, file);

if (canonicalPath.toLowerCase().endsWith(".su")) {
return Source.newBuilder(file).name(file.getPath()).mimeType(RubyLanguage.CEXT_MIME_TYPE).build();
@@ -93,4 +101,10 @@ private Source loadResource(String path) throws IOException {
return Source.newBuilder(new InputStreamReader(stream, StandardCharsets.UTF_8)).name(path).mimeType(RubyLanguage.MIME_TYPE).build();
}

private static void ensureReadable(String path, File file) throws IOException {
if (!file.canRead()) {
throw new IOException("Can't read file " + path);
}
}

}
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ private void write(Method method) {
if (sourceSection == null || sourceSection.getSource() == null) {
sourceName = "(unknown)";
} else {
sourceName = sourceSection.getSource().getName();
sourceName = sourceSection.getSource().getPath();
}

final int startLine;