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