From c5a64f445f49a1989bd4e34aa482feef49915f56 Mon Sep 17 00:00:00 2001 From: tompng Date: Wed, 23 Apr 2025 14:44:25 +0900 Subject: [PATCH 1/2] Fix rubygems hook execution when gemspec.rdoc_options contains --ri `finish` should be called before `rdoc.parse_files(options.files)`. `finish` should be called after `options.setup_generator`. We need to use a different RDoc::Options object for parse_files phase and document generation phase. --- lib/rdoc/rubygems_hook.rb | 10 +++++----- test/rdoc/test_rdoc_rubygems_hook.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb index 90cb37f86d..d4c7f46521 100644 --- a/lib/rdoc/rubygems_hook.rb +++ b/lib/rdoc/rubygems_hook.rb @@ -182,18 +182,18 @@ def generate options.default_title = "#{@spec.full_name} Documentation" options.parse args options.quiet = !Gem.configuration.really_verbose - options.finish end @rdoc = new_rdoc - @rdoc.options = options - - @rdoc.store = RDoc::Store.new(options) say "Parsing documentation for #{@spec.full_name}" Dir.chdir @spec.full_gem_path do - @rdoc.parse_files options.files + parse_options = options.dup + parse_options.finish + @rdoc.options = parse_options + @rdoc.store = RDoc::Store.new(parse_options) + @rdoc.parse_files parse_options.files end document 'ri', options, @ri_dir if diff --git a/test/rdoc/test_rdoc_rubygems_hook.rb b/test/rdoc/test_rdoc_rubygems_hook.rb index ccb86c2a2c..29488e7ac1 100644 --- a/test/rdoc/test_rdoc_rubygems_hook.rb +++ b/test/rdoc/test_rdoc_rubygems_hook.rb @@ -241,6 +241,18 @@ def test_generate_no_overwrite assert_path_not_exist File.join(@a.doc_dir('ri'), 'cache.ri') end + def test_generate_with_ri_opt + @a.rdoc_options << '--ri' + FileUtils.mkdir_p @a.doc_dir + FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') + @hook.generate_rdoc = true + @hook.generate_ri = true + @hook.generate + + assert_path_exist File.join(@a.doc_dir('rdoc'), 'index.html') + assert_path_exist File.join(@a.doc_dir('ri'), 'cache.ri') + end + def test_new_rdoc assert_kind_of RDoc::RDoc, @hook.new_rdoc end From ca64d7a20b88b03dd47871441c32d94b41216b61 Mon Sep 17 00:00:00 2001 From: tompng Date: Wed, 23 Apr 2025 18:06:11 +0900 Subject: [PATCH 2/2] Add a comment for the reason of options.dup --- lib/rdoc/rubygems_hook.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb index d4c7f46521..a1216d346d 100644 --- a/lib/rdoc/rubygems_hook.rb +++ b/lib/rdoc/rubygems_hook.rb @@ -189,6 +189,9 @@ def generate say "Parsing documentation for #{@spec.full_name}" Dir.chdir @spec.full_gem_path do + # RDoc::Options#finish must be called before parse_files. + # RDoc::Options#finish is also called after ri/darkfish generator setup. + # We need to dup the options to avoid modifying it after finish is called. parse_options = options.dup parse_options.finish @rdoc.options = parse_options