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