mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
generic_erb.rb: --vpath option
* tool/generic_erb.rb (vpath.open): move --vpath option from template/id.h.tmpl. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
67e79d1d37
commit
bcbc1f722c
3 changed files with 21 additions and 18 deletions
|
@ -855,8 +855,8 @@ insns: $(INSNS)
|
|||
$(ID_H_INCLUDES) $(ID_H_TARGET): {$(VPATH)}parse.h $(srcdir)/tool/generic_erb.rb $(srcdir)/template/id.h.tmpl
|
||||
$(ECHO) generating id.h
|
||||
$(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb --if-change --output=id.h \
|
||||
--timestamp=$@ \
|
||||
$(srcdir)/template/id.h.tmpl --vpath=$(VPATH) parse.h
|
||||
--vpath=$(VPATH) --timestamp \
|
||||
$(srcdir)/template/id.h.tmpl parse.h
|
||||
|
||||
node_name.inc: {$(VPATH)}node.h
|
||||
$(ECHO) generating $@
|
||||
|
|
|
@ -12,24 +12,13 @@
|
|||
**********************************************************************/
|
||||
<%
|
||||
require 'optparse'
|
||||
vpath = ["."]
|
||||
input = nil
|
||||
|
||||
opt = OptionParser.new do |o|
|
||||
o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
|
||||
input, = o.order!(ARGV)
|
||||
end or abort opt.opt_s
|
||||
input = ARGV.shift or abort opt.opt_s
|
||||
|
||||
tokens = nil
|
||||
vpath.find do |dir|
|
||||
begin
|
||||
if line = File.read(File.join(dir, input))[/^\s*enum\s+yytokentype\s*\{([^{}]*)\s*\};/m, 1]
|
||||
tokens = line.scan(/\b(t(?:LAST_TOKEN|U(?:PLUS|MINUS)|POW|CMP|EQQ?|[NGL]EQ|(?:AND|OR)OP|N?MATCH|DOT\d|AREF|ASET|[LR]SHFT|LAMBDA)|id\w+)\s*=\s*(\d+),?/m)
|
||||
end
|
||||
rescue Errno::ENOENT
|
||||
nil
|
||||
else
|
||||
true
|
||||
vpath.open(input) do |f|
|
||||
if line = f.read[/^\s*enum\s+yytokentype\s*\{([^{}]*)\s*\};/m, 1]
|
||||
tokens = line.scan(/\b(t(?:LAST_TOKEN|U(?:PLUS|MINUS)|POW|CMP|EQQ?|[NGL]EQ|(?:AND|OR)OP|N?MATCH|DOT\d|AREF|ASET|[LR]SHFT|LAMBDA)|id\w+)\s*=\s*(\d+),?/m)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,13 +2,27 @@ require 'erb'
|
|||
require 'optparse'
|
||||
require 'fileutils'
|
||||
|
||||
vpath = ["."]
|
||||
def vpath.open(file, *rest)
|
||||
find do |dir|
|
||||
begin
|
||||
path = File.join(dir, file)
|
||||
return File.open(path, *rest) {|f| yield(f)}
|
||||
rescue Errno::ENOENT
|
||||
nil
|
||||
end
|
||||
end or raise(Errno::ENOENT, file)
|
||||
end
|
||||
|
||||
timestamp = nil
|
||||
output = nil
|
||||
ifchange = nil
|
||||
|
||||
opt = OptionParser.new do |o|
|
||||
o.on('-t', '--timestamp[=PATH]') {|v| timestamp = v || true}
|
||||
o.on('-o', '--output=PATH') {|v| output = v}
|
||||
o.on('-c', '--[no-]if-change') {|v| ifchange = v}
|
||||
o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
|
||||
o.order!(ARGV)
|
||||
end
|
||||
template = ARGV.shift or abort opt.to_s
|
||||
|
@ -16,7 +30,7 @@ erb = ERB.new(File.read(template), nil, '%')
|
|||
erb.filename = template
|
||||
result = erb.result
|
||||
if output
|
||||
if ifchange and (IO.read(output) rescue nil) == result
|
||||
if ifchange and (vpath.open(output) {|f| f.read} rescue nil) == result
|
||||
puts "#{output} unchanged"
|
||||
else
|
||||
open(output, "wb") {|f| f.print result}
|
||||
|
|
Loading…
Reference in a new issue