diff --git a/ChangeLog b/ChangeLog index 23440b8194..e65513e521 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Nov 11 18:09:11 2014 Nobuyoshi Nakada + + * 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 * lib/rubygems/commands/contents_command.rb (files_in_default_gem): diff --git a/common.mk b/common.mk index 29a01b63bb..d2bab7b94f 100644 --- a/common.mk +++ b/common.mk @@ -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 > $@ diff --git a/tool/compile_prelude.rb b/template/prelude.c.tmpl similarity index 83% rename from tool/compile_prelude.rb rename to template/prelude.c.tmpl index 9113fd9fe8..e1859fd436 100644 --- a/tool/compile_prelude.rb +++ b/template/prelude.c.tmpl @@ -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) "" 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 -%>