[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 коммит произвёл git
Родитель cb40432c74
Коммит d13879f862
4 изменённых файлов: 15 добавлений и 32 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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"]

Просмотреть файл

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

Просмотреть файл

@ -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"
}