Gordon Thiesfeld
2008-Apr-25 04:01 UTC
[Rubyinstaller-devel] Gem compatibility and platform specific dependencies
This may be better asked on the RubyGems list, but I thought I''d try here first. I''m working on a patch[1] for the github gem[2]. The github command requires open3, which doesn''t work on Windows because of fork, so I have it check for platform, and require WIn32-Open3 if on Windows. So, I have two questions about how to go about this. First, is Gem.win_platform? the proper way to go about this. I think it''s safe to say this package will always be distributed as a gem, so Gem will always exist when I need it. Second, is there a way to have Gem depedencies that are platform specific? Open3 is part of the stdlib, so no dependency there, but on Windows we need the Win32 gem. I''ve borrowed a pattern from RSpec for this: begin require ''win32 package'' rescue LoadError warn "You must ''gem install the win32 package to do this on Windows" exit 1 end But in the case of RSpec, it''s only used for colored console output. If you don''t use that feature, you''ll never know you need to have the gem installed. In this case, the whole thing just won''t work. That''s what dependencies are all about, I''d think. If there isn''t such a thing as platform specific dependencies, then what I''m fine doing it this way. I''m just wondering if there''s a better way. Thanks, Gordon [1] http://github.com/vertiginous/github-gem/commit/a4f54d3b8d51549ff9922c55de160b713a761d8b [2] http://github.com/defunkt/github-gem/tree/master
Luis Lavena
2008-Apr-25 04:21 UTC
[Rubyinstaller-devel] Gem compatibility and platform specific dependencies
On Fri, Apr 25, 2008 at 1:01 AM, Gordon Thiesfeld <gthiesfeld at gmail.com> wrote:> This may be better asked on the RubyGems list, but I thought I''d try > here first. I''m working on a patch[1] for the github gem[2]. The > github command requires open3, which doesn''t work on Windows because > of fork, so I have it check for platform, and require WIn32-Open3 if > on Windows. So, I have two questions about how to go about this. > > First, is Gem.win_platform? the proper way to go about this. I think > it''s safe to say this package will always be distributed as a gem, so > Gem will always exist when I need it. >I think is safe to assume Gem.win_platform? is available since you''re implementing that into a project that get''s distributed/installed as gem. The only problem is that win_platform? will be ''true'' even for cygwin implementation, which will render win32/open3 useless and I can smell that will crash :-P> Second, is there a way to have Gem depedencies that are platform > specific? Open3 is part of the stdlib, so no dependency there, but on > Windows we need the Win32 gem. I''ve borrowed a pattern from RSpec for > this: >To our bad, there isn''t a way to do that, you can create a "windows-specific" version and in that gem include the dependencies, but without a real need to do that, I think workaround in the code should be used.> begin > require ''win32 package'' > rescue LoadError > warn "You must ''gem install the win32 package to do this on Windows" > exit 1 > end > > But in the case of RSpec, it''s only used for colored console output. > If you don''t use that feature, you''ll never know you need to have the > gem installed. In this case, the whole thing just won''t work. > That''s what dependencies are all about, I''d think. If there isn''t > such a thing as platform specific dependencies, then what I''m fine > doing it this way. I''m just wondering if there''s a better way. >A good workaround will be poke the ruby-core developers to merge win32/open3 package in and reduce our code cluttery, but I don''t see that will happen anytime soon :-P> Thanks,Thanks to you Gordon! BTW: just pushed installer3 into the repository: http://rubyinstaller.rubyforge.org/svn/trunk/installer3/ -- Luis Lavena Multimedia systems - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams
Gordon Thiesfeld
2008-Apr-25 06:02 UTC
[Rubyinstaller-devel] Gem compatibility and platform specific dependencies
On Thu, Apr 24, 2008 at 11:21 PM, Luis Lavena <luislavena at gmail.com> wrote:> On Fri, Apr 25, 2008 at 1:01 AM, Gordon Thiesfeld <gthiesfeld at gmail.com> wrote: > > This may be better asked on the RubyGems list, but I thought I''d try > > here first. I''m working on a patch[1] for the github gem[2]. The > > github command requires open3, which doesn''t work on Windows because > > of fork, so I have it check for platform, and require WIn32-Open3 if > > on Windows. So, I have two questions about how to go about this. > > > > First, is Gem.win_platform? the proper way to go about this. I think > > it''s safe to say this package will always be distributed as a gem, so > > Gem will always exist when I need it. > > > > I think is safe to assume Gem.win_platform? is available since you''re > implementing that into a project that get''s distributed/installed as > gem. > > The only problem is that win_platform? will be ''true'' even for cygwin > implementation, which will render win32/open3 useless and I can smell > that will crash :-P >Oh yeah, I forgot about cygwin. I guess open3 works on cygwin? Is this the proper regex, then? RUBY_PLATFORM =~ /mswin|mingw/> > > Second, is there a way to have Gem depedencies that are platform > > specific? Open3 is part of the stdlib, so no dependency there, but on > > Windows we need the Win32 gem. I''ve borrowed a pattern from RSpec for > > this: > > > > To our bad, there isn''t a way to do that, you can create a > "windows-specific" version and in that gem include the dependencies, > but without a real need to do that, I think workaround in the code > should be used. >I was hoping I''d missed something simple, like: add_dependency() if Gem.win_platform? But if it''s not there I''m not going to ask for it. At least not in this case.> > > begin > > require ''win32 package'' > > rescue LoadError > > warn "You must ''gem install the win32 package to do this on Windows" > > exit 1 > > end > > > > But in the case of RSpec, it''s only used for colored console output. > > If you don''t use that feature, you''ll never know you need to have the > > gem installed. In this case, the whole thing just won''t work. > > That''s what dependencies are all about, I''d think. If there isn''t > > such a thing as platform specific dependencies, then what I''m fine > > doing it this way. I''m just wondering if there''s a better way. > > > > A good workaround will be poke the ruby-core developers to merge > win32/open3 package in and reduce our code cluttery, but I don''t see > that will happen anytime soon :-P >I don''t follow ruby-core that much, has this ever been suggested? I''m sure it must have at some point.> > Thanks, > > Thanks to you Gordon! > > BTW: just pushed installer3 into the repository: > http://rubyinstaller.rubyforge.org/svn/trunk/installer3/Should I switch from bzr to svn, or hold out for the git repo announcement ;-) -- Gordon