Navigation Menu

Skip to content

Commit

Permalink
[Truffle] Support proper File.expand_path semantics on Windows.
Browse files Browse the repository at this point in the history
We're delegating out to non-Truffle JRuby for this.  Correctness > speed.
  • Loading branch information
nirvdrum committed Feb 11, 2015
1 parent 040a613 commit fec1f7a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
3 changes: 0 additions & 3 deletions spec/truffle/truffle.mspec
Expand Up @@ -109,6 +109,3 @@ class MSpecScript
set :files, get(:language) + get(:core) + get(:rubysl)

end

# TODO (nirvdrum 11-Feb-15) Remove this hack once our File.expand_path doesn't translate '\' & '/' ... until then, we need feed this path through it to get consistent results in the specs.
SPEC_TEMP_DIR = File.expand_path "#{File.expand_path(Dir.pwd)}/rubyspec_temp"
Expand Up @@ -277,7 +277,7 @@ public ExpandPathNode(ExpandPathNode prev) {

@Specialization
public RubyString expandPath(RubyString path, @SuppressWarnings("unused") UndefinedPlaceholder dir) {
return getContext().makeString(RubyFile.expandPath(path.toString()));
return getContext().makeString(RubyFile.expandPath(getContext(), path.toString()));
}

@Specialization
Expand Down
Expand Up @@ -72,6 +72,8 @@ public class RubyContext extends ExecutionContext {

private final AtomicLong nextObjectID = new AtomicLong(ObjectIDOperations.FIRST_OBJECT_ID);

private final boolean runningOnWindows;

public RubyContext(Ruby runtime) {
assert runtime != null;

Expand Down Expand Up @@ -116,6 +118,8 @@ public RubyContext(Ruby runtime) {
if (Options.TRUFFLE_STACK_SERVER_PORT.load() != 0) {
new StackServerManager(this, Options.TRUFFLE_STACK_SERVER_PORT.load()).start();
}

runningOnWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
}

public Shape getEmptyShape() {
Expand All @@ -142,6 +146,10 @@ public static String checkClassVariableName(RubyContext context, String name, Ru
return name;
}

public boolean isRunningOnWindows() {
return runningOnWindows;
}

public void loadFile(String fileName, RubyNode currentNode) {
if (new File(fileName).isAbsolute()) {
loadFileAbsolute(fileName, currentNode);
Expand Down
17 changes: 15 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/runtime/core/RubyFile.java
Expand Up @@ -49,8 +49,21 @@ public void close() {
}
}

public static String expandPath(String fileName) {
return expandPath(fileName, null);
public static String expandPath(RubyContext context, String fileName) {
RubyNode.notDesignedForCompilation();

// TODO (nirvdrum 11-Feb-15) This needs to work on Windows without calling into non-Truffle JRuby.
if (context.isRunningOnWindows()) {
final org.jruby.RubyString path = context.toJRuby(context.makeString(fileName));
final org.jruby.RubyString expanded = (org.jruby.RubyString) org.jruby.RubyFile.expand_path19(
context.getRuntime().getCurrentContext(),
null,
new org.jruby.runtime.builtin.IRubyObject[] { path });

return expanded.asJavaString();
} else {
return expandPath(fileName, null);
}
}

public static String expandPath(String fileName, String dir) {
Expand Down
Expand Up @@ -138,7 +138,7 @@ private boolean requireFile(String fileName, RubyNode currentNode) throws IOExce
return false;
}

final String expandedPath = RubyFile.expandPath(fileName);
final String expandedPath = RubyFile.expandPath(context, fileName);

for (Object loaded : Arrays.asList(context.getCoreLibrary().getLoadedFeatures().slowToArray())) {
if (loaded.toString().equals(expandedPath)) {
Expand Down

0 comments on commit fec1f7a

Please sign in to comment.