Blame SOURCES/macros.rubygems

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