Blame SOURCES/macros.rubygems

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