mail icon indicating copy to clipboard operation
mail copied to clipboard

Ensure lib is on the load path in mail.gemspec

Open schneems opened this issue 5 years ago • 2 comments

The current gemspec cannot be executed by native ruby code as lib is not yet on the load path. The only reason this currently with bundler is that it is "stubbed" and bundler otherwise fixes other path issues. Here's an example after you remove bundler's stubbing:

mkdir -p /tmp/da5e922c690a8d15ac3c8578981b3d4d; cd /tmp/da5e922c690a8d15ac3c8578981b3d4d
echo "source 'https://rubygems.org'" >> Gemfile
echo "gem 'mail', github: 'mikel/mail'" >> Gemfile
bundle install

echo "require 'mail'; puts 'worked'" >> main.rb

# Go into the mail gem directory and remove the changes to mail.gemspec that bundler makes
cd $(bundle info mail --path)
git stash
cd -

bundle exec ruby main.rb

If you run this code you'll get an error:

$ bundle exec ruby main.rb
Invalid gemspec in [/Users/rschneeman/.gem/ruby/2.7.1/bundler/gems/mail-8fbb17d4d536/mail.gemspec]: cannot load such file -- ./lib/mail/version
Traceback (most recent call last):
  24: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
  23: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
  22: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/setup.rb:10:in `<top (required)>'
  21: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/ui/shell.rb:88:in `silence'
  20: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/ui/shell.rb:136:in `with_level'
  19: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/setup.rb:10:in `block in <top (required)>'
  18: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler.rb:149:in `setup'
  17: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/runtime.rb:20:in `setup'
  16: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/runtime.rb:101:in `block in definition_method'
  15: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/definition.rb:226:in `requested_specs'
  14: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/definition.rb:237:in `specs_for'
  13: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/definition.rb:170:in `specs'
  12: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `materialize'
  11: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `map!'
  10: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/spec_set.rb:83:in `block in materialize'
   9: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/lazy_specification.rb:75:in `__materialize__'
   8: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/source/git.rb:168:in `specs'
   7: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/source/path.rb:105:in `local_specs'
   6: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/source/git.rb:201:in `load_spec_files'
   5: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/source/path.rb:170:in `load_spec_files'
   4: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/source/path.rb:170:in `each'
   3: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/source/path.rb:171:in `block in load_spec_files'
   2: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/source/git.rb:320:in `load_gemspec'
   1: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/bundler/stub_specification.rb:9:in `from_stub'
/Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/stub_specification.rb:158:in `name': undefined method `name' for nil:NilClass (NoMethodError)

Previously in #1411 I updated the require to be a require_relative but this doesn't work with 1.9 and 1.8 so I switched back to the "old" way of manually unshifting lib onto the path.

schneems avatar Sep 16 '20 02:09 schneems

All tests are passing now. In talking to the Bundler maintainers over slack main it sounds like the *.gemspec file should be able to be run natively by ruby (from a different working directory).

Here's an example with and without this patch:

$ cd /tmp
$ ruby ~/Documents/projects/mail/mail.gemspec && echo "worked"
Traceback (most recent call last):
  2: from /Users/rschneeman/Documents/projects/mail/mail.gemspec:1:in `<main>'
  1: from /Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/rschneeman/.rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- ./lib/mail/version (LoadError)
$ cd ~/Documents/projects/mail/ && git checkout schneems/fix-gemspec-require && cd /tmp
Switched to branch 'schneems/fix-gemspec-require'
$ ruby ~/Documents/projects/mail/mail.gemspec && echo "worked"
worked

Let me know if you have any questions here.

schneems avatar Sep 17 '20 20:09 schneems

Ping

schneems avatar Jul 09 '21 21:07 schneems

Hey there @schneems could you please get this on the latest master so the new checks will run? Then I'll merge it.

mikel avatar Dec 03 '22 09:12 mikel

Fixed by https://github.com/mikel/mail/pull/1598

eval avatar Jan 03 '24 16:01 eval