|
Building gems
|
|
|
Since gems aren't just an archive format but instead encapsulate both an archive and information used for building the Ruby library, building an RPM from a gem looks a little different from other RPMs.
|
|
|
A sample spec for building gems would look like this:
|
|
|
%prep %setup -q -n %{gem_name}-%{version}
|
|
|
# Modify the gemspec if necessary # Also apply patches to code if necessary %patch0 -p1
|
|
|
%build # Create the gem as gem install only works on a gem file gem build ../%{gem_name}-%{version}.gemspec
|
|
|
# %%gem_install compiles any C extensions and installs the gem into ./%%gem_dir # by default, so that we can move it into the buildroot in %%install %gem_install
|
|
|
%install mkdir -p %{buildroot}%{gem_dir} cp -a ./%{gem_dir}/* %{buildroot}%{gem_dir}/
|
|
|
# If there were programs installed: mkdir -p %{buildroot}%{_bindir} cp -a ./%{_bindir}/* %{buildroot}%{_bindir}
|
|
|
# If there are C extensions, copy them to the extdir. mkdir -p %{buildroot}%{gem_extdir_mri} cp -a .%{gem_extdir_mri}/{gem.build_complete,*.so} %{buildroot}%{gem_extdir_mri}/
|
|
|
%prep
|
|
|
RPM (as of 4.14) can directly unpack gem archives, so we can call `gem unpack` to extract the source from the gem. Then we call `+%setup -n %{gem_name}-%{version}+` to tell rpm what the directory the gem has unpacked into. At the same directory level, the %\{gem_name}-%\{version}.gemspec file is created automatically as well. This `.gemspec` file will be used to rebuild the gem later. If we need to modify the `.gemspec` (for instance, if the version of dependencies is wrong for Fedora or the `.gemspec` is using old, no longer supported fields) we would do it here. Patches to the code itself can also be done here.
|
|
|
%build
|
|
|
Next we build the gem. Because `+%gem_install+` only operates on gem archives, we next recreate the gem with `gem build`. The gem file that is created is then used by `+%gem_install+` to build and install the code into the temporary directory, which is `+./%{gem_dir}+` by default. We do this because the `+%gem_install+` command both builds and installs the code in one step so we need to have a temporary directory to place the built sources before installing them in `+%install+` section.
|
|
|
`+%gem_install+` macro accepts two additional options:
|
|
|
-n <gem_file>
|
|
|
Allows to override gem used for installation. This might get useful for converting legacy spec, so you might specify %\{SOURCE0} as a gem for installation.
|
|
|
-d <install_dir>
|
|
|
Might override the gem installation destination. However we do not suggest to use this option.
|
|
|
The `+%gem_install+` macro MUST NOT be used to install into the `+%{buildroot}+`
|
|