From: Stephen Bannasch Date: 2009-08-15T06:29:34+09:00 Subject: [ruby-core:24922] extending '-S' to make working with multiple ruby VM's easier This may be an email better addressed to rubygems-developers but since it also involves how Ruby VMs implement the '-S' functionality I thought I'd ask here first. JRuby appears to add an additional function when started with '-S' that other Ruby VMs don't -- effectively looking first for ruby executables in a bin/ directory located on a path relative to the location of the jruby executable itself. This can make working with multiple Ruby VMs easier but ruby19 doesn't appear to work this way. I am doing some work on a gem (has_many_polynmorphs) and trying to get it working in ruby 1.8.x and ruby 1.9.x as well as in MRI and in JRuby. As long as I have an executable 'jruby' on my path I can switch from using installed ruby executables in MRI and the ones installed for jruby in a single session easily by prefixing 'jruby -S' to my commands when I want the jruby versions. However this only partially works using ruby19. I think the issues may be both in rubygems and in how the VM implements the '-S' functionality. I know that the JRuby team has added some extra functionality to '-S' that isn't in the MRI VMs. Here's how '-S' is documented in ruby19 -S look for the script using PATH environment variable Here's how '-S' is documented in jruby -S look for the script in bin or using PATH environment variable I try to leave the system ruby and it's gem repository alone when working with multiple ruby VMs and instead install the alternative VMs in mm home dir: My installed MRI is 1.8.6 $ gem env RubyGems Environment: - RUBYGEMS VERSION: 1.3.3 - RUBY VERSION: 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8 - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby - EXECUTABLE DIRECTORY: /usr/bin - RUBYGEMS PLATFORMS: - ruby - universal-darwin-9 - GEM PATHS: - /Library/Ruby/Gems/1.8 - /Users/stephen/.gem/ruby/1.8 - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - :sources => ["http://gems.rubyforge.org", "http://gems.github.com"] - REMOTE SOURCES: - http://gems.rubyforge.org - http://gems.github.com I have both JRuby and ruby19 installed in different locations in my home dir: $ which jruby /Users/stephen/dev/ruby/src/jruby.git/bin/jruby $ jruby -S gem env RubyGems Environment: - RUBYGEMS VERSION: 1.3.3 - RUBY VERSION: 1.8.7 (2009-08-09 patchlevel 174) [java] - INSTALLATION DIRECTORY: /Users/stephen/dev/ruby/src/jruby.git/lib/ruby/gems/1.8 - RUBY EXECUTABLE: /Users/stephen/dev/ruby/src/jruby.git/bin/jruby - EXECUTABLE DIRECTORY: /Users/stephen/dev/ruby/src/jruby.git/bin - RUBYGEMS PLATFORMS: - ruby - universal-java-1.5 - GEM PATHS: - /Users/stephen/dev/ruby/src/jruby.git/lib/ruby/gems/1.8 - /Users/stephen/.gem/jruby/1.8 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - "install" => "--env-shebang" - "update" => "--env-shebang" - :sources => ["http://gems.rubyforge.org", "http://gems.github.com"] - REMOTE SOURCES: - http://gems.rubyforge.org - http://gems.github.com Using '-S' to run the gem installed with ruby19 also works: $ which ruby19 /usr/local/bin/ruby19 $ ls -l /usr/local/bin/ruby19 /usr/local/bin/ruby19 -> /Users/stephen/dev/ruby/builds/ruby19 $ ruby19 -S gem env RubyGems Environment: - RUBYGEMS VERSION: 1.3.4 - RUBY VERSION: 1.9.2 (2009-08-14 patchlevel -1) [i386-darwin9.8.0] - INSTALLATION DIRECTORY: /Users/stephen/dev/ruby/builds/mri/trunk/lib/ruby/gems/1.9.1 - RUBY EXECUTABLE: /Users/stephen/dev/ruby/builds/mri/trunk/bin/ruby - EXECUTABLE DIRECTORY: /Users/stephen/dev/ruby/builds/mri/trunk/bin - RUBYGEMS PLATFORMS: - ruby - x86-darwin-9 - GEM PATHS: - /Users/stephen/dev/ruby/builds/mri/trunk/lib/ruby/gems/1.9.1 - /Users/stephen/.gem/ruby/1.9.1 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - :sources => ["http://gems.rubyforge.org", "http://gems.github.com"] - REMOTE SOURCES: - http://gems.rubyforge.org - http://gems.github.com Running an executable like rake works if it doesn't invoke other tasks in jruby and ruby19: $ jruby -S rake -T (in /Users/stephen/dev/ruby/src/gems/has_many_polymorphs-git) rake announce # Generate a release announcement, edit it, a ... ... $ ruby19 -S rake -T (in /Users/stephen/dev/ruby/src/gems/has_many_polymorphs-git) rake announce # Generate a release announcement, edit it, a ... ... Running tests for the has_many_polymorphs gem operates correctly in jruby (there are errors but that's a separate problem). The tests do NOT run in ruby19. I get a number of 'Invalid .gemspec format' for installed gems in ruby19 and when multi_rails runs this code Gem::cache.find_name("rails").empty? to check for the existence of an installed Rails gem it fails with this error: relevance-multi_rails-0.0.8/lib/multi_rails/loader.rb:37:in `verify_rails_installed': No Rails gems installed! (MultiRailsError) The full trace for that line confirms that the gem is running from ruby19's gem repo -- here's the path prefixed to the previous error: /Users/stephen/dev/ruby/builds/mri/trunk/lib/ruby/gems/1.9.1/gems However running this same code in ruby19 irb succeeds: $ ruby19 -S irb irb(main):001:0> Gem::cache.find_name("rails").empty? => false What is jruby doing differently that ruby19 isn't? Is adding the additional jruby functionality with '-S' compatible with ruby19? Is there another way to get the functionality I am looking for where I can have many Ruby VMs installed and easily switch between them?