Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

auto-generate Unicorn::Const::UNICORN_VERSION

This DRYs out our code and prevents snafus like the 4.6.0
release where UNICORN_VERSION stayed at 4.5.0

Reported-by: Maurizio De Santis <m.desantis@morganspa.com>
  • Loading branch information...
commit cb0623f25db7f06660e563e8e746bfe0ae5ba9c5 1 parent 1b3352e
Eric Wong authored
1  .gitignore
View
@@ -22,3 +22,4 @@ pkg/
/man
/tmp
/LATEST
+/lib/unicorn/version.rb
69 GIT-VERSION-GEN
View
@@ -1,40 +1,39 @@
-#!/bin/sh
-
-GVF=GIT-VERSION-FILE
-DEF_VER=v4.6.0
-
-LF='
-'
+#!/usr/bin/env ruby
+DEF_VER = "v4.6.0"
+CONSTANT = "Unicorn::Const::UNICORN_VERSION"
+RVF = "lib/unicorn/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__
2  GNUmakefile
View
@@ -155,7 +155,7 @@ clean:
man html:
$(MAKE) -C Documentation install-$@
-pkg_extra := GIT-VERSION-FILE ChangeLog LATEST NEWS \
+pkg_extra := GIT-VERSION-FILE lib/unicorn/version.rb ChangeLog LATEST NEWS \
$(ext)/unicorn_http.c $(man1_paths)
ChangeLog: GIT-VERSION-FILE .wrongdoc.yml
4 lib/unicorn/const.rb
View
@@ -7,9 +7,6 @@
# improvement over using the strings directly. Symbols did not really
# improve things much compared to constants.
module Unicorn::Const
-
- UNICORN_VERSION = "4.5.0"
-
# default TCP listen host address (0.0.0.0, all interfaces)
DEFAULT_HOST = "0.0.0.0"
@@ -44,3 +41,4 @@ module Unicorn::Const
# :startdoc:
end
+require 'unicorn/version'
Please sign in to comment.
Something went wrong with that request. Please try again.