Hi guys,
I've had fun with patching some rubygems lately, and wasn't entirely
fond of how we do it currently. Thus, I'd like to propose a little
addition to our rubygem macros we provide to packagers.
Currently we only have the %gem_install macro, which has several
shortcomings. Not only does everything happen within %buildroot (with
%prep and %build sections unused), it also makes patching unpacked
sources tedious. You have to provide patches as 'SourceX' and cd into
the gem install path in the buildroot in order to patch in the %install
section... Last but not least, this only works by the help of a
openSUSE-specific patch for rubygems (adding buildroot support for 'gem
install'), thus the ugly "Buildrequires: rubygems_with_buildroot_patch"
everywhere. What we actually want to have instead is something like this:
%setup
%gem_unpack %{SOURCE0}
# or now possible (if we package a source tarball):
%setup -q
# and now possible:
%patch1 ...
%build
%gem_build
%install
%gem_install
%clean
%gem_cleanup
I hacked something together in 'home:saschpe:ruby', there's a new
'rubygems' package which adds the above macros and two example packages:
rubygem-gem2rpm - has a gemspec in it's gem file
rubygem-yard - build from source tarball (the gem ships no gemspec)
Without much ado, here are the current macro definitions:
%gem_unpack() \
if [ %# -eq 0 ]; then \
/usr/bin/gem unpack --verbose %{SOURCE0} \
else \
/usr/bin/gem unpack --verbose %1 \
fi \
cd %{mod_name}-%{version} \
%{nil}
%gem_build() \
GEMSPEC_SOURCE_DIR=`find . -maxdepth 2 -type f -name "*.gemspec" |
xargs dirname` \
cd $GEMSPEC_SOURCE_DIR && /usr/bin/gem build --verbose *.gemspec \
%{nil}
%gem_install() \
if [ %# -eq 1 ]; then \
/usr/bin/gem install --verbose --local --build-root=%{buildroot} \
else \
GEM_FILE=`find . -maxdepth 2 -type f -name
"%{mod_name}-%{version}.gem"` \
/usr/bin/gem install --verbose --local --bindir
%{buildroot}%{_bindir} --install-dir
%{buildroot}%{_libdir}/ruby/gems/%{rb_ver} $GEM_FILE \
fi \
%{nil}
The %gem_unpack macro is only useful if your gem actually has a gemspec,
otherwise plain old %setup and a source tarball will do. As you can see,
the %gem_install macro still has the old behavior when one parameter is
provided. Currently, the %gem_build macro tries to find the gemspec,
because 'gem build' wants to be in the same directory. Lastly, the
%gem_install macro searches the resulting gem, as git source tarballs
tend to have funny directory names
As a next step, I would like to adjust gem2rpm-opensuse to generate spec
files accordingly. If we decide to use this in d:l:r:e, we hopefully can
get away with that buildroot patch eventually.
I'm sure there's a lot of room for improvement, so what do you think?
p.s.: Please CC me, I'm not subscribed to this list!
--
Viele Grüße,
Sascha Peilicke