out of time
-
A 15-line alternative to multiruby
Today’s mission was to get Sunspot working in all the major Ruby implementations (MRI, YARV, JRuby). I personally use MRI 1.8.6p114, and hadn’t had a need to install any other Ruby implementations, so I first tried out multiruby, which handles all of the installing and running of different Ruby versions. Alas, it didn’t work very well - after all, package management is a nontrivial problem, and multiruby does attempt to perform that function in a sense. The packages didn’t install.
I also wasn’t a big fan of installing a whole filesystem hierarchy inside a hidden directory in my home directory (some people like this — follow your own path, young jedi); and it required I install the entire ZenTest gem, which I otherwise have not found much use for.
So, I went ahead and just installed YARV and JRuby as optional packages, installed gems for them, ran the spec suite under each version, and fixed the bugs that came up. Great! But I did notice that this involved a lot of typing out full paths to the various Ruby binaries, particularly since I will want to be running the specs under all the versions from now on. This is not a difficult problem to solve, I thought to myself. Enter quick 15-line script:
#!/usr/bin/env ruby require 'rubygems' gem 'escape' require 'escape' File.open(File.join(ENV['HOME'], '.rubies')) do |file| file.each_line do |bin| bin.sub!(/\n$/, '') STDERR.puts("Executing in #{`#{Escape.shell_command([bin, '-v'])}`}") fork do exec(Escape.shell_command([bin].concat(ARGV))) end Process.wait end endThen I just set up my ~/.rubies file, containing full paths to my various Ruby binaries:
/usr/local/bin/ruby /opt/ruby-1.9.1-p129/bin/ruby /opt/jruby-1.2.0/bin/jrubyAnd a quick
rubies -S rakeruns my suites in all the relevant ruby versions. Genius? No, but it gives me all the useful functionality of multiruby with the control over installation that I crave. Hopefully it’ll help you too.