__FILE__ invalid when used in gemspecs (such as will_paginate) #181

Open
nerdyc opened this Issue Jan 31, 2010 · 1 comment

Comments

Projects
None yet
1 participant

nerdyc commented Jan 31, 2010

I got the following error when bundling will_paginate's rails3 branch (where $PROJECT_ROOT is my rails project dir):

$ gem bundle
Calculating dependencies...
/Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:217:in `locate_gemspecs': /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- $PROJECT_ROOT/lib/will_paginate/version (LoadError)
  from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
  from (eval):1:in `locate_gemspecs'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:217:in `eval'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:217:in `locate_gemspecs'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:217:in `inject'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:215:in `each'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:215:in `inject'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:215:in `locate_gemspecs'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:200:in `gems'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/source.rb:319:in `gems'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/resolver.rb:78:in `initialize'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/resolver.rb:77:in `each'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/resolver.rb:77:in `initialize'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/resolver.rb:40:in `new'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/resolver.rb:40:in `resolve'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/repository.rb:42:in `install'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/environment.rb:60:in `install'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/cli.rb:39:in `bundle'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/cli.rb:65:in `send'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/cli.rb:65:in `run'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/cli.rb:6:in `run'
  from /Library/Ruby/Gems/1.8/gems/bundler-0.7.1/lib/bundler/commands/bundle_command.rb:68:in `execute'
  from /Library/Ruby/Site/1.8/rubygems/command.rb:257:in `invoke'
  from /Library/Ruby/Site/1.8/rubygems/command_manager.rb:132:in `process_args'
  from /Library/Ruby/Site/1.8/rubygems/command_manager.rb:102:in `run'
  from /Library/Ruby/Site/1.8/rubygems/gem_runner.rb:58:in `run'
  from /usr/bin/gem:21

After some digging, I found that will_paginate's gemspec includes the following:

require File.expand_path('../lib/will_paginate/version', __FILE__)

Alas, it seems that FILE is not actually set to the gemspec's filename. Sure enough, looking at bundler/source.rb:217, I see:

    if spec = eval(File.read(file))
        ...
    end

I changed it to include the filename in the eval call, and it worked:

    if spec = eval(File.read(file), nil, file)
        ...
    end

nerdyc commented Jan 31, 2010

Hrm. I was using bundler 0.7.1 in the example above. I upgraded to 0.8.1 and still have the issue. However, will_paginate's gemspec has changed on the rails3 branch and is failing for a different reason.

However, the FILE will still be set incorrectly in 0.8.1 as well. It's just that will_paginate seems to have changed how its gemspec is written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment