kcar RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: kcar-public@bogomips.org
Subject: [PATCH] continue generating VERSION constant
Date: Mon, 12 Jan 2015 07:43:04 +0000	[thread overview]
Message-ID: <1421048584-16553-3-git-send-email-e@80x24.org> (raw)

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


                 reply	other threads:[~2015-01-12  7:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/kcar/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421048584-16553-3-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=kcar-public@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).