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