about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-05-03 18:45:06 +0000
committerEric Wong <normalperson@yhbt.net>2013-05-03 18:48:23 +0000
commit5a757f1515d4131ad4f6f1203dd6a117a9005d4f (patch)
treee965863f1ba6d78dfcbd9661ffc24927ed084e23
parenta64016a9c6e80302da46b46b96fa2f3765ea5591 (diff)
downloadsleepy_penguin-5a757f1515d4131ad4f6f1203dd6a117a9005d4f.tar.gz
This allows the Ruby-visible constant to always be up-to-date
with the release.
-rw-r--r--.gitignore1
-rwxr-xr-xGIT-VERSION-GEN9
-rw-r--r--ext/sleepy_penguin/init.c8
-rw-r--r--lib/sleepy_penguin.rb5
-rw-r--r--test/test_constants.rb16
5 files changed, 33 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index a47f7fa..b4f1eab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,4 @@ tags
 TAGS
 /LATEST
 /tmp
+git_version.h
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 861c86f..72c921a 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,7 +1,8 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v3.1.0.GIT
+DEF_VER=v3.2.0.GIT
+GVH=ext/sleepy_penguin/git_version.h
 
 LF='
 '
@@ -35,6 +36,12 @@ else
         VC=unset
 fi
 test "$VN" = "$VC" || {
+        {
+                echo '#ifndef MY_GIT_VERSION'
+                echo '#define MY_GIT_VERSION "'$VN'"'
+                echo '#endif /* MY_GIT_VERSION */'
+        } >$GVH.tmp.$$
+        mv $GVH.tmp.$$ $GVH
         echo >&2 "GIT_VERSION = $VN"
         echo "GIT_VERSION = $VN" >$GVF
 }
diff --git a/ext/sleepy_penguin/init.c b/ext/sleepy_penguin/init.c
index cab97ed..9b4f31c 100644
--- a/ext/sleepy_penguin/init.c
+++ b/ext/sleepy_penguin/init.c
@@ -1,6 +1,8 @@
 #define _GNU_SOURCE
+#include <ruby.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include "git_version.h"
 #define L1_CACHE_LINE_MAX 128 /* largest I've seen (Pentium 4) */
 size_t rb_sp_l1_cache_line_size;
 
@@ -53,8 +55,14 @@ static size_t l1_cache_line_size_detect(void)
 
 void Init_sleepy_penguin_ext(void)
 {
+        VALUE mSleepyPenguin;
+
         rb_sp_l1_cache_line_size = l1_cache_line_size_detect();
 
+        mSleepyPenguin = rb_define_module("SleepyPenguin");
+        rb_define_const(mSleepyPenguin, "SLEEPY_PENGUIN_VERSION",
+                        rb_str_new2(MY_GIT_VERSION));
+
         sleepy_penguin_init_kqueue();
         sleepy_penguin_init_epoll();
         sleepy_penguin_init_timerfd();
diff --git a/lib/sleepy_penguin.rb b/lib/sleepy_penguin.rb
index 17f134e..808c94a 100644
--- a/lib/sleepy_penguin.rb
+++ b/lib/sleepy_penguin.rb
@@ -1,9 +1,4 @@
 # -*- encoding: binary -*-
-module SleepyPenguin
-
-  # the version of sleepy_penguin, currently 3.1.0
-  SLEEPY_PENGUIN_VERSION = '3.1.0'
-end
 require 'sleepy_penguin_ext'
 
 # We need to serialize Inotify#take for Rubinius since that has no GVL
diff --git a/test/test_constants.rb b/test/test_constants.rb
new file mode 100644
index 0000000..cafba45
--- /dev/null
+++ b/test/test_constants.rb
@@ -0,0 +1,16 @@
+require 'test/unit'
+$-w = true
+Thread.abort_on_exception = true
+require 'sleepy_penguin/sp'
+
+class TestConstants < Test::Unit::TestCase
+  def test_constants
+    assert_equal SleepyPenguin::SLEEPY_PENGUIN_VERSION,
+                 SP::SLEEPY_PENGUIN_VERSION
+    v = SP::SLEEPY_PENGUIN_VERSION.split('.')
+
+    (0..2).each do |i|
+      assert_equal v[i], v[i].to_i.to_s, v.inspect
+    end
+  end
+end