fake.rb: Override constants in Ruby module

This commit is contained in:
Nobuyoshi Nakada 2024-12-12 20:21:41 +09:00 committed by Nobuyoshi Nakada
parent e5e4db1748
commit b923a59b8e
Notes: git 2024-12-25 10:12:52 +00:00

View File

@ -21,7 +21,7 @@ def src.value(name)
end end
arg['versions'] = version = {} arg['versions'] = version = {}
File.read(File.join(arg['srcdir'], 'version.c')). File.read(File.join(arg['srcdir'], 'version.c')).
scan(/rb_define_global_const\("(RUBY_\w+)",[^;]*?\bMK(?:INT|(STR))\(([^()]*)\)/m) do |n, s, v| scan(/rb_define_(?:global_)?const\((mRuby, *)?"(?(1)|RUBY_)(\w+)",[^;]*?\bMK(?:INT|(STR))\(([^()]*)\)/m) do |_, n, s, v|
version[n] = arg[v] || src.value(v) || (s ? v : 0) version[n] = arg[v] || src.value(v) || (s ? v : 0)
end end
-%> -%>
@ -41,13 +41,19 @@ class Object
options = remove_const(:RUBY_DESCRIPTION)[/( \+[^\[\]\+]+)*(?= \[\S+\]\z)/] options = remove_const(:RUBY_DESCRIPTION)[/( \+[^\[\]\+]+)*(?= \[\S+\]\z)/]
constants.grep(/^RUBY_/) {|n| remove_const n} constants.grep(/^RUBY_/) {|n| remove_const n}
% arg['versions'].each {|n, v| % arg['versions'].each {|n, v|
<%=n%> = <%if n=='RUBY_DESCRIPTION' RUBY_<%=n%> = <%if n=='DESCRIPTION'
v1, v2 = v.split(/(?= \[\S+\]\z)/) v1, v2 = v.split(/(?= \[\S+\]\z)/)
%><%=v1.dump.chomp('"')%>#{options}<%= %><%=v1.dump.chomp('"')%>#{options}<%=
v2.dump[1..-1]%>.freeze<% v2.dump[1..-1]%>.freeze<%
else%><%=v.inspect%><%end%> else%><%=v.inspect%><%end%>
% } % }
end end
module Ruby
constants.each {|n| remove_const n}
% arg['versions'].each {|n, v|
<%=n%> = ::RUBY_<%=n%>
% }
end
builddir = File.dirname(File.expand_path(__FILE__)) builddir = File.dirname(File.expand_path(__FILE__))
libpathenv = libpathenv = "<%=arg['LIBPATHENV']%>" libpathenv = libpathenv = "<%=arg['LIBPATHENV']%>"
preloadenv = preloadenv = "<%=arg['PRELOADENV']%>" preloadenv = preloadenv = "<%=arg['PRELOADENV']%>"