spec.activate instead of mark_loaded ?

8 views
Skip to first unread message

Emanuel Rietveld

unread,
May 14, 2012, 7:19:57 AM5/14/12
to ruby-b...@googlegroups.com
In lib/bundler/runtime.rb, function setup, there are the following lines:

Bundler.rubygems.mark_loaded(spec)
load_paths = spec.load_paths.reject {|path| $LOAD_PATH.include (path)}
$LOAD_PATH.unshift(*load_paths)

In my view, these can be replaced by

spec.activate

Since Bundler calls Bundler.rubygems.replace_entrypoints(specs) which
means "require" no longer automatically activates gems, it is very
important that gems are properly activated. What better way to make sure
than to call rubygems' own activate method?

A real world problem caused by this: on my Fedora 18 machine, gems are
installed to /usr/share/gems/gems/ and native extensions to
/usr/lib64/gems/exts/. spec.activate correctly adds
/usr/lib64/gems/exts/<GEM NAME>/LIB to $LOAD_PATH, but bundler's method
does not, causing applications to fail.

It should be more future-proof to let rubygems' own activate method
handle the gem activation. Or am I missing something?

Thank you for reading my email

Kind Regards,

Emanuel

Andre Arko

unread,
May 14, 2012, 1:10:07 PM5/14/12
to ruby-b...@googlegroups.com
My main worry is that Bundler has to stay compatible with Rubygems 1.3 through 1.8, and I don't know if spec.activate will work through all of the changes in Rubygems during that time.

You could try making this change and then running the Bundler specs, but I think it would be safer to patch Bundler to add the correct directory if it exists.
> --
> You received this message because you are subscribed to the Google Groups "ruby-bundler" group.
> To post to this group, send email to ruby-b...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-bundler...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-bundler?hl=en.
>

Emanuel Rietveld

unread,
May 15, 2012, 8:40:47 AM5/15/12
to ruby-b...@googlegroups.com
Well, spec.activate exists since rubygems 1.8. Maybe this?

diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 52e3dc6..8683cf7 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -31,9 +31,13 @@ module Bundler
raise e
end

- Bundler.rubygems.mark_loaded(spec)
- load_paths = spec.load_paths.reject {|path| $LOAD_PATH.include?(path)}
- $LOAD_PATH.unshift(*load_paths)
+ if spec.respond_to?(:activate)
+ spec.activate
+ else
+ Bundler.rubygems.mark_loaded(spec)
+ load_paths = spec.load_paths.reject {|path|
$LOAD_PATH.include?(path)}
+ $LOAD_PATH.unshift(*load_paths)
+ end
end

lock

Thank you for considering.

Kind Regards,

Emanuel
Reply all
Reply to author
Forward
0 new messages