0fce6c
# The RubyGems root folder.
0fce6c
%gem_dir %{_datadir}/gems
0fce6c
%gem_archdir %{_libdir}/gems
0fce6c
0fce6c
# Common gem locations and files.
0fce6c
%gem_instdir %{gem_dir}/gems/%{gem_name}-%{version}%{?prerelease}
0fce6c
%gem_extdir_mri %{gem_archdir}/%{name}/%{gem_name}-%{version}%{?prerelease}
0fce6c
%gem_libdir %{gem_instdir}/lib
0fce6c
%gem_cache %{gem_dir}/cache/%{gem_name}-%{version}%{?prerelease}.gem
0fce6c
%gem_spec %{gem_dir}/specifications/%{gem_name}-%{version}%{?prerelease}.gemspec
0fce6c
%gem_docdir %{gem_dir}/doc/%{gem_name}-%{version}%{?prerelease}
0fce6c
0fce6c
0fce6c
# %gem_install - Install gem into appropriate directory.
0fce6c
#
0fce6c
# Usage: %gem_install [options]
0fce6c
#
0fce6c
# -n <gem_file>      Overrides gem file name for installation.
0fce6c
# -d <install_dir>   Set installation directory.
0fce6c
#
0fce6c
%gem_install(d:n:) \
0fce6c
mkdir -p %{-d*}%{!?-d:.%{gem_dir}} \
0fce6c
\
0fce6c
CONFIGURE_ARGS="--with-cflags='%{optflags}' --with-cxxflags='%{optflags}' $CONFIGURE_ARGS" \\\
0fce6c
gem install \\\
0fce6c
        -V \\\
0fce6c
        --local \\\
0fce6c
        --build-root %{-d*}%{!?-d:.} \\\
0fce6c
        --force \\\
0fce6c
        --document=ri,rdoc \\\
0fce6c
        %{-n*}%{!?-n:%{gem_name}-%{version}%{?prerelease}.gem} \
0fce6c
%{nil}
0fce6c
0fce6c
0fce6c
# For rubygems packages we want to filter out any provides caused by private
0fce6c
# libs in %%{gem_archdir}.
0fce6c
#
0fce6c
# Note that this must be invoked in the spec file, preferably as
0fce6c
# "%{?rubygems_default_filter}", before any %description block.
0fce6c
%rubygems_default_filter %{expand: \
0fce6c
%global __provides_exclude_from %{?__provides_exclude_from:%{__provides_exclude_from}|}^%{gem_extdir_mri}/.*\\\\.so$ \
0fce6c
}
0fce6c
0fce6c
0fce6c
# The 'read' command in %%gemspec_* macros is not essential, but it is usefull
0fce6c
# to make the sript appear in build log.
0fce6c
0fce6c
0fce6c
# %gemspec_add_dep - Add dependency into .gemspec.
0fce6c
#
0fce6c
# Usage: %gemspec_add_dep -g <gem> [options] [requirements]
0fce6c
#
0fce6c
# Add dependency named <gem> to .gemspec file. The macro adds runtime
0fce6c
# dependency by default. The [requirements] argument can be used to specify
0fce6c
# the dependency constraints more precisely. It is expected to be valid Ruby
0fce6c
# code.
0fce6c
#
0fce6c
# -s <gemspec_file>   Overrides the default .gemspec location.
0fce6c
# -d                  Add development dependecy.
0fce6c
#
0fce6c
%gemspec_add_dep(g:s:d) \
0fce6c
read -d '' gemspec_add_dep_script << 'EOR' || : \
0fce6c
  gemspec_file = '%{-s*}%{!?-s:%{_builddir}/%{gem_name}-%{version}%{?prerelease}.gemspec}' \
0fce6c
  \
0fce6c
  name = '%{-g*}' \
0fce6c
  requirements = %{*}%{!?1:nil} \
0fce6c
  \
0fce6c
  type = :%{!?-d:runtime}%{?-d:development} \
0fce6c
  \
0fce6c
  spec = Gem::Specification.load(gemspec_file) \
0fce6c
  abort("#{gemspec_file} is not accessible.") unless spec \
0fce6c
  \
0fce6c
  dep = spec.dependencies.detect { |d| d.type == type && d.name == name } \
0fce6c
  if dep \
0fce6c
    dep.requirement.concat requirements \
0fce6c
  else \
0fce6c
    spec.public_send "add_#{type}_dependency", name, requirements \
0fce6c
  end \
0fce6c
  File.write gemspec_file, spec.to_ruby \
0fce6c
EOR\
0fce6c
echo "$gemspec_add_dep_script" | ruby \
0fce6c
unset -v gemspec_add_dep_script \
0fce6c
%{nil}
0fce6c
0fce6c
0fce6c
# %gemspec_remove_dep - Remove dependency from .gemspec.
0fce6c
#
0fce6c
# Usage: %gemspec_remove_dep -g <gem> [options] [requirements]
0fce6c
#
0fce6c
# Remove dependency named <gem> from .gemspec file. The macro removes runtime
0fce6c
# dependency by default. The [requirements] argument can be used to specify
0fce6c
# the dependency constraints more precisely. It is expected to be valid Ruby
0fce6c
# code. The macro fails if these specific requirements can't be removed.
0fce6c
#
0fce6c
# -s <gemspec_file>   Overrides the default .gemspec location.
0fce6c
# -d                  Remove development dependecy.
0fce6c
#
0fce6c
%gemspec_remove_dep(g:s:d) \
0fce6c
read -d '' gemspec_remove_dep_script << 'EOR' || : \
0fce6c
  gemspec_file = '%{-s*}%{!?-s:%{_builddir}/%{gem_name}-%{version}%{?prerelease}.gemspec}' \
