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

···

--
Posted via http://www.ruby-forum.com/.

Quoting David Unric <lists@ruby-forum.com>:

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

I think you better look for the source code. Gosu is in GitHub - gosu/gosu: 2D game development library for Ruby and C++ . 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

···

Any idea ?

Thx, David

--
Posted via http://www.ruby-forum.com/\.

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 Sat, Sep 8, 2012 at 12:25 AM, David Unric <lists@ruby-forum.com> wrote:

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

--
Posted via http://www.ruby-forum.com/\.

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

Doesn't `gem build` work for you?

5. ??? 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 Rex

···

2012/9/7 David Unric <lists@ruby-forum.com>:

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

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

···

--
Posted via http://www.ruby-forum.com/.

Jordi Massaguer Pla wrote in post #1075065:

I think you better look for the source code. Gosu is in
GitHub - gosu/gosu: 2D game development library for Ruby and C++ . 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.

···

--
Posted via http://www.ruby-forum.com/\.

4. ??? 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`

5. ??? 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.

···

On Sep 7, 2012, at 10:21 AM, Bartosz Dziewoński <matma.rex@gmail.com> wrote:

2012/9/7 David Unric <lists@ruby-forum.com>:

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

···

On Sat, Sep 8, 2012 at 1:14 AM, David Unric <lists@ruby-forum.com> wrote:

Jordi Massaguer Pla 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.

--
Posted via http://www.ruby-forum.com/\.

Eric Hodel wrote in post #1075073:

4. ??? 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`

5. ??? 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.

···

On Sep 7, 2012, at 10:21 AM, Bartosz Dziewoński <matma.rex@gmail.com> > wrote:

2012/9/7 David Unric <lists@ruby-forum.com>:

--
Posted via http://www.ruby-forum.com/\.

Whoops, thanks for the correction.

-- Matma Rex

···

2012/9/7 Eric Hodel <drbrain@segment7.net>:

On Sep 7, 2012, at 10:21 AM, Bartosz Dziewoński <matma.rex@gmail.com> 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.

rake release
or gem build

Henry

···

On 8/09/2012, at 5:14 AM, David Unric 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.