summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-02-19 18:45:06 +0900
committergit <svn-admin@ruby-lang.org>2023-02-21 09:50:02 +0000
commitd13879f862a98e718ba7ec40e8d43137efb97a8b (patch)
tree02945baaa60afc3a5fb8fb90fcb8d9c2065bb0c4 /ext
parentcb40432c74b9c5f785e8be53cbda981a64d47c72 (diff)
downloadruby-d13879f862a98e718ba7ec40e8d43137efb97a8b.tar.gz
[ruby/bigdecimal] 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. https://github.com/ruby/bigdecimal/commit/7f99b28552
Diffstat (limited to 'ext')
-rw-r--r--ext/bigdecimal/bigdecimal.c7
-rw-r--r--ext/bigdecimal/bigdecimal.gemspec14
-rw-r--r--ext/bigdecimal/depend1
-rw-r--r--ext/bigdecimal/extconf.rb25
4 files changed, 15 insertions, 32 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 637e824af5..24f299d248 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -31,6 +31,8 @@
#include "bits.h"
#include "static_assert.h"
+#define BIGDECIMAL_VERSION "3.1.3"
+
/* #define ENABLE_NUMERIC_STRING */
#define SIGNED_VALUE_MAX INTPTR_MAX
@@ -4402,13 +4404,10 @@ Init_bigdecimal(void)
/* Constants definition */
-#ifndef RUBY_BIGDECIMAL_VERSION
-# error RUBY_BIGDECIMAL_VERSION is not defined
-#endif
/*
* The version of bigdecimal library
*/
- rb_define_const(rb_cBigDecimal, "VERSION", rb_str_new2(RUBY_BIGDECIMAL_VERSION));
+ rb_define_const(rb_cBigDecimal, "VERSION", rb_str_new2(BIGDECIMAL_VERSION));
/*
* Base value used in internal calculations. On a 32 bit system, BASE
diff --git a/ext/bigdecimal/bigdecimal.gemspec b/ext/bigdecimal/bigdecimal.gemspec
index a72205f517..f9f3b45616 100644
--- a/ext/bigdecimal/bigdecimal.gemspec
+++ b/ext/bigdecimal/bigdecimal.gemspec
@@ -1,8 +1,18 @@
# coding: utf-8
+name = File.basename(__FILE__, '.*')
+source_version = ["", "ext/#{name}/"].find do |dir|
+ begin
+ break File.foreach(File.join(__dir__, "#{dir}#{name}.c")) {|line|
+ break $1.sub("-", ".") if /^#define\s+#{name.upcase}_VERSION\s+"(.+)"/o =~ line
+ }
+ rescue Errno::ENOENT
+ end
+end or raise "can't find #{name.upcase}_VERSION"
+
Gem::Specification.new do |s|
- s.name = "bigdecimal"
- s.version = "3.1.3"
+ s.name = name
+ s.version = source_version
s.authors = ["Kenta Murata", "Zachary Scott", "Shigeo Kobayashi"]
s.email = ["mrkn@mrkn.jp"]
diff --git a/ext/bigdecimal/depend b/ext/bigdecimal/depend
index e64d22434a..fea8c39c6e 100644
--- a/ext/bigdecimal/depend
+++ b/ext/bigdecimal/depend
@@ -1,4 +1,3 @@
-extconf.h: $(srcdir)/$(GEMSPEC)
Makefile: $(BIGDECIMAL_RB)
# AUTOGENERATED DEPENDENCIES START
diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb
index 17e7905dd6..23904ed60e 100644
--- a/ext/bigdecimal/extconf.rb
+++ b/ext/bigdecimal/extconf.rb
@@ -1,18 +1,6 @@
# frozen_string_literal: false
require 'mkmf'
-def check_bigdecimal_version(gemspec_path)
- message "checking RUBY_BIGDECIMAL_VERSION... "
- bigdecimal_version = File.read(gemspec_path).match(/^\s*s\.version\s+=\s+['"]([^'"]+)['"]\s*$/)[1]
-
- version_components = bigdecimal_version.split('.')
- bigdecimal_version = version_components[0, 3].join('.')
- bigdecimal_version << "-#{version_components[3]}" if version_components[3]
- $defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
-
- message "#{bigdecimal_version}\n"
-end
-
def have_builtin_func(name, check_expr, opt = "", &b)
checking_for checking_message(name.funcall_style, nil, opt) do
if try_compile(<<SRC, opt, &b)
@@ -27,18 +15,6 @@ SRC
end
end
-gemspec_name = gemspec_path = nil
-unless ['', '../../'].any? {|dir|
- gemspec_name = "#{dir}bigdecimal.gemspec"
- gemspec_path = File.expand_path("../#{gemspec_name}", __FILE__)
- File.file?(gemspec_path)
- }
- $stderr.puts "Unable to find bigdecimal.gemspec"
- abort
-end
-
-check_bigdecimal_version(gemspec_path)
-
have_builtin_func("__builtin_clz", "__builtin_clz(0)")
have_builtin_func("__builtin_clzl", "__builtin_clzl(0)")
have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
@@ -82,6 +58,5 @@ else
end
create_makefile('bigdecimal') {|mf|
- mf << "GEMSPEC = #{gemspec_name}\n"
mf << "BIGDECIMAL_RB = #{bigdecimal_rb}\n"
}