socket/pure_ruby: favor String#clear if available
[ruby-mogilefs-client.git] / GIT-VERSION-GEN
blob526e7fb1dcb06cd4778d9c4d777fd473b2197eb4
1 #!/usr/bin/env ruby
2 CONSTANT = "MogileFS::VERSION"
3 RVF = "lib/mogilefs/version.rb"
4 GVF = "GIT-VERSION-FILE"
5 DEF_VER = "v3.11.1"
6 vn = DEF_VER
8 # First see if there is a version file (included in release tarballs),
9 # then try git-describe, then default.
10 if File.exist?(".git")
11 describe = `git describe --abbrev=4 HEAD 2>/dev/null`.strip
12 case describe
13 when /\Av[0-9]*/
14 vn = describe
15 system(*%w(git update-index -q --refresh))
16 unless `git diff-index --name-only HEAD --`.chomp.empty?
17 vn << "-dirty"
18 end
19 vn.tr!('-', '.')
20 end
21 end
23 vn = vn.sub!(/\Av/, "")
24 new_ruby_version = "#{CONSTANT} = '#{vn}' # :nodoc:\n"
25 cur_ruby_version = File.read(RVF) rescue nil
26 if new_ruby_version != cur_ruby_version
27 File.open(RVF, "w") { |fp| fp.write(new_ruby_version) }
28 end
29 File.chmod(0644, RVF)
31 # generate the makefile snippet
32 new_make_version = "GIT_VERSION = #{vn}\n"
33 cur_make_version = File.read(GVF) rescue nil
34 if new_make_version != cur_make_version
35 File.open(GVF, "w") { |fp| fp.write(new_make_version) }
36 end
37 File.chmod(0644, GVF)
39 puts vn if $0 == __FILE__