Are you fed up by enabling multiple collections, which are dependent on themselves? We were. For example, thermostat needs mongo, mongo needs v8. Enabling them looks like:
scl enable thermostat1 mongodb24 v8314 bash
There another reason to use dependent collections: when you are missing packages in a RHSCL collection and you want to add them. Obviously, we don't plan to package everything because some packages have high maintenance costs or they are changing too fast even for two or three years of support.
Dependent collections have been available since RHSCL 1.1 and are supported by scl-utils-20131017 and higher.
Where are dependent collections are useful
Let's say you are using the ruby193 collection and would like to use additional gems. Some users are doing a rebuild of the existing ruby193 collection and mixing their gems with those provided by ruby193. It might lead to a problem, however, especially if RHSCL adds the same package as you previously added. It already has happened to the passenger gem where the user's version was overridden by RHSCL passenger and they were quite surprised by the new version. The correct solution is to package additional gems as a dependent collection. Another benefit would be portability to a new version of a ruby collection, so you could use your dependent collection even with ruby210 (or whatever will be in the next RHSCL Ruby release). It does work for passenger - see the passenger testing collection on the upstream pages.
How to create dependent collection
Now let's show you how to write specfiles to create a dependent collection. Let's look at the best existing example of dependent collections: Ruby on Rails (ror40) and Ruby (ruby200) as two collections and made them dependent.
Into ruby200.spec add scldevel subpackage:
%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. ... cat >> %{buildroot}%{_root_sysconfdir}/rpm/macros.%{scl_name_base}-scldevel << EOF %%scl_%{scl_name_base} %{scl} %%scl_prefix_%{scl_name_base} %{scl_prefix} EOF ... %files scldevel %{_root_sysconfdir}/rpm/macros.%{scl_name_base}-scldevel
This code will create file installed into /etc/rpm/macros.ruby-scldevel. It contains basic macros needed for dependent collection.
%scl_ruby ruby200 %scl_prefix_ruby ruby200-
You can access the whole source rpm package on upstream page and look at the whole specfile. No git yet, we are sorry.
How can you enable ruby200 collection as dependent collection? Just add scl_source macro into another specfile e.g. ror40 (ruby on rails). The dependent collection will be also automatically enabled, you will need to run only scl enable ror40 and ruby200 will be enabled automatically. You can enable more collections than one. Let's look at example of ror40 specfile:
# Fallback to ruby200 in case ruby200-scldevel is not available. %{!?scl_ruby:%global scl_ruby ruby200} # Must be defined for enabling ruby200 collection because standard # scl_prefix macro will contain ror40 in this specfile. %{!?scl_prefix_ruby:%global scl_prefix_ruby %{scl_ruby}-} ... # Don't forget to add ruby200-scldevel into build requirements of package BuildRequires: %{scl_prefix_ruby}scldevel ... # Install section calls scl_source for enabling ruby200 collection in ror40 enable scriptlet. %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
The source rpm is again on the upstream page. You can access complete collections on softwarecollections.org for more experiments.
Where to put scl_source
The dependency between Ruby and RoR was obvious, but in other cases it may not be so straight forward. For example v8 as javascript interpreter is enabled by rubygem-rubyracer, which is using it. The v8 is not automatically enabled for all of ror40, because not all gems or all customers use it. It's up to your actual use-case where you put the scl_source.
Last updated: November 2, 2023