1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

template/prelude.c.tmpl

* template/prelude.c.tmpl: move from tool/compile_prelude.rb and
  expand by generic_erb.rb.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-11-11 09:09:14 +00:00
parent 2607419700
commit 8e677dc443
3 changed files with 36 additions and 41 deletions

View file

@ -1,3 +1,8 @@
Tue Nov 11 18:09:11 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* template/prelude.c.tmpl: move from tool/compile_prelude.rb and
expand by generic_erb.rb.
Tue Nov 11 13:01:31 2014 NARUSE, Yui <naruse@ruby-lang.org>
* lib/rubygems/commands/contents_command.rb (files_in_default_gem):

View file

@ -115,8 +115,8 @@ ALLOBJS = $(NORMALMAINOBJ) $(MINIOBJS) $(COMMONOBJS) $(DMYEXT)
GOLFOBJS = goruby.$(OBJEXT) golf_prelude.$(OBJEXT)
DEFAULT_PRELUDES = $(GEM_PRELUDE)
PRELUDE_SCRIPTS = $(srcdir)/prelude.rb $(srcdir)/enc/prelude.rb $(DEFAULT_PRELUDES)
GEM_PRELUDE = $(srcdir)/gem_prelude.rb
PRELUDE_SCRIPTS = prelude.rb enc/prelude.rb $(DEFAULT_PRELUDES)
GEM_PRELUDE = gem_prelude.rb
PRELUDES = prelude.c miniprelude.c
GOLFPRELUDES = golf_prelude.c
@ -146,7 +146,7 @@ TESTRUN_SCRIPT = $(srcdir)/test.rb
BOOTSTRAPRUBY = $(BASERUBY)
COMPILE_PRELUDE = $(MINIRUBY) -I$(srcdir) $(srcdir)/tool/compile_prelude.rb
COMPILE_PRELUDE = $(srcdir)/tool/generic_erb.rb $(srcdir)/template/prelude.c.tmpl
all: showflags main docs
@ -969,20 +969,23 @@ known_errors.inc: $(srcdir)/template/known_errors.inc.tmpl $(srcdir)/defs/known_
$(ECHO) generating $@
$(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb -c -o $@ $(srcdir)/template/known_errors.inc.tmpl $(srcdir)/defs/known_errors.def
$(MINIPRELUDE_C): $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb
$(MINIPRELUDE_C): $(COMPILE_PRELUDE) prelude.rb
$(ECHO) generating $@
$(Q) $(BASERUBY) -I$(srcdir) $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $@
$(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb -I$(srcdir) -o $@ \
$(srcdir)/template/prelude.c.tmpl prelude.rb
prelude.c: $(srcdir)/tool/compile_prelude.rb $(RBCONFIG) \
$(srcdir)/lib/rubygems/defaults.rb \
$(srcdir)/lib/rubygems/core_ext/kernel_gem.rb \
prelude.c: $(COMPILE_PRELUDE) $(RBCONFIG) \
lib/rubygems/defaults.rb \
lib/rubygems/core_ext/kernel_gem.rb \
$(PRELUDE_SCRIPTS) $(PREP) $(LIB_SRCS)
$(ECHO) generating $@
$(Q) $(COMPILE_PRELUDE) $(PRELUDE_SCRIPTS) $@
$(Q) $(MINIRUBY) $(srcdir)/tool/generic_erb.rb -I$(srcdir) -c -o $@ \
$(srcdir)/template/prelude.c.tmpl $(PRELUDE_SCRIPTS)
golf_prelude.c: $(srcdir)/tool/compile_prelude.rb $(RBCONFIG) $(srcdir)/prelude.rb $(srcdir)/golf_prelude.rb $(PREP)
golf_prelude.c: $(COMPILE_PRELUDE) $(RBCONFIG) golf_prelude.rb $(PREP)
$(ECHO) generating $@
$(Q) $(COMPILE_PRELUDE) $(srcdir)/golf_prelude.rb $@
$(Q) $(MINIRUBY) $(srcdir)/tool/generic_erb.rb -I$(srcdir) -c -o $@ \
$(srcdir)/template/prelude.c.tmpl golf_prelude.rb
probes.dmyh: {$(srcdir)}probes.d $(srcdir)/tool/gen_dummy_probes.rb
$(BASERUBY) $(srcdir)/tool/gen_dummy_probes.rb $(srcdir)/probes.d > $@

View file

@ -1,15 +1,11 @@
<%
# This file is interpreted by $(BASERUBY) and miniruby.
# $(BASERUBY) is used for miniprelude.c.
# miniruby is used for prelude.c.
# Since $(BASERUBY) may be older than Ruby 1.9,
# Ruby 1.9 feature should not be used.
require 'erb'
class Prelude
SRCDIR = File.dirname(File.dirname(__FILE__))
$:.unshift(SRCDIR)
C_ESC = {
"\\" => "\\\\",
'"' => '\"',
@ -24,27 +20,30 @@ class Prelude
'"' + str.gsub(C_ESC_PAT) { C_ESC[$&] } + '"'
end
def prelude_base(filename)
filename[/\A#{Regexp.quote(SRCDIR)}\/(.*?)(\.rb)?\z/om, 1]
filename.chomp(".rb")
end
def prelude_name(filename)
"<internal:" + prelude_base(filename) + ">"
end
def initialize(preludes)
def initialize(init_name, preludes, vpath)
@init_name = init_name
@mkconf = nil
@have_sublib = false
@need_ruby_prefix = false
@vpath = vpath
@preludes = {}
@mains = preludes.map {|filename| translate(filename)[0]}
@preludes.delete_if {|_, (_, _, lines, sub)| !sub && lines.empty?}
@preludes.delete_if {|_, (_, _, lines, sub)| sub && lines.empty?}
end
def translate(filename, sub = false)
idx = @preludes[filename]
return idx if idx
lines = []
@preludes[filename] = result = [@preludes.size, filename, lines, sub]
File.readlines(filename).each do |line|
result = [@preludes.size, filename, lines, sub]
@vpath.foreach(filename) do |line|
@preludes[filename] ||= result
line.sub!(/(?:^|\s+)\#(?:$|\s.*)/, '')
line.gsub!(/RbConfig::CONFIG\["(\w+)"\]/) {
key = $1
@ -62,10 +61,10 @@ class Prelude
}
line.sub!(/require\s*\(?\s*(["'])(.*?)\1\)?/) do
orig, path = $&, $2
path = File.join(SRCDIR, path)
if File.exist?(path)
path = translate(path, true) rescue nil
if path
@have_sublib = true
"TMP_RUBY_PREFIX.require(#{translate(path, true)[0]})"
"TMP_RUBY_PREFIX.require(#{path[0]})"
else
orig
end
@ -74,12 +73,11 @@ class Prelude
end
result
end
def emit(outfile)
@init_name = outfile[/\w+(?=_prelude.c\b)/] || 'prelude'
erb = ERB.new(<<'EOS', nil, '%')
end
Prelude.new(output && output[/\w+(?=_prelude.c\b)/] || 'prelude', ARGV, vpath).instance_eval do
-%>
/* -*-c-*-
THIS FILE WAS AUTOGENERATED BY tool/compile_prelude.rb. DO NOT EDIT.
THIS FILE WAS AUTOGENERATED BY template/prelude.c.tmpl. DO NOT EDIT.
sources: <%= @preludes.map {|n,*| prelude_base(n)}.join(', ') %>
*/
@ -185,15 +183,4 @@ Init_<%=@init_name%>(void)
% }
#endif
}
EOS
tmp = erb.result(binding)
open(outfile, 'w'){|f|
f << tmp
}
end
end
preludes = ARGV.dup
outfile = preludes.pop
Prelude.new(preludes).emit(outfile)
<%end -%>