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

Already on GitHub? Sign in to your account

Add Gem::Commands::PatchCommand and Gem::Patcher #381

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
4 participants
Contributor

strzibny commented Oct 2, 2012

patch command

This adds the patch command to RubyGems. The patch command helps to patch gems without manually opening and rebuilding them. It opens a given .gem file, extracts it, patches it with system patch command, clones its spec, updates the file list and builds the patched gem.

Usage

gem patch [options] name-version.gem PATCH [PATCH ...]

Optionally with -pNUMBER or --strip=NUMBER option that sets the file name strip count to NUMBER (same options as for patch command on Linux machines).

Example

Instead of extracting gem, patching the gem files with patch, manually changing file list in spec and packing it again:

irb(main):001:0> require 'rubygems/package'
=> true
irb(main):002:0> package = Gem::Package.new 'idn-0.0.2.gem'
=> #<Gem::Package:0x00000001e394e0 @gem="idn-0.0.2.gem", @build_time=2012-09-24 13:35:56 +0200, @checksums={}, @contents=nil, @digests={}, @files=nil, @security_policy=nil, @signatures={}, @signer=nil, @spec=nil>
irb(main):008:0> package.extract_files '/home/strzibny/unpacked'
=> nil
irb(main):009:0> patched_gem = package.spec.file_name
=> "idn-0.0.2.gem"
patch -p0 < mypatch.patch
irb(main):012:0> patched_package = Gem::Package.new patched_gem
=> #<Gem::Package:0x00000002aa0710 @gem="idn-0.0.2.gem", @build_time=2012-09-24 13:39:08 +0200, @checksums={}, @contents=nil, @digests={}, @files=nil, @security_policy=nil, @signatures={}, @signer=nil, @spec=nil>
irb(main):013:0> patched_package.spec = package.spec.clone
=> #<Gem::Specification:0x103c658 idn-0.0.2>
irb(main):014:0> patched_package.spec.rubygems_version = '2.0.a'
=> "2.0.a"
irb(main):015:0> Dir.chdir '/home/strzibny/unpacked' do
irb(main):016:1* patched_package.build
irb(main):017:1> end

will be enough to run:

[strzibny@dhcp-25-242 gem-patch]$ gem patch idn-0.0.2.gem rubygem-idn-0.0.2-Fix-for-ruby-1.9.x.patch 

Note: To reproduce this you have to add patched_package.spec.rubygems_version = 2.0.a in lib/rubygems/patcher.rb on line 74. This is because idn gem file uses RubyGems 1.8.

Josef Strzibny added some commits Oct 1, 2012

Add Gem::Commands::PatchCommand and Gem::Patcher
This adds the patch command to RubyGems. The patch command helps to patch gems without manually opening and rebuilding them. It opens a given .gem file, extracts it, patches it with system `patch` command, clones its spec, updates the file list and builds the patched gem.
Owner

drbrain commented Oct 2, 2012

This seems better as a RubyGems plugin, is there a reason it should be embedded in RubyGems?

See http://rubygems.rubyforge.org/rubygems-update/Gem.html#label-RubyGems+Plugins

Contributor

voxik commented Oct 4, 2012

It would be sad if one day, you wan to install gem-patch plugin only to find it cannot be installed and you need to patch it. There is higher chance that this will never happen, if it becomes part of RubyGems.

Owner

drbrain commented Oct 4, 2012

Historically we've asked proposed commands to live in plugins until an overwhelming need to include them in RubyGems is discovered.

As far as I know, patching gems is not something users do often, so this burden has not been met.

Owner

evanphx commented Oct 6, 2012

Agreed, this should be a plugin instead of in core.

@evanphx evanphx closed this Oct 6, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment