Permalink
Browse files

fix for #173 (patch contributed by Vincent Isambart)

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@766 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 33d37c8 commit 30a73adfab0aa1c9fcd2ed1b17f5fe3aeb453ce1 @lrz lrz committed Dec 3, 2008
Showing with 37 additions and 1 deletion.
  1. +35 −1 Rakefile
  2. +2 −0 version.c
View
@@ -262,8 +262,42 @@ task :dtrace_h do
end
end
+desc "Create revision.h"
+task :revision_h do
+ revision_h = 'revision.h'
+ current_revision = nil
+ if File.exist?('.svn')
+ info = `sh -c 'LANG=C svn info' 2>&1`
+ md_revision = /^Revision: (\d+)$/.match(info)
+ md_url = /^URL: (.+)$/.match(info)
+ current_revision = "svn revision #{md_revision[1]} from #{md_url[1]}" if md_revision and md_url
+ end
+ if not current_revision and File.exist?('.git/HEAD')
+ md_ref = /^ref: (.+)$/.match(File.read('.git/HEAD'))
+ if md_ref
+ head_file = ".git/#{md_ref[1]}"
+ current_revision = "git commit #{File.read(head_file).strip}" if File.exist?(head_file)
+ end
+ end
+ current_revision = 'unknown revision' unless current_revision
+
+ new_revision_h = "#define MACRUBY_REVISION \"#{current_revision}\"\n"
+
+ must_recreate_header = true
+ if File.exist?(revision_h)
+ must_recreate_header = false if File.read(revision_h) == new_revision_h
+ end
+
+ if must_recreate_header
+ File.open(revision_h, 'w') do |f|
+ f.print new_revision_h
+ end
+ end
+end
+
+
desc "Build known objects"
-task :objects => [:config_h, :dtrace_h] do
+task :objects => [:config_h, :dtrace_h, :revision_h] do
sh "/usr/bin/ruby tool/compile_prelude.rb prelude.rb miniprelude.c.new"
if !File.exist?('miniprelude.c') or File.read('miniprelude.c') != File.read('miniprelude.c.new')
mv('miniprelude.c.new', 'miniprelude.c')
View
@@ -11,6 +11,7 @@
#include "ruby/ruby.h"
#include "version.h"
+#include "revision.h"
#include <stdio.h>
#define PRINT(type) puts(ruby_##type)
@@ -39,6 +40,7 @@ Init_version(void)
#if WITH_OBJC
rb_define_global_const("RUBY_ARCH", rb_str_new2(RUBY_ARCH));
rb_define_global_const("MACRUBY_VERSION", rb_float_new(MACRUBY_VERSION));
+ rb_define_global_const("MACRUBY_REVISION", rb_str_new2(MACRUBY_REVISION));
#endif
}

0 comments on commit 30a73ad

Please sign in to comment.