about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-02-16 00:04:53 +0000
committerEric Wong <normalperson@yhbt.net>2013-02-16 00:04:53 +0000
commit7dd14b2780b87be58c7afbd03df8d1f7cc3e9575 (patch)
tree865ba58592250b6dc19207c2bea8e1b9508df40f
parente166cfe5e8d648b544b1291ec157bd234a425e21 (diff)
This DRYs up versioning and makes packages easier to distribute.
-rw-r--r--.gitignore1
-rwxr-xr-xGIT-VERSION-GEN69
-rw-r--r--GNUmakefile6
-rw-r--r--lib/rainbows/const.rb6
4 files changed, 42 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index 707af62..66dea81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,4 @@ pkg/
 /LATEST
 tags
 TAGS
+/lib/rainbows/version.rb
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index c3becab..c111ce7 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,40 +1,39 @@
-#!/bin/sh
-
-GVF=GIT-VERSION-FILE
-DEF_VER=v4.4.3
-
-LF='
-'
+#!/usr/bin/env ruby
+DEF_VER = "v4.4.3"
+CONSTANT = "Rainbows::Const::RAINBOWS_VERSION"
+RVF = "lib/rainbows/version.rb"
+GVF = "GIT-VERSION-FILE"
+vn = DEF_VER
 
 # First see if there is a version file (included in release tarballs),
 # then try git-describe, then default.
-if test -f version
-then
-        VN=$(cat version) || VN="$DEF_VER"
-elif test -d .git -o -f .git &&
-        VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
-        case "$VN" in
-        *$LF*) (exit 1) ;;
-        v[0-9]*)
-                git update-index -q --refresh
-                test -z "$(git diff-index --name-only HEAD --)" ||
-                VN="$VN-dirty" ;;
-        esac
-then
-        VN=$(echo "$VN" | sed -e 's/-/./g');
-else
-        VN="$DEF_VER"
-fi
+if File.exist?(".git")
+  describe = `git describe --abbrev=4 HEAD 2>/dev/null`.strip
+  case describe
+  when /\Av[0-9]*/
+    vn = describe
+    system(*%w(git update-index -q --refresh))
+    unless `git diff-index --name-only HEAD --`.chomp.empty?
+      vn << "-dirty"
+    end
+    vn.tr!('-', '.')
+  end
+end
+
+vn = vn.sub!(/\Av/, "")
+
+# generate the Ruby constant
+new_ruby_version = "#{CONSTANT} = '#{vn}'\n"
+cur_ruby_version = File.read(RVF) rescue nil
+if new_ruby_version != cur_ruby_version
+  File.open(RVF, "w") { |fp| fp.write(new_ruby_version) }
+end
 
-VN=$(expr "$VN" : v*'\(.*\)')
+# generate the makefile snippet
+new_make_version = "GIT_VERSION = #{vn}\n"
+cur_make_version = File.read(GVF) rescue nil
+if new_make_version != cur_make_version
+  File.open(GVF, "w") { |fp| fp.write(new_make_version) }
+end
 
-if test -r $GVF
-then
-        VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
-else
-        VC=unset
-fi
-test "$VN" = "$VC" || {
-        echo >&2 "GIT_VERSION = $VN"
-        echo "GIT_VERSION = $VN" >$GVF
-}
+puts vn if $0 == __FILE__
diff --git a/GNUmakefile b/GNUmakefile
index cd087db..5fb780c 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -28,14 +28,16 @@ clean:
 man html:
         $(MAKE) -C Documentation install-$@
 
-pkg_extra += $(man1_paths)
+pkg_extra += $(man1_paths) lib/rainbows/version.rb
 
 doc::
         cat Documentation/comparison.css >> doc/rdoc.css
         $(RM) $(man1_rdoc)
 
+lib/rainbows/version.rb: GIT-VERSION-FILE
+
 all:: test
-test:
+test: lib/rainbows/version.rb
         $(MAKE) -C t
 
 .PHONY: man html
diff --git a/lib/rainbows/const.rb b/lib/rainbows/const.rb
index f9d18bb..8db95c0 100644
--- a/lib/rainbows/const.rb
+++ b/lib/rainbows/const.rb
@@ -1,9 +1,9 @@
 # -*- encoding: binary -*-
 # :enddoc:
 module Rainbows::Const
-
-  RAINBOWS_VERSION = '4.4.3'
-
+end
+require 'rainbows/version'
+module Rainbows::Const
   include Unicorn::Const
 
   RACK_DEFAULTS = Unicorn::HttpRequest::DEFAULTS.update({