summaryrefslogtreecommitdiff
path: root/tool/generic_erb.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-25 07:20:29 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-25 07:20:29 +0000
commitbcbc1f722c0ab7e26334c6fdafab502f4f021860 (patch)
tree8d3363d01cb6457a6b909e58e28a75330b2f02c4 /tool/generic_erb.rb
parent67e79d1d372879dd9bd185b508aad150de76ff6f (diff)
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
Diffstat (limited to 'tool/generic_erb.rb')
-rwxr-xr-xtool/generic_erb.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/tool/generic_erb.rb b/tool/generic_erb.rb
index 8e84a46..b2b988f 100755
--- a/tool/generic_erb.rb
+++ b/tool/generic_erb.rb
@@ -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}