From 7155cb9fd78fdde845a2a3a3ff4341dcdb37991a Mon Sep 17 00:00:00 2001 From: Pavel Valena Date: Thu, 3 May 2018 14:53:28 +0200 Subject: [PATCH] Add macros to edit files lists in .gemspec %gemspec_add_file and %gemspec_remove_file. --- macros.rubygems | 69 +++++++++++++++++++++++++++++++++++++++++++++++-- ruby.spec | 4 +++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/macros.rubygems b/macros.rubygems index b4dfc92..d2e8514 100644 --- a/macros.rubygems +++ b/macros.rubygems @@ -42,8 +42,8 @@ gem install \\\ } -# The 'read' command in gemspec_add_dep and gemspec_remove_dep macros is not -# essential, but it is usefull to make the script appear in build log. +# The 'read' command in %%gemspec_* macros is not essential, but it is usefull +# to make the sript appear in build log. # %gemspec_add_dep - Add dependency into .gemspec. @@ -128,3 +128,68 @@ EOR\ echo "$gemspec_remove_dep_script" | ruby \ unset -v gemspec_remove_dep_script \ %{nil} + + +# %%gemspec_add_file - Add files to various files lists in .gemspec. +# +# Usage: %%gemspec_add_file [options] +# +# Add files to .gemspec file. is expected to be valid Ruby code. +# Path to file is expected. Does not check real files in any way. +# By default, `files` list is edited. +# +# -s Overrides the default .gemspec location. +# -t Edit test_files only. +# -r Edit extra_rdoc_files only. +# +%gemspec_add_file(s:tr) \ +read -d '' gemspec_add_file_script << 'EOR' || : \ + gemspec_file = '%{-s*}%{!?-s:%{_builddir}/%{gem_name}-%{version}.gemspec}' \ + \ + abort("gemspec_add_file: Use only one '-t' or '-r' at a time.") if "%{?-t}%{?-r}" == "-t-r" \ + \ + filenames = %{*}%{!?1:nil} \ + filenames = Array(filenames) \ + \ + spec = Gem::Specification.load(gemspec_file) \ + abort("#{gemspec_file} is not accessible.") unless spec \ + \ + spec.%{?-t:test_}%{?-r:extra_rdoc_}files += filenames \ + File.write gemspec_file, spec.to_ruby \ +EOR\ +echo "$gemspec_add_file_script" | ruby \ +unset -v gemspec_add_file_script \ +%{nil} + + +# %%gemspec_remove_file - Remove files from various files lists in .gemspec. +# +# Usage: %%gemspec_remove_file [options] +# +# Remove files from .gemspec file. is expected to be valid Ruby code. +# Path to file is expected. Does not check/remove real files in any way. +# By default, `files` list is edited. File has to be removed from `test_files` +# first in order to be removable from `files`. +# +# -s Overrides the default .gemspec location. +# -t Edit test_files only. +# -r Edit extra_rdoc_files only. +# +%gemspec_remove_file(s:tr) \ +read -d '' gemspec_remove_file_script << 'EOR' || : \ + gemspec_file = '%{-s*}%{!?-s:%{_builddir}/%{gem_name}-%{version}.gemspec}' \ + \ + abort("gemspec_remove_file: Use only one '-t' or '-r' at a time.") if "%{?-t}%{?-r}" == "-t-r" \ + \ + filenames = %{*}%{!?1:nil} \ + filenames = Array(filenames) \ + \ + spec = Gem::Specification.load(gemspec_file) \ + abort("#{gemspec_file} is not accessible.") unless spec \ + \ + spec.%{?-t:test_}%{?-r:extra_rdoc_}files -= filenames \ + File.write gemspec_file, spec.to_ruby \ +EOR\ +echo "$gemspec_remove_file_script" | ruby \ +unset -v gemspec_remove_file_script \ +%{nil} diff --git a/ruby.spec b/ruby.spec index eababfa..78866cd 100644 --- a/ruby.spec +++ b/ruby.spec @@ -1029,6 +1029,10 @@ make check TESTS="-v $DISABLE_TESTS" %{gem_dir}/specifications/xmlrpc-%{xmlrpc_version}.gemspec %changelog +* Thu May 10 2018 Pavel Valena - 2.4.4-89 +- Add macros to edit files lists in .gemspec + (gemspec_add_file and gemspec_remove_file). + * Wed May 02 2018 Vít Ondruch - 2.4.4-89 - Make %%gemspec_{add,remove}_dep modify .gemspec provided by %%setup macro.