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: f3f6589134e8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d36ef071ee18
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 6, 2015

  1. Copy the full SHA
    a44f1bd View commit details
  2. Copy the full SHA
    d36ef07 View commit details
64 changes: 60 additions & 4 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -45,16 +45,72 @@
import org.jruby.util.ByteList;
import org.jruby.util.cli.Options;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

@CoreClass(name = "Kernel")
public abstract class KernelNodes {

@CoreMethod(names = "`", isModuleFunction = true, needsSelf = false, required = 1)
public abstract static class BacktickNode extends CoreMethodNode {

public BacktickNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public BacktickNode(BacktickNode prev) {
super(prev);
}

@Specialization
public RubyString backtick(RubyString command) {
// Command is lexically a string interoplation, so variables will already have been expanded

notDesignedForCompilation();

final RubyContext context = getContext();

final RubyHash env = context.getCoreLibrary().getENV();

final List<String> envp = new ArrayList<>();

// TODO(CS): cast
for (KeyValue keyValue : HashOperations.verySlowToKeyValues(env)) {
envp.add(keyValue.getKey().toString() + "=" + keyValue.getValue().toString());
}

final Process process;

try {
// We need to run via bash to get the variable and other expansion we expect
process = Runtime.getRuntime().exec(new String[]{"bash", "-c", command.toString()}, envp.toArray(new String[envp.size()]));
} catch (IOException e) {
throw new RuntimeException(e);
}

final InputStream stdout = process.getInputStream();
final InputStreamReader reader = new InputStreamReader(stdout);

final StringBuilder resultBuilder = new StringBuilder();

// TODO(cs): this isn't great for binary output

try {
int c;

while ((c = reader.read()) != -1) {
resultBuilder.append((char) c);
}
} catch (IOException e) {
throw new RuntimeException(e);
}

return context.makeString(resultBuilder.toString());
}

}

/**
* Check if operands are the same object or call #==.
* Known as rb_equal() in MRI. The fact Kernel#=== uses this is pure coincidence.
85 changes: 0 additions & 85 deletions core/src/main/java/org/jruby/truffle/nodes/core/SystemNode.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -945,11 +945,11 @@ public RubyNode visitDVarNode(org.jruby.ast.DVarNode node) {

@Override
public RubyNode visitDXStrNode(org.jruby.ast.DXStrNode node) {
SourceSection sourceSection = translate(node.getPosition());

final RubyNode string = translateInterpolatedString(sourceSection, node.childNodes());

return new SystemNode(context, sourceSection, string);
final org.jruby.ast.DStrNode string = new org.jruby.ast.DStrNode(node.getPosition(), node.getEncoding());
string.childNodes().addAll(node.childNodes());
final org.jruby.ast.Node argsNode = buildArrayNode(node.getPosition(), string);
final org.jruby.ast.Node callNode = new FCallNode(node.getPosition(), "`", argsNode, null);
return callNode.accept(this);
}

@Override
@@ -2467,11 +2467,9 @@ public RubyNode visitWhileNode(org.jruby.ast.WhileNode node) {

@Override
public RubyNode visitXStrNode(org.jruby.ast.XStrNode node) {
SourceSection sourceSection = translate(node.getPosition());

final StringLiteralNode literal = new StringLiteralNode(context, sourceSection, node.getValue());

return new SystemNode(context, sourceSection, literal);
final org.jruby.ast.Node argsNode = buildArrayNode(node.getPosition(), new org.jruby.ast.StrNode(node.getPosition(), node.getValue()));
final org.jruby.ast.Node callNode = new FCallNode(node.getPosition(), "`", argsNode, null);
return callNode.accept(this);
}

@Override
27 changes: 25 additions & 2 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -35,6 +35,9 @@ def help
puts 'jt untag spec/ruby/language untag passing specs in this directory'
puts 'jt untag spec/ruby/language/while_spec.rb untag passing specs in this file'
puts 'jt findbugs run findbugs'
puts 'jt findbugs report run findbugs and generate an HTML report'
puts
puts 'you can also put build or redbuild in front of any command'
end

def build
@@ -75,6 +78,11 @@ def findbugs
sh 'tool/truffle-findbugs.sh'
end

def findbugs_report
sh 'tool/truffle-findbugs.sh --report'
sh 'open truffle-findbugs-report.html' rescue nil
end

COMMANDS = [
['help'],
['build'],
@@ -84,7 +92,8 @@ def findbugs
['test', :path],
['tag', :path],
['untag', :path],
['findbugs']
['findbugs'],
['findbugs', 'report']
]

if [[], ['-h'], ['-help'], ['--help']].include? ARGV
@@ -95,18 +104,32 @@ def findbugs
def match(args, command)
return false if ARGV.size != command.size

command_name = []
impl_args = []

command.zip(ARGV).each do |expected, actual|
if expected.is_a? String
return false if expected != actual
command_name.push expected
elsif expected.is_a? Symbol
impl_args.push actual
end
end

send command[0], *impl_args
send command_name.join('_'), *impl_args

exit
end

if ARGV[0] == 'build'
build
ARGV.shift
elsif ARGV[0] == 'rebuild'
rebuild
ARGV.shift
end

if ARGV.empty?
exit
end