Skip to content

Commit

Permalink
Showing 4 changed files with 58 additions and 19 deletions.
17 changes: 17 additions & 0 deletions lib/ruby/truffle/jruby+truffle/README.md
Original file line number Diff line number Diff line change
@@ -92,6 +92,23 @@ activesupport's configuration file follows:
- shims
```
## Using the tool in CI
Assuming there are similar stored commands for a given gem:
```yaml
:stored_commands:
:ci:
- :setup
- :test
:setup:
- "git clone git@github.com:lucasocon/openweather.git"
- "jruby+truffle --dir openweather setup"
:test: "jruby+truffle --dir openweather run --require-pattern 'test/*_test.rb' -I test -- -e nil"
```
then `jruby+truffle --config openweather stored ci` can be used to run tests of the given gem in CI.

## Example step-by-step

```sh
Original file line number Diff line number Diff line change
@@ -81,8 +81,11 @@
- pathname
:stored_commands:
:ci:
- "jruby+truffle setup"
- :setup
- :test
:test: "jruby+truffle run --exclude-pattern 'jdom_engine' --require-pattern 'test/**/**/*_test.rb' -r exclude_tests -- -I test -e 'nil'"
:setup:
- "git clone -b 4-2-stable git@github.com:rails/rails.git"
- "jruby+truffle --dir rails/activesupport setup"
:test: "jruby+truffle --dir rails/activesupport run --exclude-pattern 'jdom_engine' --require-pattern 'test/**/**/*_test.rb' -r exclude_tests -- -I test -e 'nil'"


12 changes: 12 additions & 0 deletions lib/ruby/truffle/jruby+truffle/gem_configurations/openweather.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
:setup:
:file:
"bundler/gem_tasks.rb": nil
:stored_commands:
:ci:
- :setup
- :test
:setup:
- "git clone git@github.com:lucasocon/openweather.git"
- "jruby+truffle --dir openweather setup"
:test: "jruby+truffle --dir openweather run --require-pattern 'test/*_test.rb' -I test -- -e nil"

41 changes: 24 additions & 17 deletions lib/ruby/truffle/jruby+truffle/runner.rb
Original file line number Diff line number Diff line change
@@ -57,9 +57,11 @@ class JRubyTruffleRunner
mock_load_path: ['--mock-load-path PATH',
'Path of mocks & monkey-patches (prepended in $:, relative to --truffle_bundle_path)',
assign_new_value, 'mocks'],
use_fs_core: ['--[no-]use-fs-core', 'use core from the filesystem rather than the JAR',
use_fs_core: ['--[no-]use-fs-core', 'Use core from the filesystem rather than the JAR',
assign_new_value, true],
bundle_cmd: ['--bundle-cmd CMD', 'command to run for bundle', assign_new_value, 'bundle']
bundle_cmd: ['--bundle-cmd CMD', 'Command to run for bundle', assign_new_value, 'bundle'],
configuration: ['--config GEM_NAME', 'Load configuration for specified gem', assign_new_value, nil],
dir: ['--dir DIRECTORY', 'Set working directory', assign_new_value, Dir.pwd],
},
setup: {
help: ['-h', '--help', 'Show this message', assign_new_value, false],
@@ -170,27 +172,32 @@ class JRubyTruffleRunner

def initialize(argv = ARGV)
construct_default_options
load_gem_configuration
load_local_configuration
build_option_parsers

subcommand, *argv_after_global = @option_parsers[:global].order argv

if subcommand.nil?
print_options
help :global
end
help :global if @options[:global][:help]
Dir.chdir @options[:global][:dir] do
puts "pwd: #{Dir.pwd}" if verbose?

subcommand = subcommand.to_sym
load_gem_configuration
load_local_configuration

if subcommand.nil?
print_options
help :global
end
help :global if @options[:global][:help]

subcommand_option_parser = @option_parsers[subcommand] || raise("unknown subcommand: #{subcommand}")
argv_after_subcommand = subcommand_option_parser.order argv_after_global
subcommand = subcommand.to_sym

print_options
help subcommand if @options[subcommand][:help] && subcommand != :readme
subcommand_option_parser = @option_parsers[subcommand] || raise("unknown subcommand: #{subcommand}")
argv_after_subcommand = subcommand_option_parser.order argv_after_global

send "subcommand_#{subcommand}", argv_after_subcommand
print_options
help subcommand if @options[subcommand][:help] && subcommand != :readme

send "subcommand_#{subcommand}", argv_after_subcommand
end
end

def print_options
@@ -224,12 +231,11 @@ def build_option_parsers
end

def load_gem_configuration
candidates = Dir['*.gemspec'] # TODO pwd?
candidates = @options[:global][:configuration] ? [@options[:global][:configuration]] : Dir['*.gemspec']

if candidates.size == 1
gem_name, _ = candidates.first.split('.')
yaml_path = File.dirname(__FILE__) + "/gem_configurations/#{gem_name}.yaml"
File.exist? yaml_path
end

apply_yaml_to_configuration(yaml_path)
@@ -325,6 +331,7 @@ def subcommand_setup(rest)

@options[:setup][:file].each do |name, content|
puts "creating file: #{mock_path}/#{name}" if verbose?
FileUtils.mkpath File.dirname("#{mock_path}/#{name}")
File.write "#{mock_path}/#{name}", content
end

1 comment on commit e6ca426

@pitr-ch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.