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