kcar RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] continue generating VERSION constant
@ 2015-01-12  7:43 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-01-12  7:43 UTC (permalink / raw)
  To: kcar-public

It's probably useful to someone, so keep it to avoid needlessly
breaking compatibility.
---
 .gitignore      |  1 +
 GIT-VERSION-GEN | 60 +++++++++++++++++++++++----------------------------------
 GNUmakefile     |  2 +-
 lib/kcar.rb     |  7 +------
 4 files changed, 27 insertions(+), 43 deletions(-)

diff --git a/.gitignore b/.gitignore
index a6c49b4..4495968 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@ pkg/
 /NEWS*
 /.manifest
 /GIT-VERSION-FILE
+/lib/kcar/version.rb
 /man
 tags
 TAGS
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 4a466ed..dd9ca07 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,40 +1,28 @@
-#!/bin/sh
-
-GVF=GIT-VERSION-FILE
-DEF_VER=v0.4.0.GIT
-
-LF='
-'
+#!/usr/bin/env ruby
+CONSTANT = "Kcar::VERSION"
+RVF = "lib/kcar/version.rb"
+DEF_VER = "v0.4.0"
+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
-
-VN=$(expr "$VN" : v*'\(.*\)')
+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
 
-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
-}
+vn = vn.sub!(/\Av/, "")
+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
+puts vn if $0 == __FILE__
diff --git a/GNUmakefile b/GNUmakefile
index 929eede..2fb0bd9 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -3,7 +3,7 @@ RSYNC_DEST := bogomips.org:/srv/bogomips/kcar
 RAGEL = ragel
 RLFLAGS = -G2
 rfpackage := kcar
-pkg_extra += ext/kcar/kcar.c
+pkg_extra += ext/kcar/kcar.c lib/kcar/version.rb
 ext/kcar/kcar.c: ext/kcar/kcar.rl ext/kcar/kcar_http_common.rl
 	cd $(@D) && $(RAGEL) kcar.rl -C $(RLFLAGS) -o $(@F)
 include pkg.mk
diff --git a/lib/kcar.rb b/lib/kcar.rb
index 1fe0554..55ac527 100644
--- a/lib/kcar.rb
+++ b/lib/kcar.rb
@@ -1,13 +1,8 @@
 # -*- encoding: binary -*-
 module Kcar
-
-  # current version of Kcar, currently 0.2.0
-  # This constant is deprecated and will be removed in the next
-  # release.  Use +respond_to?+ or +defined?+ instead to test for features.
-  VERSION = "0.2.0"
-
   autoload :Response, 'kcar/response'
 end
 
+require 'kcar/version'
 require 'kcar/parser'
 require 'kcar_ext'
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-01-12  7:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-12  7:43 [PATCH] continue generating VERSION constant Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kcar.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).