4.3. Extending the ruby193 and ruby200 Software Collections

In Red Hat Software Collections 1.2 Beta, it is possible to extend the ruby193 and ruby200 Software Collections by adding dependent packages. The Ruby on Rails 4.0 (ror40) Software Collection, which is built on top of Ruby 2.0.0 provided by the ruby200 Software Collection, is one example of such an extension.
This section provides detailed information about the ror40 metapackage and the ror40-rubygem-bcrypt-ruby package, which are both part of the ror40 Software Collection.

4.3.1. The ror40 Software Collection

This section contains a commented example of the Ruby on Rails 4.0 metapackage for the ror40 Software Collection. The ror40 Software Collection depends on the ror200 Software Collection.
Note the following in the ror40 Software Collection spec file example:
  • The ror40 Software Collection spec file has the following build dependencies set:
    BuildRequires: %{scl_prefix_ruby}scldevel
    BuildRequires: %{scl_prefix_ruby}rubygems-devel
    This expands to, for example, ruby200-scldevel and ruby200-rubygems-devel.
    The ruby200-scldevel subpackage contains two important macros, %scl_ruby and %scl_prefix_ruby. The ruby200-scldevel subpackage should be available in the build root. It specifies which of the available Ruby Software Collections you want to use. You can also replace it with the ruby193-scldevel subpackage.
    Note that the %scl_ruby and %scl_prefix_ruby macros are also defined at the top of the spec file. Although the definitions are not required, they provide a visual hint that the ror40 Software Collection has been designed to be built on top of the ruby200 Software Collection. They also serve as a fallback value.
  • The ror40-runtime subpackage must depend on the runtime subpackage of the Software Collection it depends on. This dependency is specified as follows:
    %package runtime
    Requires: %{scl_prefix_ruby}runtime
    This expands to ruby200-runtime in the case of the ruby200 Software Collection, and to ruby193-runtime in the case when the package is built against the ruby193 Software Collection.
  • The ror40-build subpackage must depend on the scldevel subpackage of the Software Collection it depends on. This is to ensure that all other packages of this Software Collection will have the same macros defined, thus it is built against the same Ruby version.
    %package build
    Requires: %{scl_prefix_ruby}scldevel
    In the case of the ruby200 Software Collection, this expands to ruby200-scldevel.
  • The enable scriptlet for the ror40 Software Collection contains the following line:
    . scl_source enable %{scl_ruby}
    Note the dot at the beginning of the line. This line makes the Ruby Software Collection start implicitly when the ror40 Software Collection is started so that the user can only type scl enable ror40 command instead of scl enable ruby200 ror40 command to run command in the Software Collection environment.
  • The ror40-scldevel subpackage is provided so that it is available in case you need it to build a Software Collection which extends the ror40 Software Collection. The package provides the %{scl_ror} and %{scl_prefix_ror} macros, which can be used to extend the ror40 Software Collection.
  • Because the ror40 Software Collection's gems are installed in a separate root directory structure, you need to ensure that the correct ownership for the rubygems directories is set. This is done by using a snippet to generate a file list rubygems_filesystem.list.
    You are advised to set the runtime package to own all directories which would, if located in the root file system, be owned by another package. One example of such directories in the case of the ror40 Software Collection is the Rubygem directory structure.
%global scl_name_base ror
%global scl_name_version 40

%global scl %{scl_name_base}%{scl_name_version}
%scl_package %scl

# Fallback to ruby200. ruby200-scldevel is unlikely to be available in
# the build root.
%{!?scl_ruby:%global scl_ruby ruby200}
%{!?scl_prefix_ruby:%global scl_prefix_ruby %{scl_ruby}-}

Summary: Package that installs %scl
Name: %scl_name
Version: 1.1
Release: 3%{?dist}
License: GPLv2+

BuildRequires: help2man
BuildRequires: scl-utils-build
BuildRequires: %{scl_prefix_ruby}scldevel
BuildRequires: %{scl_prefix_ruby}rubygems-devel

%description
This is the main package for %scl Software Collection.

%package runtime
Summary: Package that handles %scl Software Collection.
Requires: scl-utils
Requires: %{scl_prefix_ruby}runtime

%description runtime
Package shipping essential scripts to work with %scl Software Collection.

%package build
Summary: Package shipping basic build configuration
Requires: scl-utils-build
Requires: %{scl_runtime}
Requires: %{scl_prefix_ruby}scldevel

%description build
Package shipping essential configuration macros to build %scl Software Collection.

%package scldevel
Summary: Package shipping development files for %scl

%description scldevel
Package shipping development files, especially usefull for development of
packages depending on %scl Software Collection.

%prep
%setup -c -T

%install
%scl_install

cat >> %{buildroot}%{_scl_scripts}/enable << EOF
export PATH=%{_bindir}\${PATH:+:\${PATH}}
export LD_LIBRARY_PATH=%{_libdir}\${LD_LIBRARY_PATH:+:\${LD_LIBRARY_PATH}}
export MANPATH=%{_mandir}:\${MANPATH}
export PKG_CONFIG_PATH=%{_libdir}/pkgconfig\${PKG_CONFIG_PATH:+:\${PKG_CONFIG_PATH}}
export GEM_PATH=%{gem_dir}:\${GEM_PATH:+\${GEM_PATH}}\${GEM_PATH:-\`scl enable %{scl_ruby} -- ruby -e "print Gem.path.join(':')"\`}

. scl_source enable %{scl_ruby}
EOF

cat >> %{buildroot}%{_root_sysconfdir}/rpm/macros.%{scl_name_base}-scldevel << EOF
%%scl_%{scl_name_base} %{scl}
%%scl_prefix_%{scl_name_base} %{scl_prefix}
EOF


scl enable %{scl_ruby} - << \EOF
# Fake ror40 Software Collection environment.
GEM_PATH=%{gem_dir}:${GEM_PATH:+${GEM_PATH}}${GEM_PATH:-`ruby -e "print Gem.path.join(':')"`} \
X_SCLS=ror40 \
ruby -rfileutils > rubygems_filesystem.list << \EOR
  # Create the RubyGems file system.
  Gem.ensure_gem_subdirectories '%{buildroot}%{gem_dir}'
  FileUtils.mkdir_p File.join '%{buildroot}', Gem.default_ext_dir_for('%{gem_dir}')

  # Output the relevant directories.
  Gem.default_dirs[:%{scl}_system].each { |k, p| puts p }
EOR
EOF

%files

%files runtime -f rubygems_filesystem.list
%scl_files

%files build
%{_root_sysconfdir}/rpm/macros.%{scl}-config

%files scldevel
%{_root_sysconfdir}/rpm/macros.%{scl_name_base}-scldevel


%changelog
* Thu Jan 16 2014 John Doe <jdoe@example.com> - 1-1
- Initial package.