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