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

Make srb aware of tapioca #3332

Merged
merged 3 commits into from Aug 19, 2020
Merged

Make srb aware of tapioca #3332

merged 3 commits into from Aug 19, 2020

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Jul 29, 2020

Motivation

One difference between srb and tapioca is the way they handle signatures coming from gems.

With srb, the developer of a gem can provide a dir called rbi/ that contains all the signatures they want to export.
When the end user runs srb tc, the content of the gem rbi/ dir is cached locally then passed to sorbet along the other files to be typechecked in the project.

This approach brings at least two problems: 1) Sorbet does not come with a de-facto solution to copy signatures from the code to the rbi/ folder, hence 2) there is a high probability for the rbi/ folder to get desynchronized from the actual lib code.

tapioca tries to address this problem by automatically copying code signatures to the RBI when it generates the RBIs for all the gems in the end user project. That way, the work is transferred from the gem developer to the gem user, and ultimately to tapioca. Since you likely run tapioca every time you change your Gemfile, you always get the up-to-date signatures from the gem code for free.

While still imperfect, this solution allows the whole RBI sharing to work without intervention from the developer nor the end user and avoid desynchronization. Also, since tapioca comes with an exclusion list mechanism the end user can chose to completely ignore a gem RBI if they want.

Now comes the problem with the current srb behaviour. By always copying the rbi/ folder, the RBI from the gem is always passed to Sorbet when one call srb tc. Which is then in conflict with the expected behaviour of a tapioca user.

To address this problem, @paracycle proposed a new environment variable controlling srb behaviour regarding gems RBIs: SRB_SKIP_GEM_RBIS. While it solves the problem, it can be cumbersome for the end user that always have to remember to set this variable every time they use tapioca in a project that depends on gems with a rbi/ folder. This problem is even bigger since tapioca started depending on the parlour gem which provides a rbi/ folder meaning that all tapioca users now need to set the environment variable.

With this pull-request, the idea is to make srb aware that tapioca is used in the project and copying the rbi/ folder is not needed. The end user get the expected behaviour without changing environment variables and nothing changes if the project does not use tapioca.

Test plan

See included automated tests.

@Morriar Morriar requested a review from a team as a code owner July 29, 2020 23:30
@Morriar Morriar requested review from elliottt and removed request for a team July 29, 2020 23:30
Copy link
Contributor

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

Thanks for adding the comment!

@elliottt
Copy link
Contributor

This change will be untested in our repo, do you think it would be possible to add a snapshot test to gems/sorbet/test/snapshot that would exercise it?

@Morriar
Copy link
Collaborator Author

Morriar commented Aug 11, 2020

@elliottt I rebased this one on #3357 so I could add the tests you asked for.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
…s used

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Copy link
Contributor

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

This looks good, I just had one question about the content of the test.sh for the tapioca test.

@@ -0,0 +1,3 @@
#!/bin/bash

bundle exec "$1" tc
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is explicitly not calling srb init because that's not the workflow with tapioca, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly. We assume the user will do tapioca init instead.

@elliottt elliottt merged commit 9988053 into sorbet:master Aug 19, 2020
@Morriar Morriar deleted the at-fix-srb branch August 19, 2020 20:51
Morriar added a commit to Shopify/spoom that referenced this pull request Mar 13, 2024
By default, `srb` will look for RBIs coming from gems. Since we migrated to
Prism, Sorbet is now picking up the RBI shipped with the gem which results
in a lot of errors.

We can disable this behavior by using Tapioca. See sorbet/sorbet#3332.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
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