pvalena / rpms / ruby

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