Skip to content

Commit 7f99b28

Browse files
committed
Read version from bigdecimal.c
The dependency of extconf.h on bigdecimal.gemspec does not make sense as far as no rule is defined for it. Also, the relationship between extension library and gemspec file is various in default gems, and does not work well.
1 parent bd34312 commit 7f99b28

File tree

4 files changed

+15
-32
lines changed

4 files changed

+15
-32
lines changed

bigdecimal.gemspec

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# coding: utf-8
22

3+
name = File.basename(__FILE__, '.*')
4+
source_version = ["", "ext/#{name}/"].find do |dir|
5+
begin
6+
break File.foreach(File.join(__dir__, "#{dir}#{name}.c")) {|line|
7+
break $1.sub("-", ".") if /^#define\s+#{name.upcase}_VERSION\s+"(.+)"/o =~ line
8+
}
9+
rescue Errno::ENOENT
10+
end
11+
end or raise "can't find #{name.upcase}_VERSION"
12+
313
Gem::Specification.new do |s|
4-
s.name = "bigdecimal"
5-
s.version = "3.1.3"
14+
s.name = name
15+
s.version = source_version
616
s.authors = ["Kenta Murata", "Zachary Scott", "Shigeo Kobayashi"]
717
s.email = ["mrkn@mrkn.jp"]
818

ext/bigdecimal/bigdecimal.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "bits.h"
3232
#include "static_assert.h"
3333

34+
#define BIGDECIMAL_VERSION "3.1.3"
35+
3436
/* #define ENABLE_NUMERIC_STRING */
3537

3638
#define SIGNED_VALUE_MAX INTPTR_MAX
@@ -4402,13 +4404,10 @@ Init_bigdecimal(void)
44024404

44034405
/* Constants definition */
44044406

4405-
#ifndef RUBY_BIGDECIMAL_VERSION
4406-
# error RUBY_BIGDECIMAL_VERSION is not defined
4407-
#endif
44084407
/*
44094408
* The version of bigdecimal library
44104409
*/
4411-
rb_define_const(rb_cBigDecimal, "VERSION", rb_str_new2(RUBY_BIGDECIMAL_VERSION));
4410+
rb_define_const(rb_cBigDecimal, "VERSION", rb_str_new2(BIGDECIMAL_VERSION));
44124411

44134412
/*
44144413
* Base value used in internal calculations. On a 32 bit system, BASE

ext/bigdecimal/depend

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extconf.h: $(srcdir)/$(GEMSPEC)
21
Makefile: $(BIGDECIMAL_RB)
32

43
# AUTOGENERATED DEPENDENCIES START

ext/bigdecimal/extconf.rb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
# frozen_string_literal: false
22
require 'mkmf'
33

4-
def check_bigdecimal_version(gemspec_path)
5-
message "checking RUBY_BIGDECIMAL_VERSION... "
6-
bigdecimal_version = File.read(gemspec_path).match(/^\s*s\.version\s+=\s+['"]([^'"]+)['"]\s*$/)[1]
7-
8-
version_components = bigdecimal_version.split('.')
9-
bigdecimal_version = version_components[0, 3].join('.')
10-
bigdecimal_version << "-#{version_components[3]}" if version_components[3]
11-
$defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
12-
13-
message "#{bigdecimal_version}\n"
14-
end
15-
164
def have_builtin_func(name, check_expr, opt = "", &b)
175
checking_for checking_message(name.funcall_style, nil, opt) do
186
if try_compile(<<SRC, opt, &b)
@@ -27,18 +15,6 @@ def have_builtin_func(name, check_expr, opt = "", &b)
2715
end
2816
end
2917

30-
gemspec_name = gemspec_path = nil
31-
unless ['', '../../'].any? {|dir|
32-
gemspec_name = "#{dir}bigdecimal.gemspec"
33-
gemspec_path = File.expand_path("../#{gemspec_name}", __FILE__)
34-
File.file?(gemspec_path)
35-
}
36-
$stderr.puts "Unable to find bigdecimal.gemspec"
37-
abort
38-
end
39-
40-
check_bigdecimal_version(gemspec_path)
41-
4218
have_builtin_func("__builtin_clz", "__builtin_clz(0)")
4319
have_builtin_func("__builtin_clzl", "__builtin_clzl(0)")
4420
have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
@@ -82,6 +58,5 @@ def have_builtin_func(name, check_expr, opt = "", &b)
8258
end
8359

8460
create_makefile('bigdecimal') {|mf|
85-
mf << "GEMSPEC = #{gemspec_name}\n"
8661
mf << "BIGDECIMAL_RB = #{bigdecimal_rb}\n"
8762
}

0 commit comments

Comments
 (0)