Support Content Addressable File Naming - gem build Flow#9703
Open
OughtPuts wants to merge 4 commits into
Open
Support Content Addressable File Naming - gem build Flow#9703OughtPuts wants to merge 4 commits into
gem build Flow#9703OughtPuts wants to merge 4 commits into
Conversation
…by_abi from required_ruby_version
…sable or standard)
… the --ruby_abi flag to gem build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
As part of the work to speed up
bundle install, this PR adjustsgem buildto support using content-addressable naming at build-time for a gem which only supports a single Ruby ABI.Summary
This PR introduces changes to the
gem buildprocess to assign a content-addressable file name during the build of a gem that only supports one Ruby ABI (a skinny gem).The bulk of the changes are in
Gem::Package. Inself.build, we now check if theruby_abiflag has been set when thegem buildcommand is run. Only if it has do we first validate the Ruby ABI value (and compare this to therequired_ruby_versionfor compatibility etc.) and then build a content addressable file if the validation passes without raising. If the user has passed a file name value at time of runninggem build, we raise, as we would not expect a content addressable gem to have a custom file name (it instead has a SHA value based on the file contents). As part of the CA file name compilation, we build the gem first in memory (usingStringIO.new), generate the SHA value from the file contents, and then write the file including the SHA value as the filename.There is also a minor change to
package_taskwhich ensures that we are eventually transferring the correct file output of the build (as now the name could take three different forms - standard, platformed or content addressed), and a helper method inspecification.rbwhich helps compare the Ruby ABI to therequired_ruby_versionprovided.Testing
Tests written in
test_gem_commands_build_command,test_gem_package,test_gem_package_task, andtest_gem_specificationto cover new behaviour.Tophat
Within IRB terminal, paste this script so you can see the output of using the
Gem::Package.buildcommand in different scenarios:To try the
gem buildcommand locally against this branch, you can run it through the RubyGems checkout rather than your installed RubyGems. From a test gem directory with a platformed gemspec, use:ruby --disable-gems -I/path/to/rubygems/lib /path/to/rubygems/exe/gem build *.gemspec --ruby-abi 3.4.As an example, for my checkout that is:ruby --disable-gems -I/Users/harrietoughton/rubygems/lib /Users/harrietoughton/rubygems/exe/gem build *.gemspec --ruby-abi 3.4.The single Ruby ABI built file should be named
<name>-<version>-<sha10>.gemrather than<name>-<version>-<platform>.gem.It's also worth testing out that you receive the expected behaviour with a wrong format ruby ABI (e.g.--ruby-abi 3), with a mismatched Ruby ABI andrequired_ruby_versionand when a gem is platformed with no Ruby ABI and when it is neither platformed nor intended for a single ABI.