From 5a757f1515d4131ad4f6f1203dd6a117a9005d4f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 3 May 2013 18:45:06 +0000 Subject: auto-generate SLEEPY_PENGUIN_VERSION constant This allows the Ruby-visible constant to always be up-to-date with the release. --- .gitignore | 1 + GIT-VERSION-GEN | 9 ++++++++- ext/sleepy_penguin/init.c | 8 ++++++++ lib/sleepy_penguin.rb | 5 ----- test/test_constants.rb | 16 ++++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 test/test_constants.rb 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 #include #include +#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 -- cgit v1.2.3-24-ge0c7