How to patch ruby's gem before an install?

Hi,

got stuck and cann’t find appropriate guide how can I patch gem package
before it gets installed.

For example I’m trying to fix gem for Gosu library:

  1. download the gem with “gem fetch gosu”
  2. extract contents of the gem with “gem unpack gosu-0.7.45.gem”
  3. apply a patch: cd gosu-0.7.45 && patch -p1
    /path/to/patch/fix_cflags.patch
  4. ??? how to rebuild a gem from modified sources ? I cann’t find the
    original gemspec.
  5. ??? install modified gem with gem install ./gosu-0.7.45.gem

Any idea ?

Thx, David

Quoting David U. [email protected]:

/path/to/patch/fix_cflags.patch
4. ??? how to rebuild a gem from modified sources ? I cann’t find the
original gemspec.
5. ??? install modified gem with gem install ./gosu-0.7.45.gem

I think you better look for the source code. Gosu is in
https://github.com/jlnr/gosu . You can find the link for the source
code in rubygems.org.

In this case is in github, so you can clone and even fork and do a
pull request to request your changes be in the next version for gosu.

regards

jordi

Jordi Massaguer P. wrote in post #1075065:

I think you better look for the source code. Gosu is in
https://github.com/jlnr/gosu . You can find the link for the source
code in rubygems.org.

In this case is in github, so you can clone and even fork and do a
pull request to request your changes be in the next version for gosu.

regards

jordi

Ok, I can use the git sources and maybe install the libs with rake, but
still curious how to modify & rebuild the gem. I thought it has to be a
simple task.

If it’s a pure Ruby gem I think this simple command builds the gem
package:

gem build mygem.gemspec

http://docs.rubygems.org/read/chapter/5#page18

For Gosu, because it has native extension, use the included Rakefile to
build the gem package.

  • Jeff

2012/9/7 David U. [email protected]:

  1. ??? how to rebuild a gem from modified sources ? I cann’t find the
    original gemspec.

Doesn’t gem build work for you?

  1. ??? install modified gem with gem install ./gosu-0.7.45.gem

gem install gosu --local.

Also, .gem files are just ZIP archives, you can unpack them with any
archiver and modify the contents.

– Matma R.

On Sep 7, 2012, at 10:21 AM, Bartosz Dziewoński [email protected]
wrote:

2012/9/7 David U. [email protected]:

  1. ??? how to rebuild a gem from modified sources ? I cann’t find the
    original gemspec.

Doesn’t gem build work for you?

gem unpack --spec

Will retrieve the original gem spec from the gem. If you’ve added new
files you will need to update the gemspec.

Move this file into the unpacked gem directory then run gem build

  1. ??? install modified gem with gem install ./gosu-0.7.45.gem

gem install gosu --local.

Also, .gem files are just ZIP archives, you can unpack them with any
archiver and modify the contents.

.gem files are tar files which contain (at least) a gzipped YAML file
(metadata.gz, the gem spec) and a data.tar.gz (A gzipped tar file).
Tools that only handle zip will not unpack them.

Eric H. wrote in post #1075073:

On Sep 7, 2012, at 10:21 AM, Bartosz Dziewoński [email protected]
wrote:

2012/9/7 David U. [email protected]:

  1. ??? how to rebuild a gem from modified sources ? I cann’t find the
    original gemspec.

Doesn’t gem build work for you?

gem unpack --spec

I did missed this option. THAT’s the answer. Thank you.

Will retrieve the original gem spec from the gem. If you’ve added new
files you will need to update the gemspec.

Move this file into the unpacked gem directory then run gem build

  1. ??? install modified gem with gem install ./gosu-0.7.45.gem

gem install gosu --local.

Also, .gem files are just ZIP archives, you can unpack them with any
archiver and modify the contents.

.gem files are tar files which contain (at least) a gzipped YAML file
(metadata.gz, the gem spec) and a data.tar.gz (A gzipped tar file).
Tools that only handle zip will not unpack them.

Correct. In addition all files stored in gem (tar) archive and
subarchive data.tar.gz have time set to 1.1.1970.

Why not just clone/fork it from GitHub, apply your patch and commit it,
then use bundler to install the gem using the :git => syntax?

gem ‘gosu’, :git => ‘git://github.com/yourname/gosu.git’ , or
gem ‘gosu’, :git => ‘/myproject/src/gosu.git’ (if it’s on your hard
drive)

I’m a bit for a Ruby noob but have modified gems this way myself several
times, very easy. Gosu has native code in C++ so not sure if that
affects
it. If the above syntax fails, you can try running the Rakefile included
in
the source to build the gem package locally.

  • Jeff

On 8/09/2012, at 5:14 AM, David U. wrote:

Ok, I can use the git sources and maybe install the libs with rake, but
still curious how to modify & rebuild the gem. I thought it has to be a
simple task.

rake release
or gem build

Henry

2012/9/7 Eric H. [email protected]:

On Sep 7, 2012, at 10:21 AM, Bartosz Dziewoński [email protected] wrote:

Also, .gem files are just ZIP archives, you can unpack them with any
archiver and modify the contents.

.gem files are tar files which contain (at least) a gzipped YAML file
(metadata.gz, the gem spec) and a data.tar.gz (A gzipped tar file). Tools that
only handle zip will not unpack them.

Whoops, thanks for the correction.

– Matma R.

If any of the people coming here still needs this, try my plugin
gem-patch[1].

[1] https://github.com/strzibny/gem-patch

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs