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