4.3. 扩展 rh-ruby23 软件集合
在 Red Hat Software Collections 3.8 中,可以通过添加依赖软件包来扩展 rh-ruby23 Software Collection。Ruby on Rails 4.2 (rh-ror42) Software Collection 基于 rh-ruby23 Software Collection 提供的 Ruby 2.3 构建,是这样的扩展的一个示例。
本节提供有关 rh-ror42 metapackage 和 rh-ror42-rubygem-bcrypt 软件包的详细信息,它们是 rh-ror42 软件集合的一部分。
4.3.1. rh-ror42 Software Collection 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
本节包含 rh-ror42 软件集合的 Ruby on Rails 4.2 metapackage 的注释示例。rh-ror42 Software Collection 依赖于 rh-ruby23 Software Collection。
注意 rh-ror42 Software Collection metapackage 示例中的以下内容:
- rh-ror42 Software Collection spec 文件设置了以下构建依赖项:
BuildRequires: %{scl_prefix_ruby}scldevel BuildRequires: %{scl_prefix_ruby}rubygems-devel例如,这扩展至 rh-ruby23-scldevel 和 rh-ruby23-rubygems-devel。rh-ruby23-scldevel 子软件包包含两个重要的宏%scl_ruby和%scl_prefix_ruby。rh-ruby23-scldevel 子软件包应该在构建 root 中提供。如果有多个 Ruby Software Collections 可用,rh-ruby23-scldevel 决定应使用哪个可用 Software Collections。请注意,%scl_ruby和%scl_prefix_ruby宏也定义在 spec 文件的顶部。虽然定义不是必需的,但它们提供了一个可视化提示,但 rh-ror42 Software Collection 已设计为基于 rh-ruby23 Software Collection 构建。它们也充当回退值。 - rh-ror42-runtime 子软件包必须依赖于它依赖的软件集合的 runtime 子软件包。这个依赖项指定如下:
%package runtime Requires: %{scl_prefix_ruby}runtime当软件包针对 rh-ruby23 软件集合构建时,这扩展至 rh-ruby23-runtime。 - rh-ror42-build 子软件包必须依赖于它依赖的软件集合的 scldevel 子软件包。这是为了确保这个 Software Collection 的所有其他软件包都定义相同的宏,因此针对同一 Ruby 版本构建它。
%package build Requires: %{scl_prefix_ruby}scldevel如果是 rh-ruby23 Software Collection,这扩展至 rh-ruby23-scldevel。 - rh-ror42 Software Collection 的
enablescriptlet 包含以下行:. scl_source enable %{scl_ruby}请注意行开头的点。当 rh-ror42 Software Collection 启动时,此行使 Ruby Software Collection 会隐式启动,以便用户只能键入 scl enable rh-ror42 命令而不是 scl enable rh-ruby23 rh-ror42 命令,以便在 Software Collection 环境中运行命令。 - 提供了 rh-ror42-scldevel 子软件包,以便在需要它来构建软件集合来扩展 rh-ror42 Software Collection 时可用。软件包提供
%{scl_ror}和%{scl_prefix_ror}宏,可用于扩展 rh-ror42 软件集合。 - 由于 rh-ror42 Software Collection 的 gem 安装在单独的 root 目录结构中,您需要确保设置了 rubygems 目录的正确所有权。这可以通过使用代码片段生成文件列表 rubygems_filesystem.list 来完成。建议您将 runtime 软件包设置为拥有所有目录(如果位于 root 文件系统中)归另一个软件包所有。例如,当 rh-ror42 Software Collection 是 Rubygem 目录结构时,此类目录的一个示例。
%global scl_name_prefix rh-
%global scl_name_base ror
%global scl_name_version 41
%global scl %{scl_name_prefix}%{scl_name_base}%{scl_name_version}
# Fallback to rh-ruby23. rh-ruby23-scldevel is unlikely to be available in
# the build root.
%{!?scl_ruby:%global scl_ruby rh-ruby23}
%{!?scl_prefix_ruby:%global scl_prefix_ruby %{scl_ruby}-}
# Do not produce empty debuginfo package.
%global debug_package %{nil}
# Support SCL over NFS.
%global nfsmountable 1
%{!?install_scl: %global install_scl 1}
%scl_package %scl
Summary: Package that installs %scl
Name: %scl_name
Version: 2.0
Release: 5%{?dist}
License: GPLv2+
%if 0%{?install_scl}
Requires: %{scl_prefix}rubygem-therubyracer
Requires: %{scl_prefix}rubygem-sqlite3
Requires: %{scl_prefix}rubygem-rails
Requires: %{scl_prefix}rubygem-sass-rails
Requires: %{scl_prefix}rubygem-coffee-rails
Requires: %{scl_prefix}rubygem-jquery-rails
Requires: %{scl_prefix}rubygem-sdoc
Requires: %{scl_prefix}rubygem-turbolinks
Requires: %{scl_prefix}rubygem-bcrypt
Requires: %{scl_prefix}rubygem-uglifier
Requires: %{scl_prefix}rubygem-jbuilder
Requires: %{scl_prefix}rubygem-spring
%endif
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
# The enable scriptlet depends on the ruby executable.
Requires: %{scl_prefix_ruby}ruby
%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
Provides: scldevel(%{scl_name_base})
%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}:%{_sbindir}\${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_PATH:=%{gem_dir}:\`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
set -e
# Fake rh-ror42 Software Collection environment.
GEM_PATH=%{gem_dir}:`ruby -e "print Gem.path.join(':')"` \
X_SCLS=%{scl} \
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'.to_sym].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 2015 John Doe <jdoe@example.com> - 1-1
- Initial package.
4.3.2. rh-ror42-rubygem-bcrypt 软件包 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
以下是 rh-ror42-rubygem-bcrypt 软件包 spec 文件的注释示例。这个软件包提供 bcrypt Ruby gem。有关 bcrypt 的更多信息,请参阅以下网站:
请注意,rh-ror42-rubygem-bcrypt 软件包 spec 文件和普通 Software Collection 软件包 spec 文件之间的唯一显著区别如下:
BuildRequires标签前缀为%{?scl_prefix_ruby}而不是%{scl_prefix}。
%{?scl:%scl_package rubygem-%{gem_name}}
%{!?scl:%global pkg_name %{name}}
%global gem_name bcrypt
Summary: Wrapper around bcrypt() password hashing algorithm
Name: %{?scl_prefix}rubygem-%{gem_name}
Version: 3.1.9
Release: 2%{?dist}
Group: Development/Languages
# ext/* - Public Domain
# spec/TestBCrypt.java - ISC
License: MIT and Public Domain and ISC
URL: https://github.com/codahale/bcrypt-ruby
Source0: http://rubygems.org/downloads/%{gem_name}-%{version}.gem
Requires: %{?scl_prefix_ruby}ruby(release)
Requires: %{?scl_prefix_ruby}ruby(rubygems)
BuildRequires: %{?scl_prefix_ruby}rubygems-devel
BuildRequires: %{?scl_prefix_ruby}ruby-devel
BuildRequires: %{?scl_prefix}rubygem(rspec)
Provides: %{?scl_prefix}rubygem(bcrypt) = %{version}
%description
bcrypt() is a sophisticated and secure hash algorithm designed by The
OpenBSD project for hashing passwords. bcrypt provides a simple,
humane wrapper for safely handling passwords.
%package doc
Summary: Documentation for %{pkg_name}
Group: Documentation
Requires: %{?scl_prefix}%{pkg_name} = %{version}-%{release}
%description doc
Documentation for %{pkg_name}.
%prep
%setup -n %{pkg_name}-%{version} -q -c -T
%{?scl:scl enable %{scl} - << \EOF}
%gem_install -n %{SOURCE0}
%{?scl:EOF}
%build
%install
mkdir -p %{buildroot}%{gem_dir}
cp -pa .%{gem_dir}/* \
%{buildroot}%{gem_dir}/
mkdir -p %{buildroot}%{gem_extdir_mri}
cp -pa .%{gem_extdir_mri}/* %{buildroot}%{gem_extdir_mri}/
# Prevent a symlink with an invalid target in -debuginfo (BZ#878863).
rm -rf %{buildroot}%{gem_instdir}/ext/
%check
%{?scl:scl enable %{scl} - << \EOF}
pushd .%{gem_instdir}
# 2 failutes due to old RSpec
# https://github.com/rspec/rspec-expectations/pull/284
rspec -I$(dirs +1)%{gem_extdir_mri} spec |grep '34 examples, 2 failures' || exit 1
popd
%{?scl:EOF}
%files
%dir %{gem_instdir}
%exclude %{gem_instdir}/.*
%{gem_libdir}
%{gem_extdir_mri}
%exclude %{gem_cache}
%{gem_spec}
%doc %{gem_instdir}/COPYING
%files doc
%doc %{gem_docdir}
%doc %{gem_instdir}/README.md
%doc %{gem_instdir}/CHANGELOG
%{gem_instdir}/Rakefile
%{gem_instdir}/Gemfile*
%{gem_instdir}/%{gem_name}.gemspec
%{gem_instdir}/spec
%changelog
* Fri Mar 21 2015 John Doe <jdoe@example.com> - 3.1.2-4
- Initial package.
4.3.3. 构建 rh-ror42 Software Collection 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
构建 rh-ror42 Software Collection:
- 安装 rh-ruby23-scldevel 子软件包,它是 rh-ruby23 软件集合的一部分。
- 构建
rh-ror42.spec并安装 ror42-runtime 和 ror42-build 软件包。 - 构建
rubygem-bcrypt.spec。
4.3.4. 测试 rh-ror42 Software Collection 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
测试 rh-ror42 Software Collection:
- 安装 rh-ror42-rubygem-bcrypt 软件包。
- 运行以下命令:
$ scl enable rh-ror42 -- ruby -r bcrypt -e "puts BCrypt::Password.create('my password')" - 验证输出是否包含以下行:
$2a$10$s./ReniLY.wXPHVBQ9npoeyZf5KzywfpvI5lhjG6Ams3u0hKqwVbW