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