Este contenido no está disponible en el idioma seleccionado.
2.10. Converting a Conventional Spec File
This section discusses converting a conventional spec file into a Software Collection spec file so that the converted spec file can be used in both the conventional package and the Software Collection.
2.10.1. Example of the Converted Spec File Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
To see what the diff file comparing a conventional spec file with a converted spec file looks like, refer to the following example:
2.10.2. Converting Tags and Macro Definitions Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
The following steps show how to convert tags and macro definitions in a conventional spec file into a Software Collection spec file.
Procedure 2.1. Converting tags and macro definitions
- You can change the location of the root directory by defining the
%_scl_prefixmacro above the%scl_package macro:%{?scl:%global _scl_prefix /opt/provider}%{?scl:%global _scl_prefix /opt/provider}Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Add the
%scl_packagemacro to the spec file. Place the macro in front of the spec file preamble as follows:%{?scl:%scl_package package_name}%{?scl:%scl_package package_name}Copy to Clipboard Copied! Toggle word wrap Toggle overflow - You are advised to define the
%pkg_namemacro in the spec file preamble in case the package is not built for the Software Collection:%{!?scl:%global pkg_name %{name}}%{!?scl:%global pkg_name %{name}}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Consequently, you can use the%pkg_namemacro to define the original name of the package wherever it is needed in the spec file that you can then use for building both the conventional package and the Software Collection. - Change the
Nametag in the spec file preamble as follows:Name: %{?scl_prefix}package_nameName: %{?scl_prefix}package_nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow - If you are building or linking with other Software Collection packages, then prefix the names of those Software Collection packages in the
RequiresandBuildRequirestags with%{?scl_prefix}as follows:Requires: %{?scl_prefix}ifconfigRequires: %{?scl_prefix}ifconfigCopy to Clipboard Copied! Toggle word wrap Toggle overflow When depending on the system versions of packages, you should avoid using versionedRequiresorBuildRequires. If you need to depend on a package that could be updated by the system, consider including that package in your Software Collection, or remember to rebuild your Software Collection when the system package updates. - To check that all essential Software Collection's packages are dependencies of the main metapackage, add the following macro after the
BuildRequiresorRequirestags in the spec file:%{?scl:Requires: %scl_runtime}%{?scl:Requires: %scl_runtime}Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Prefix the
Obsoletes,ConflictsandBuildConflictstags with%{?scl_prefix}. This is to ensure that the Software Collection can be used to deploy new packages to older systems without having the packages specified, for example, byObsoleteremoved from the base system installation. For example:Obsoletes: %{?scl_prefix}lesspipe < 1.0Obsoletes: %{?scl_prefix}lesspipe < 1.0Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Prefix the
Providestag with%{?scl_prefix}, as in the following example:Provides: %{?scl_prefix}moreProvides: %{?scl_prefix}moreCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.10.3. Converting Subpackages Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
For any subpackages that define their name with the
-n option, prefix their name with %{?scl_prefix}, as in the following example:
%package -n %{?scl_prefix}more
%package -n %{?scl_prefix}more
Prefixing applies not only to the
%package macro, but also for %description and %files. For example:
%description -n %{?scl_prefix}rubygems
RubyGems is the Ruby standard for publishing and managing third party
libraries.
%description -n %{?scl_prefix}rubygems
RubyGems is the Ruby standard for publishing and managing third party
libraries.
In case the subpackage requires the main package, make sure to also adjust the
Requires tag in that subpackage so that the tag uses %{?scl_prefix}%{pkg_name}. For example:
Requires: %{?scl_prefix}%{pkg_name} = %{version}-%{release}
Requires: %{?scl_prefix}%{pkg_name} = %{version}-%{release}
2.10.4. Converting RPM Scripts Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
This section describes general rules for converting RPM scripts that can often be found in the
%prep, %build, %install, %check, %pre, and %post sections of a conventional spec file.
- Replace all occurrences of
%namewith%pkg_name. Most importantly, this includes adjusting the%setupmacro.- Adjust the
%setupmacro in the%prepsection of the spec file so that the macro can deal with a different package name in the Software Collection environment:%setup -q -n %{pkg_name}-%{version}%setup -q -n %{pkg_name}-%{version}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that the%setupmacro is required and that you must always use the macro with the-noption to successfully build your Software Collection.
- If you are using any of the
%_root_macros to point to the system file system hierarchy, you must use conditionals for these macros so that you can then use the spec file for building both the conventional package and the Software Collection. Edit the macros as in the following example:mkdir -p %{?scl:%_root_sysconfdir}%{?!scl:%_sysconfdir}mkdir -p %{?scl:%_root_sysconfdir}%{?!scl:%_sysconfdir}Copy to Clipboard Copied! Toggle word wrap Toggle overflow - When building Software Collection packages that depend on other Software Collection packages, it is often important to ensure that the
scl enablefunctionality links properly or run proper binaries, and so on. One of the examples where this is needed is compiling against a Software Collection library or running an interpreted script with the interpreter in the Software Collection.Wrap the script using the%{?scl:prefix, as in the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow It is important to specifyset -ein the script so that the script behavior is consistent regardless of whether the script is executed in therpmshell or thesclenvironment. - Pay attention to any scripts that are executed during the Software Collection package installation, such as:
%pretrans,%pre,%post,%postun,%posttrans,%triggerin,%triggerun, and%triggerpostun.
If you use thescl enablefunctionality in those scripts, you are advised to start with an empty environment to avoid any unintentional collisions with the base system installation.To do so, useenv -i -before enabling the Software Collection, as in the following example:%posttrans %{?scl:env -i - scl enable %{scl} - << \EOF} %vagrant_plugin_register %{vagrant_plugin_name} %{?scl:EOF}%posttrans %{?scl:env -i - scl enable %{scl} - << \EOF} %vagrant_plugin_register %{vagrant_plugin_name} %{?scl:EOF}Copy to Clipboard Copied! Toggle word wrap Toggle overflow - All hardcoded paths found in RPM scripts must be replaced with proper macros. For example, replace all occurrences of
/usr/sharewith%{_datadir}. This is needed because the$RPM_BUILD_ROOTvariable and the%{build_root}macro are not relocated by thesclmacro.
2.10.5. Software Collection Automatic Provides and Requires and Filtering Support Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
Important
The functionality described in this section is not available in Red Hat Enterprise Linux 6.
RPM in Red Hat Enterprise Linux 7 features support for automatic
Provides and Requires and filtering. For example, for all Python libraries, RPM automatically adds the following Requires:
Requires: python(abi) = (version)
Requires: python(abi) = (version)
As explained in Section 2.10, “Converting a Conventional Spec File”, you should prefix this
Requires with %{?scl_prefix} when converting your conventional RPM package:
Requires: %{?scl_prefix}python(abi) = (version))
Requires: %{?scl_prefix}python(abi) = (version))
Keep in mind that the scripts searching for these dependencies must sometimes be rewritten for your Software Collection, as the original RPM scripts are not extensible enough, and, in some cases, filtering is not usable. For example, to rewrite automatic Python
Provides and Requires, add the following lines in the macros.%{scl}-config macro file:
%__python_provides /usr/lib/rpm/pythondeps-scl.sh --provides %{_scl_root} %{scl_prefix}
%__python_requires /usr/lib/rpm/pythondeps-scl.sh --requires %{_scl_root} %{scl_prefix}
%__python_provides /usr/lib/rpm/pythondeps-scl.sh --provides %{_scl_root} %{scl_prefix}
%__python_requires /usr/lib/rpm/pythondeps-scl.sh --requires %{_scl_root} %{scl_prefix}
The
/usr/lib/rpm/pythondeps-scl.sh file is based on a pythondeps.sh file from the conventional package and adjusts search paths.
If there are
Provides or Requires that you need to adjust, for example, a pkg_config Provides, there are two ways to do it:
- Add the following lines in the
macros.%{scl}-configmacro file so that it applies to all packages in the Software Collection:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Or, alternatively, add the following lines after tag definitions in every spec file for which you want to filter
ProvidesorRequires:%{?scl:%filter_from_provides s|pkgconfig|%{?scl_prefix}pkgconfig|g} %{?scl:%filter_from_requires s|pkgconfig|%{?scl_prefix}pkgconfig|g} %{?scl:%filter_setup}%{?scl:%filter_from_provides s|pkgconfig|%{?scl_prefix}pkgconfig|g} %{?scl:%filter_from_requires s|pkgconfig|%{?scl_prefix}pkgconfig|g} %{?scl:%filter_setup}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Important
When using filters, you need to pay attention to the automatic dependencies you change. For example, if the conventional package contains
Requires: pkgconfig(package_1) and Requires: pkgconfig(package_2), and only package_2 is included in the Software Collection, ensure that you do not filter the Requires tag for package_1.
2.10.6. Software Collection Macro Files Support Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
In some cases, you may need to ship macro files with your Software Collection packages. They are located in the
%{?scl:%{_root_sysconfdir}}%{!?scl:%{_sysconfdir}}/rpm/ directory, which corresponds to the /etc/rpm/ directory for conventional packages. When shipping macro files, ensure that:
- You rename the macro files by appending
.%{scl}to their names so that they do not conflict with the files from the base system installation. - The macros in the macro files are either not expanded, or they are using conditionals, as in the following example:
%__python2 %{_bindir}/python %python2_sitelib %(%{?scl:scl enable %scl '}%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"%{?scl:'})%__python2 %{_bindir}/python %python2_sitelib %(%{?scl:scl enable %scl '}%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"%{?scl:'})Copy to Clipboard Copied! Toggle word wrap Toggle overflow
As another example, there may be a situation where you need to create a Software Collection mypython that depends on a Software Collection python26. The python26 Software Collection defines the
%{__python2} macro as in the above sample. This macro will evaluate to /opt/provider/mypython/root/usr/bin/python2, but the python2 binary is only available in the python26 Software Collection (/opt/provider/python26/root/usr/bin/python2).
To be able to build software in the mypython Software Collection environment, ensure that:
- The
macros.python.python26macro file, which is a part of the python26-python-devel package, contains the following line:%__python26_python2 /opt/provider/python26/root/usr/bin/python2
%__python26_python2 /opt/provider/python26/root/usr/bin/python2Copy to Clipboard Copied! Toggle word wrap Toggle overflow - And the macro file in the python26-build subpackage, and also the build subpackage in any depending Software Collection, contains the following line:
%scl_package_override() {%global __python2 %__python26_python2}%scl_package_override() {%global __python2 %__python26_python2}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
This will redefine the
%{__python2} macro only if the build subpackage from a corresponding Software Collection is present, which usually means that you want to build software for that Software Collection.
2.10.7. Software Collection Shebang Support Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
A shebang is a sequence of characters at the beginning of a script that is used as an interpreter directive. The shebang is processed by the automatic dependency generator and it points to a certain location, possibly in the system root file system.
When the automatic dependency generator processes the shebang, it adds dependencies according to the interpreters they point to. From the Software Collection point of view, there are two types of shebangs:
#!/usr/bin/env example- This shebang instructs the
/usr/bin/envprogram to run the interpreter.The automatic dependency generator will create a dependency on the/usr/bin/envprogram, as expected.If the$PATHenvironment variable is redefined properly in theenablescriptlet, the example interpreter is found in the Software Collection file system hierarchy, as expected.You are advised to rewrite the shebang in your Software Collection package so that the shebang specifies the full path to the interpreter located in the Software Collection file system hierarchy. #!/usr/bin/example- This shebang specifies the direct path to the interpreter.The automatic dependency generator will create a dependency on the
/usr/bin/exampleinterpreter located outside the Software Collection file system hierarchy. However, when building a package for your Software Collection, you often want to create a dependency on the%{?_scl_root}/usr/bin/exampleinterpreter located in the Software Collection file system hierarchy.Keep in mind that even when you properly redefine the$PATHenvironment variable, this has no effect on what interpreter is used. The system version of the interpreter located outside the Software Collection file system hierarchy is always used. In most cases, this is not desired.If you are using this type of shebang and you want the shebang to point to the Software Collection file system hierarchy when building your Software Collection package, use a command like the following:find %{buildroot} -type f | \ xargs sed -i -e '1 s"^#!/usr/bin/example"#!%{?_scl_root}/usr/bin/example"'find %{buildroot} -type f | \ xargs sed -i -e '1 s"^#!/usr/bin/example"#!%{?_scl_root}/usr/bin/example"'Copy to Clipboard Copied! Toggle word wrap Toggle overflow where /usr/bin/example is the interpreter you want to use.
2.10.8. Making a Software Collection Depend on Another Software Collection Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
To make one Software Collection depend on a package from another Software Collection, you need to adjust the
BuildRequires and Requires tags in the dependent Software Collection's spec file so that these tags properly define the dependency.
For example, to define dependencies on two Software Collections named software_collection_1 and software_collection_2, add the following three lines to your application's spec file:
BuildRequires: scl-utils-build Requires: %scl_require software_collection_1 Requires: %scl_require software_collection_2
BuildRequires: scl-utils-build
Requires: %scl_require software_collection_1
Requires: %scl_require software_collection_2
Ensure that the spec file also contains the
%scl_package macro in front of the spec file preamble, for example:
%{?scl:%scl_package less}
%{?scl:%scl_package less}
Note that the
%scl_package macro must be included in every spec file of your Software Collection.
You can also use the
%scl_require_package macro to define dependencies on a particular package from a specific Software Collection, as in the following example:
BuildRequires: scl-utils-build Requires: %scl_require_package software_collection_1 package_name
BuildRequires: scl-utils-build
Requires: %scl_require_package software_collection_1 package_name