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

Treat default gems properly #330

Merged
merged 1 commit into from
May 25, 2021
Merged

Conversation

paracycle
Copy link
Member

Motivation

If the version of a default gem specified in the Gemfile is the version of that default gem that is bundled with the Ruby version, then Bundler just uses the default gem from the Ruby library directory.

But Bundler still acts like the gem is installed in where it would have been, which prevents Tapioca from generating a proper RBI for the gem and we end up generating an empty gem.

Implementation

This PR makes sure that if a gem is marked as a default gem, we check against the files listed in its gemspec inside the Ruby library folder instead of looking inside what the gem install folder would have been.

Tests

No added tests.

@paracycle paracycle requested a review from a team May 25, 2021 19:29
Copy link
Contributor

@KaanOzkan KaanOzkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone else didn't know what are default gems: https://nts.strzibny.name/ruby-stdlib-default-bundled-gems/

end

private

sig { returns(T::Boolean) }
def default_gem?
@spec.respond_to?(:default_gem?) && @spec.default_gem?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the respond_to? for older versions of Bundler? When would it not respond to default_gem??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. To be perfectly honest, I cargo-culted it from some of the Bundler code that was doing similar checks so I assumed it could be an older version Rubygems, maybe.

If the version of a default gem specified in the `Gemfile` is the
version of that default gem that is bundled with the Ruby version, then
Bundler just uses the default gem from the Ruby library directory.

This prevents Tapioca from generating a proper RBI for the gem and we
end up generating an empty gem.

This commit makes sure that if a gem is marked as a default gem, we
check against the files listed in its gemspec inside the Ruby library
folder instead of looking inside what the gem install folder would have
been.
@paracycle paracycle force-pushed the uk-treat-default-gems-properly branch from e47b89a to c8f1f8d Compare May 25, 2021 21:03
@paracycle paracycle merged commit 7f93369 into master May 25, 2021
@paracycle paracycle deleted the uk-treat-default-gems-properly branch May 25, 2021 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants