tags:

views:

48

answers:

1

How do I add optional dependencies to rubygems, as it does not support it?

Use cases:

  • I have a library that does either depend on Backports, Extlib, Facets or ActiveSupport. In the past I just did not add any of this dependencies, as people could choose (read: it would play nicely with whatever they were using), but people complained a lot about the library not working out of the box, or they would believe it depended on ActiveSupport (which in some cases is a no go for some people). So at the moment it depends on Backports, as it is the most minimal. Though that means people will install Backports if they install my library, even though they might not use it at Runtime.
  • I want to depend on different gems depending on the environment (i.e. Johnson on MRI/Rubinius, TheRubyRhino on JRuby, Lyndon on MacRuby).

One approach I though about is highjacking extconf.rb. I could do system checks there. However, this feels wrong. Moreover, if this is the only way, how do I go about it? How do I trigger installing additional gems from there? system 'gem install ...'?

+1  A: 

Have you tried giving informative error messages for unmet dependencies to clear up those misconceptions? With zombie-chaser, I don't make gosu a dependency, but if people try to use the graphical version of it without gosu, I inform them that they need to install gosu.

Andrew Grimm
I did that, but some people just don't care and scream "error". Also, I would like it to just work. Though this is probably the way to go (as rubygems is not able to handle the situation).
Konstantin Haase
I wonder if rubygems accepts feature requests, or whether it's "patches welcome"...
Andrew Grimm
I think this is rather hard to implement, for instance as breaking compatibility is not an option and meta data may not contain executable code.
Konstantin Haase