Skip to content

Commit

Permalink
[Truffle] Refactor jt a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 7, 2015
1 parent e0589c5 commit 378ca01
Showing 1 changed file with 88 additions and 103 deletions.
191 changes: 88 additions & 103 deletions tool/jt.rb
Expand Up @@ -10,131 +10,116 @@

# Recommended: function jt { ruby tool/jt.rb $@; }

def sh(*args)
system args.join(' ')
raise "failed" unless $? == 0
end

def mvn(*args)
sh 'mvn', *args
end
module ShellUtils
private

def mspec(command, *args)
sh 'ruby', 'spec/mspec/bin/mspec', command, '--config', 'spec/truffle/truffle.mspec', *args
end
def sh(*args)
system args.join(' ')
raise "failed" unless $? == 0
end

def help
puts 'jt build build'
puts 'jt clean clean'
puts 'jt rebuild clean and build'
puts 'jt test run all specs'
puts 'jt test spec/ruby/language run specs in this directory'
puts 'jt test spec/ruby/language/while_spec.rb run specs in this file'
puts 'jt tag spec/ruby/language tag failing specs in this directory'
puts 'jt tag spec/ruby/language/while_spec.rb tag failing specs in this file'
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 mvn(*args)
sh 'mvn', *args
end

def build
mvn 'package'
def mspec(command, *args)
sh 'ruby', 'spec/mspec/bin/mspec', command, '--config', 'spec/truffle/truffle.mspec', *args
end
end

def clean
mvn 'clean'
end
module Commands
include ShellUtils

def help
puts 'jt build build'
puts 'jt clean clean'
puts 'jt rebuild clean and build'
puts 'jt test run all specs'
puts 'jt test spec/ruby/language run specs in this directory'
puts 'jt test spec/ruby/language/while_spec.rb run specs in this file'
puts 'jt tag spec/ruby/language tag failing specs in this directory'
puts 'jt tag spec/ruby/language/while_spec.rb tag failing specs in this file'
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 rebuild
clean
build
end
def build
mvn 'package'
end

def test(path=nil)
if path.nil?
mspec 'run', '--excl-tag', 'fails', ':language', ':core'
elsif path.start_with? 'spec/ruby'
mspec 'run', '--excl-tag', 'fails', path
else
raise "don't know how to test #{path}"
def clean
mvn 'clean'
end
end

def tag(path)
mspec 'tag', '--add', 'fails', '--fail', path
end
def rebuild
clean
build
end

def untag(path)
puts
puts "WARNING: untag is currently not very reliable - run test #{path} after and manually annotate any new failures"
puts
mspec 'tag', '--del', 'fails', '--pass', path
end
def test(path=nil)
if path == nil
mspec 'run', '--excl-tag', 'fails', ':language', ':core'
elsif path.start_with? 'spec/ruby'
mspec 'run', '--excl-tag', 'fails', path
else
raise ArgumentError, "don't know how to test #{path}"
end
end

def findbugs
sh 'tool/truffle-findbugs.sh'
end
def tag(path)
mspec 'tag', '--add', 'fails', '--fail', path
end

def findbugs_report
sh 'tool/truffle-findbugs.sh --report' rescue nil
sh 'open truffle-findbugs-report.html' rescue nil
end
def untag(path)
puts
puts "WARNING: untag is currently not very reliable - run test #{path} after and manually annotate any new failures"
puts
mspec 'tag', '--del', 'fails', '--pass', path
end

COMMANDS = [
['help'],
['build'],
['clean'],
['rebuild'],
['test'],
['test', :path],
['tag', :path],
['untag', :path],
['findbugs'],
['findbugs', 'report']
]

if [[], ['-h'], ['-help'], ['--help']].include? ARGV
help
exit
def findbugs(report=nil)
case report
when "report"
sh 'tool/truffle-findbugs.sh --report' rescue nil
sh 'open truffle-findbugs-report.html' rescue nil
when nil
sh 'tool/truffle-findbugs.sh'
else
raise ArgumentError, report
end
end
end

def match(args, command)
return false if ARGV.size != command.size
class JT
include Commands

command_name = []
impl_args = []
def run(args)
args = args.dup

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
if args.empty? or !(args & %w[-h -help --help]).empty?
help
exit
end
end

send command_name.join('_'), *impl_args
send args.shift if %w[build rebuild].include? args.first

exit
end
return if args.empty?

if ARGV[0] == 'build'
build
ARGV.shift
elsif ARGV[0] == 'rebuild'
rebuild
ARGV.shift
end
commands = Commands.public_instance_methods.map(&:to_s)

if ARGV.empty?
exit
end
abort "no command matched" unless commands.include?(args.first)

COMMANDS.each do |command|
match(ARGV, command)
begin
send(*args)
rescue
puts "Error during command: #{args*' '}"
raise $!
end
end
end

raise "no command matched"
JT.new.run(ARGV)

0 comments on commit 378ca01

Please sign in to comment.