0fce6c
  \
0fce6c
  name = '%{-g*}' \
0fce6c
  requirements = %{*}%{!?1:nil} \
0fce6c
  \
0fce6c
  type = :%{!?-d:runtime}%{?-d:development} \
0fce6c
  \
0fce6c
  spec = Gem::Specification.load(gemspec_file) \
0fce6c
  abort("#{gemspec_file} is not accessible.") unless spec \
0fce6c
  \
0fce6c
  dep = spec.dependencies.detect { |d| d.type == type && d.name == name } \
0fce6c
  if dep \
0fce6c
    if requirements \
0fce6c
      requirements = Gem::Requirement.create(requirements).requirements \
0fce6c
      requirements.each do |r| \
0fce6c
        unless dep.requirement.requirements.reject! { |dependency_requirements| dependency_requirements == r } \
0fce6c
          abort("Requirement '#{r.first} #{r.last}' was not possible to remove for dependency '#{dep}'!") \
0fce6c
        end \
0fce6c
      end \
0fce6c
      spec.dependencies.delete dep if dep.requirement.requirements.empty? \
0fce6c
    else \
0fce6c
      spec.dependencies.delete dep \
0fce6c
    end \
0fce6c
  else \
0fce6c
    abort("Dependency '#{name}' was not found!") \
0fce6c
  end \
0fce6c
  File.write gemspec_file, spec.to_ruby \
0fce6c
EOR\
0fce6c
echo "$gemspec_remove_dep_script" | ruby \
0fce6c
unset -v gemspec_remove_dep_script \
0fce6c
%{nil}
0fce6c
0fce6c
0fce6c
# %%gemspec_add_file - Add files to various files lists in .gemspec.
0fce6c
#
0fce6c
# Usage: %%gemspec_add_file [options] <file>
0fce6c
#
0fce6c
# Add files to .gemspec file. <file> is expected to be valid Ruby code.
0fce6c
# Path to file is expected. Does not check real files in any way.
0fce6c
# By default, `files` list is edited.
0fce6c
#
0fce6c
# -s <gemspec_file>   Overrides the default .gemspec location.
0fce6c
# -t                  Edit test_files only.
0fce6c
# -r                  Edit extra_rdoc_files only.
0fce6c
#
0fce6c
%gemspec_add_file(s:tr) \
0fce6c
read -d '' gemspec_add_file_script << 'EOR' || : \
0fce6c
  gemspec_file = '%{-s*}%{!?-s:%{_builddir}/%{gem_name}-%{version}%{?prerelease}.gemspec}' \
0fce6c
  \
0fce6c
  abort("gemspec_add_file: Use only one '-t' or '-r' at a time.") if "%{?-t}%{?-r}" == "-t-r" \
0fce6c
  \
0fce6c
  filenames = %{*}%{!?1:nil} \
0fce6c
  filenames = Array(filenames) \
0fce6c
  \
0fce6c
  spec = Gem::Specification.load(gemspec_file) \
0fce6c
  abort("#{gemspec_file} is not accessible.") unless spec \
0fce6c
  \
0fce6c
  spec.%{?-t:test_}%{?-r:extra_rdoc_}files += filenames \
0fce6c
  File.write gemspec_file, spec.to_ruby \
0fce6c
EOR\
0fce6c
echo "$gemspec_add_file_script" | ruby \
0fce6c
unset -v gemspec_add_file_script \
0fce6c
%{nil}
0fce6c
0fce6c
0fce6c
# %%gemspec_remove_file - Remove files from various files lists in .gemspec.
0fce6c
#
0fce6c
# Usage: %%gemspec_remove_file [options] <file>
0fce6c
#
0fce6c
# Remove files from .gemspec file. <file> is expected to be valid Ruby code.
0fce6c
# Path to file is expected. Does not check/remove real files in any way.
0fce6c
# By default, `files` list is edited. File has to be removed from `test_files`
0fce6c
# first in order to be removable from `files`.
0fce6c
#
0fce6c
# -s <gemspec_file>   Overrides the default .gemspec location.
0fce6c
# -t                  Edit test_files only.
0fce6c
# -r                  Edit extra_rdoc_files only.
0fce6c
#
0fce6c
%gemspec_remove_file(s:tr) \
0fce6c
read -d '' gemspec_remove_file_script << 'EOR' || : \
0fce6c
  gemspec_file = '%{-s*}%{!?-s:%{_builddir}/%{gem_name}-%{version}%{?prerelease}.gemspec}' \
0fce6c
  \
0fce6c
  abort("gemspec_remove_file: Use only one '-t' or '-r' at a time.") if "%{?-t}%{?-r}" == "-t-r" \
0fce6c
  \
0fce6c
  filenames = %{*}%{!?1:nil} \
0fce6c
  filenames = Array(filenames) \
0fce6c
  \
0fce6c
  spec = Gem::Specification.load(gemspec_file) \
0fce6c
  abort("#{gemspec_file} is not accessible.") unless spec \
0fce6c
  \
0fce6c
  spec.%{?-t:test_}%{?-r:extra_rdoc_}files -= filenames \
0fce6c
  File.write gemspec_file, spec.to_ruby \
0fce6c
EOR\
0fce6c
echo "$gemspec_remove_file_script" | ruby \
0fce6c
unset -v gemspec_remove_file_script \
0fce6c
%{nil}