2008-12-22 08:19:08 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'optparse'
|
2013-11-09 08:35:39 -05:00
|
|
|
|
|
|
|
# this file run with BASERUBY, which may be older than 1.9, so no
|
|
|
|
# require_relative
|
2013-11-09 01:20:57 -05:00
|
|
|
require File.expand_path('../vcs', __FILE__)
|
2010-07-17 05:30:54 -04:00
|
|
|
|
|
|
|
Program = $0
|
2010-03-13 03:48:49 -05:00
|
|
|
|
2009-06-30 03:53:22 -04:00
|
|
|
@output = nil
|
|
|
|
def self.output=(output)
|
|
|
|
if @output and @output != output
|
|
|
|
raise "you can specify only one of --changed, --revision.h and --doxygen"
|
|
|
|
end
|
|
|
|
@output = output
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2009-06-30 03:53:22 -04:00
|
|
|
@suppress_not_found = false
|
2008-12-22 08:19:08 -05:00
|
|
|
|
2010-03-13 03:48:49 -05:00
|
|
|
srcdir = nil
|
2008-12-22 08:19:08 -05:00
|
|
|
parser = OptionParser.new {|opts|
|
2010-03-13 03:48:49 -05:00
|
|
|
opts.on("--srcdir=PATH", "use PATH as source directory") do |path|
|
|
|
|
srcdir = path
|
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
opts.on("--changed", "changed rev") do
|
2009-06-30 03:53:22 -04:00
|
|
|
self.output = :changed
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2010-03-13 03:48:49 -05:00
|
|
|
opts.on("--revision.h", "RUBY_REVISION macro") do
|
2009-06-30 03:53:22 -04:00
|
|
|
self.output = :revision_h
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2010-03-13 03:48:49 -05:00
|
|
|
opts.on("--doxygen", "Doxygen format") do
|
2009-06-30 03:53:22 -04:00
|
|
|
self.output = :doxygen
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2014-08-22 02:36:46 -04:00
|
|
|
opts.on("--modified", "modified time") do
|
|
|
|
self.output = :modified
|
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
opts.on("-q", "--suppress_not_found") do
|
2009-06-30 03:53:22 -04:00
|
|
|
@suppress_not_found = true
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
|
|
|
}
|
2010-07-17 05:30:54 -04:00
|
|
|
parser.parse! rescue abort "#{File.basename(Program)}: #{$!}\n#{parser}"
|
2008-12-22 08:19:08 -05:00
|
|
|
|
2012-01-02 08:14:24 -05:00
|
|
|
srcdir ||= File.dirname(File.dirname(Program))
|
2008-12-22 08:19:08 -05:00
|
|
|
begin
|
2010-03-13 03:48:49 -05:00
|
|
|
vcs = VCS.detect(srcdir)
|
|
|
|
rescue VCS::NotFoundError => e
|
2010-07-17 05:30:54 -04:00
|
|
|
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
|
2010-03-13 03:48:49 -05:00
|
|
|
else
|
2010-04-15 07:43:09 -04:00
|
|
|
begin
|
2014-08-22 02:36:46 -04:00
|
|
|
last, changed, modified = vcs.get_revisions(ARGV.shift)
|
2010-04-15 07:43:09 -04:00
|
|
|
rescue => e
|
2010-07-17 05:30:54 -04:00
|
|
|
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
|
2010-04-15 07:43:09 -04:00
|
|
|
exit false
|
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
|
|
|
|
2009-06-30 03:53:22 -04:00
|
|
|
case @output
|
2008-12-22 08:19:08 -05:00
|
|
|
when :changed, nil
|
|
|
|
puts changed
|
|
|
|
when :revision_h
|
2009-01-15 06:45:01 -05:00
|
|
|
puts "#define RUBY_REVISION #{changed.to_i}"
|
2008-12-22 08:19:08 -05:00
|
|
|
when :doxygen
|
|
|
|
puts "r#{changed}/r#{last}"
|
2014-08-22 02:36:46 -04:00
|
|
|
when :modified
|
|
|
|
puts modified.strftime('%Y-%m-%dT%H:%M:%S%z')
|
2008-12-22 08:19:08 -05:00
|
|
|
else
|
2009-06-30 03:53:22 -04:00
|
|
|
raise "unknown output format `#{@output}'"
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|