summaryrefslogtreecommitdiff
path: root/tool/checksum.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-06 21:54:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-06 21:54:07 +0000
commit81c83f55e72bb16ba992dce61b90b9f4b46d2993 (patch)
treed90adffb1e46936199ac1cef5aaee2f1583727cd /tool/checksum.rb
parentfe6c545d4381267cb168ea8d0a19d7cbc47cda52 (diff)
io/console: win32_vk dependencies
* ext/io/console/depend: check if VK table is modified by the checksum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/checksum.rb')
-rwxr-xr-xtool/checksum.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/tool/checksum.rb b/tool/checksum.rb
new file mode 100755
index 0000000..40f444e
--- /dev/null
+++ b/tool/checksum.rb
@@ -0,0 +1,65 @@
+#!ruby
+
+require_relative 'vpath'
+
+class Checksum
+ def initialize(vpath)
+ @vpath = vpath
+ end
+
+ def source=(source)
+ @source = source
+ @checksum = File.basename(source, ".*") + ".chksum"
+ end
+
+ def update?
+ src = @vpath.read(@source)
+ @len = src.length
+ @sum = src.sum
+ begin
+ data = @vpath.read(@checksum)
+ rescue
+ return false
+ else
+ return false unless data[/src="([0-9a-z_.-]+)",/, 1] == @source
+ return false unless @len == data[/\blen=(\d+)/, 1].to_i
+ return false unless @sum == data[/\bchecksum=(\d+)/, 1].to_i
+ return true
+ end
+ end
+
+ def update!
+ open(@checksum, "wb") {|f|
+ f.puts("src=\"#{@source}\", len=#{@len}, checksum=#{@sum}")
+ }
+ end
+
+ def update
+ return true if update?
+ update! if ret = yield(self)
+ ret
+ end
+
+ def copy(name)
+ @vpath.open(name, "rb") {|f|
+ IO.copy_stream(f, name)
+ }
+ true
+ end
+
+ def make(arg)
+ system([@make, arg].compact.join(' '))
+ end
+
+ def def_options(opt = (require 'optparse'; OptionParser.new))
+ @vpath.def_options(opt)
+ opt.on("--make=PATH") {|v| @make = v}
+ opt
+ end
+
+ def self.update(argv)
+ k = new(VPath.new)
+ k.source, *argv = k.def_options.parse(*argv)
+ k.update {|k| yield(k, *argv)}
+ end
+end