|
| 1 | +# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This |
| 2 | +# code is released under a tri EPL/GPL/LGPL license. You can use it, |
| 3 | +# redistribute it and/or modify it under the terms of the: |
| 4 | +# |
| 5 | +# Eclipse Public License version 1.0 |
| 6 | +# GNU General Public License version 2 |
| 7 | +# GNU Lesser General Public License version 2.1 |
| 8 | + |
| 9 | +# A workflow tool for JRuby+Truffle development |
| 10 | + |
| 11 | +# Recommended: function jt { ruby tool/jt.rb $@; } |
| 12 | + |
| 13 | +def sh(*args) |
| 14 | + system args.join(' ') |
| 15 | + raise "failed" unless $? == 0 |
| 16 | +end |
| 17 | + |
| 18 | +def mvn(*args) |
| 19 | + sh 'mvn', *args |
| 20 | +end |
| 21 | + |
| 22 | +def mspec(command, *args) |
| 23 | + sh 'ruby', 'spec/mspec/bin/mspec', command, '--config', 'spec/truffle/truffle.mspec', *args |
| 24 | +end |
| 25 | + |
| 26 | +def help |
| 27 | + puts 'jt build build' |
| 28 | + puts 'jt clean clean' |
| 29 | + puts 'jt rebuild clean and build' |
| 30 | + puts 'jt test run all specs' |
| 31 | + puts 'jt test spec/ruby/language run specs in this directory' |
| 32 | + puts 'jt test spec/ruby/language/while_spec.rb run specs in this file' |
| 33 | + puts 'jt tag spec/ruby/language tag failing specs in this directory' |
| 34 | + puts 'jt tag spec/ruby/language/while_spec.rb tag failing specs in this file' |
| 35 | + puts 'jt untag spec/ruby/language untag passing specs in this directory' |
| 36 | + puts 'jt untag spec/ruby/language/while_spec.rb untag passing specs in this file' |
| 37 | + puts 'jt findbugs run findbugs' |
| 38 | +end |
| 39 | + |
| 40 | +def build |
| 41 | + mvn 'package' |
| 42 | +end |
| 43 | + |
| 44 | +def clean |
| 45 | + mvn 'clean' |
| 46 | +end |
| 47 | + |
| 48 | +def rebuild |
| 49 | + clean |
| 50 | + build |
| 51 | +end |
| 52 | + |
| 53 | +def test(path=nil) |
| 54 | + if path.nil? |
| 55 | + mspec 'run', '--excl-tag', 'fails', ':language', ':core' |
| 56 | + elsif path.start_with? 'spec/ruby' |
| 57 | + mspec 'run', '--excl-tag', 'fails', path |
| 58 | + else |
| 59 | + raise "don't know how to test #{path}" |
| 60 | + end |
| 61 | +end |
| 62 | + |
| 63 | +def tag(path) |
| 64 | + mspec 'tag', '--add', 'fails', '--fail', path |
| 65 | +end |
| 66 | + |
| 67 | +def untag(path) |
| 68 | + puts |
| 69 | + puts "WARNING: untag is currently not very reliable - run test #{path} after and manually annotate any new failures" |
| 70 | + puts |
| 71 | + mspec 'tag', '--del', 'fails', '--pass', path |
| 72 | +end |
| 73 | + |
| 74 | +def findbugs |
| 75 | + sh 'tool/truffle-findbugs.sh' |
| 76 | +end |
| 77 | + |
| 78 | +COMMANDS = [ |
| 79 | + ['help'], |
| 80 | + ['build'], |
| 81 | + ['clean'], |
| 82 | + ['rebuild'], |
| 83 | + ['test'], |
| 84 | + ['test', :path], |
| 85 | + ['tag', :path], |
| 86 | + ['untag', :path], |
| 87 | + ['findbugs'] |
| 88 | +] |
| 89 | + |
| 90 | +if [[], ['-h'], ['-help'], ['--help']].include? ARGV |
| 91 | + help |
| 92 | + exit |
| 93 | +end |
| 94 | + |
| 95 | +def match(args, command) |
| 96 | + return false if ARGV.size != command.size |
| 97 | + |
| 98 | + impl_args = [] |
| 99 | + |
| 100 | + command.zip(ARGV).each do |expected, actual| |
| 101 | + if expected.is_a? String |
| 102 | + return false if expected != actual |
| 103 | + elsif expected.is_a? Symbol |
| 104 | + impl_args.push actual |
| 105 | + end |
| 106 | + end |
| 107 | + |
| 108 | + send command[0], *impl_args |
| 109 | + |
| 110 | + exit |
| 111 | +end |
| 112 | + |
| 113 | +COMMANDS.each do |command| |
| 114 | + match(ARGV, command) |
| 115 | +end |
| 116 | + |
| 117 | +raise "no command matched" |
0 commit comments