Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure lib is on the load path in mail.gemspec #1412

Closed
wants to merge 1 commit into from

Conversation

schneems
Copy link

@schneems schneems commented Sep 16, 2020

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.

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:

```ruby
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 I mikel#1411 I updated it to 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
Copy link
Author

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
Copy link
Author

schneems commented Jul 9, 2021

Ping

@mikel
Copy link
Owner

mikel commented Dec 3, 2022

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

@mikel mikel added this to the 2.9.0 milestone Dec 3, 2022
eval added a commit that referenced this pull request Jan 3, 2024
eval added a commit that referenced this pull request Jan 3, 2024
eval added a commit that referenced this pull request Jan 3, 2024
eval added a commit that referenced this pull request Jan 3, 2024
@eval
Copy link
Collaborator

eval commented Jan 3, 2024

Fixed by #1598

@eval eval closed this Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants