Fix gem install to generate documentation

This commit is contained in:
Vít Ondruch 2025-01-02 19:54:47 +01:00
commit b5a9c2685f
2 changed files with 38 additions and 0 deletions

View file

@ -241,6 +241,10 @@ Source16: rpm_test_helper.rb
Source17: test_rubygems_req.rb
Source18: test_rubygems_prov.rb
Source19: test_rubygems_con.rb
# This file is available in official RDoc 6.9+, while it is missing from
# default RDoc gem as shipped in Ruby tarball. This should not be needed for
# Ruby 3.5+.
Source20: https://github.com/ruby/rdoc/blob/master/lib/rubygems_plugin.rb
# The load directive is supported since RPM 4.12, i.e. F21+. The build process
# fails on older Fedoras.
@ -896,6 +900,16 @@ popd
mkdir -p %{buildroot}%{gem_libdir rdoc}
mv %{buildroot}%{ruby_libdir}/rdoc* %{buildroot}%{gem_libdir rdoc}
mv %{buildroot}%{gem_spec -d rdoc} %{buildroot}%{gem_spec rdoc}
# Default gem is missing the RubyGems plugin, using various sorts of
# heuristics to workadound this. Restore the plugin to let the documentaion
# generator work properly. This shold not be needed for Ruby 3.5+.
# https://github.com/ruby/rdoc/pull/1171
# https://github.com/rubygems/rubygems/pull/8340
# Make sure to not overwrite the file, because it should not exist.
test ! -e %{buildroot}%{gem_libdir rdoc}/%{basename:%{SOURCE20}}
mv %{SOURCE20} %{buildroot}%{gem_libdir rdoc}
echo "require_relative '../gems/rdoc-%{rdoc_version}/lib/rubygems_plugin.rb'" \
> %{buildroot}%{gem_plugin rdoc}
# TODO: Put help files into proper location.
# https://bugs.ruby-lang.org/issues/15359
@ -1513,6 +1527,7 @@ make -C %{_vpath_builddir} runruby TESTRUN_SCRIPT=" \
%{_bindir}/ri
%{gem_instdir rdoc}
%{gem_spec rdoc}
%{gem_plugin rdoc}
%{_mandir}/man1/ri*
%files doc -f .ruby-doc.en -f .ruby-doc.ja

23
rubygems_plugin.rb Normal file
View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
# If this file is exist, RDoc generates and removes documents by rubygems plugins.
#
# In follwing cases,
# RubyGems directly exectute RDoc::RubygemsHook.generation_hook and RDoc::RubygemsHook#remove to generate and remove documents.
#
# - RDoc is used as a default gem.
# - RDoc is a old version that doesn't have rubygems_plugin.rb.
require_relative 'rdoc/rubygems_hook'
# To install dependency libraries of RDoc, you need to run bundle install.
# At that time, rdoc/markdown is not generated.
# If generate and remove are executed at that time, an error will occur.
# So, we can't register generate and remove to Gem at that time.
begin
require_relative 'rdoc/markdown'
rescue LoadError
else
Gem.done_installing(&RDoc::RubyGemsHook.method(:generate))
Gem.pre_uninstall(&RDoc::RubyGemsHook.method(:remove))
end