From d13879f862a98e718ba7ec40e8d43137efb97a8b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 19 Feb 2023 18:45:06 +0900 Subject: [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 --- ext/bigdecimal/bigdecimal.c | 7 +++---- ext/bigdecimal/bigdecimal.gemspec | 14 ++++++++++++-- ext/bigdecimal/depend | 1 - ext/bigdecimal/extconf.rb | 25 ------------------------- 4 files changed, 15 insertions(+), 32 deletions(-) (limited to 'ext') 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(<