[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
This commit is contained in:
Nobuyoshi Nakada 2023-02-19 18:45:06 +09:00 committed by git
parent cb40432c74
commit d13879f862
4 changed files with 15 additions and 32 deletions

View File

@ -31,6 +31,8 @@
#include "bits.h" #include "bits.h"
#include "static_assert.h" #include "static_assert.h"
#define BIGDECIMAL_VERSION "3.1.3"
/* #define ENABLE_NUMERIC_STRING */ /* #define ENABLE_NUMERIC_STRING */
#define SIGNED_VALUE_MAX INTPTR_MAX #define SIGNED_VALUE_MAX INTPTR_MAX
@ -4402,13 +4404,10 @@ Init_bigdecimal(void)
/* Constants definition */ /* Constants definition */
#ifndef RUBY_BIGDECIMAL_VERSION
# error RUBY_BIGDECIMAL_VERSION is not defined
#endif
/* /*
* The version of bigdecimal library * 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 * Base value used in internal calculations. On a 32 bit system, BASE

View File

@ -1,8 +1,18 @@
# coding: utf-8 # 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| Gem::Specification.new do |s|
s.name = "bigdecimal" s.name = name
s.version = "3.1.3" s.version = source_version
s.authors = ["Kenta Murata", "Zachary Scott", "Shigeo Kobayashi"] s.authors = ["Kenta Murata", "Zachary Scott", "Shigeo Kobayashi"]
s.email = ["mrkn@mrkn.jp"] s.email = ["mrkn@mrkn.jp"]

View File

@ -1,4 +1,3 @@
extconf.h: $(srcdir)/$(GEMSPEC)
Makefile: $(BIGDECIMAL_RB) Makefile: $(BIGDECIMAL_RB)
# AUTOGENERATED DEPENDENCIES START # AUTOGENERATED DEPENDENCIES START

View File

@ -1,18 +1,6 @@
# frozen_string_literal: false # frozen_string_literal: false
require 'mkmf' 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) def have_builtin_func(name, check_expr, opt = "", &b)
checking_for checking_message(name.funcall_style, nil, opt) do checking_for checking_message(name.funcall_style, nil, opt) do
if try_compile(<<SRC, opt, &b) if try_compile(<<SRC, opt, &b)
@ -27,18 +15,6 @@ SRC
end end
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_clz", "__builtin_clz(0)")
have_builtin_func("__builtin_clzl", "__builtin_clzl(0)") have_builtin_func("__builtin_clzl", "__builtin_clzl(0)")
have_builtin_func("__builtin_clzll", "__builtin_clzll(0)") have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
@ -82,6 +58,5 @@ else
end end
create_makefile('bigdecimal') {|mf| create_makefile('bigdecimal') {|mf|
mf << "GEMSPEC = #{gemspec_name}\n"
mf << "BIGDECIMAL_RB = #{bigdecimal_rb}\n" mf << "BIGDECIMAL_RB = #{bigdecimal_rb}\n"
} }