Horrible hack to work around a RubyGems bug

RailsConf inspired me to be more vocal in the community, and one way is for me to share some of the problem workarounds I’ve come up with. Here’s the first one, and I’m posting it in spite of being ashamed of it!

I use an automated mechanism to set up my Ubuntu machines from scratch, but I’ve had trouble with getting “gem install” to install the right version of binary gems: in spite of my efforts to script it, it’s been installing “mswin32″-platform gems under Ubuntu. There’s already a discussion on the RubyGems list about this, but I don’t have the experience with the gems architecture to help drive the decision; in the meantime, I needed a fix..

This works for me, for now:

    # /usr/lib/ruby/site_ruby/1.8/rubygems/remote_install.rb, line 112:
    # Find a gem to be installed by interacting with the user.
    def find_gem_to_install(gem_name, version_requirement)
        specs_n_sources = specs_n_sources_matching gem_name, version_requirement

        # BJS: added: reject win32 gems
        specs_n_sources.delete_if { |item| item[0].platform=="mswin32" }
        # [...]

This makes “gem” ignore “mswin32″-platform gems. I apply the patch (in my automated mechanism, of course), and if the apply fails, the install will fail, so (assuming the real fix for this problem modifies remote_install.rb), I’ll quickly find out and can rip this hack out.

(Please comment if you know a better solution!)

One thought on “Horrible hack to work around a RubyGems bug

  1. jamiew

    don’t have a better solution yet, but I changed the line to a regex like

    specs_n_sources.delete_if { |item| item[0].platform =~ /mswin32/ }

    to also exclude “i386-mswin32″ matches

    ideally one could configure rubygems to automatically select “ruby” packages as I don’t use jruby either

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>