gem.rb: add post_user_config hook for gem-author finalization

Lets a gem author register a block that runs after the user's
`build.gem` block has been processed.  Intended for filling in
defaults that depend on user-supplied configuration — for example,
library auto-detection that should only kick in when the user
hasn't explicitly chosen which library to use.

Initialization order is now:
  1. block in MRuby::Gem::Specification.new (gem author defaults)
  2. block in build.gem (user override)
  3. block in post_user_config (gem author finalize, new)

Closes #6212, picked from PR by dearblue with the method renamed
from last_initializer to post_user_config (per matz's review).

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
dearblue
2026-05-09 15:10:58 +09:00
committed by Yukihiro "Matz" Matsumoto
parent 81cfeb917e
commit 2e429a034d
+15
View File
@@ -43,6 +43,7 @@ module MRuby
def initialize(name, &block)
@name = name
@initializer = block
@post_user_config = nil
@version = "0.0.0"
@dependencies = []
@conflicts = []
@@ -91,6 +92,7 @@ module MRuby
build.libmruby_objs << @objs
instance_eval(&@build_config_initializer) if @build_config_initializer
instance_eval(&@post_user_config) if @post_user_config
repo_url = build.gem_dir_to_repo_url[dir]
build.locks[repo_url]['version'] = version if repo_url
@@ -200,6 +202,19 @@ module MRuby
end
end
# Register a block that runs after the user's `build.gem` block has
# been processed. Intended for gem authors to fill in defaults that
# depend on user-supplied configuration (e.g. auto-detect a library
# only if the user didn't specify which to use).
#
# Initialization order:
# 1. block in `MRuby::Gem::Specification.new` (gem author)
# 2. block in `build.gem` (user's build_config)
# 3. block in `post_user_config` (gem author, this hook)
def post_user_config(&block)
@post_user_config = block
end
def build_settings(&blk)
@build_settings = blk
end