Backport upstream pull request for ruby3.2 build issue

Add -Werror=implicit-function explicitly to detect such function
This commit is contained in:
Mamoru TASAKA 2022-12-01 13:31:20 +09:00
commit ee2720c212
4 changed files with 116 additions and 3 deletions

View file

@ -8,4 +8,4 @@
+$CFLAGS = "#{$CFLAGS} " + case RUBY_VERSION
when /^1\.9/; '-DRUBY19'
when /^2\./; '-DRUBY19'
when /^3\./; '-DRUBY19'
when /^3\./; '-DRUBY19 -DRUBY30'

View file

@ -0,0 +1,29 @@
commit eab4aba3f5e06ea8f124d3e5ff6b3fa88c4807cd
Author: Mamoru TASAKA <mtasaka@fedoraproject.org>
Date: Thu Dec 1 12:23:05 2022 +0900
extconf.rb: use Rbconfig::CONFIG instead of mkmf CONFIG
In mkmf.rb CONFIG is defined as CONFIG is defined as RbConfig::MAKEFILE_CONFIG
and RbConfig::MAKEFILE_CONFIG is almost same as RbConfig::CONFIG
except that RbConfig::MAKEFILE_CONFIG uses reference for other variables.
Using CONFIG in extconf.rb causes error with ruby3.2 because now
CONFIG['host_os'] uses reference for target_os variable, and extconf.rb
expects that this variable is all expanded. So instead, use RbConfig::CONFIG .
Closes #30
diff --git a/extconf.rb b/extconf.rb
index d17f926..55dcff5 100644
--- a/extconf.rb
+++ b/extconf.rb
@@ -14,7 +14,7 @@ $CFLAGS = case RUBY_VERSION
else; ''
end
-implementation = case CONFIG['host_os']
+implementation = case RbConfig::CONFIG['host_os']
when /linux/i; 'shadow'
when /sunos|solaris/i; 'shadow'
when /freebsd|mirbsd|netbsd|openbsd/i; 'pwd'

View file

@ -0,0 +1,72 @@
commit 7b450355b540df43bab2617fe25437dc3dde12af
Author: Mamoru TASAKA <mtasaka@fedoraproject.org>
Date: Thu Dec 1 12:54:31 2022 +0900
Replace taintedness function with generic one
Taintedness is deprecated from ruby 2.7.0 and is removed on ruby3.2.0preview3.
To keep compatibility with ruby older than 2.7, introduce -DRUBY30 compilation
flag from ruby3.0 and onwards, and replace taintedness function with generic one
when RUBY30 is defined (i.e. from ruby3.0 and onwards)
diff --git a/extconf.rb b/extconf.rb
index d17f926..04f8f97 100644
--- a/extconf.rb
+++ b/extconf.rb
@@ -10,7 +10,7 @@ require 'rbconfig'
$CFLAGS = case RUBY_VERSION
when /^1\.9/; '-DRUBY19'
when /^2\./; '-DRUBY19'
- when /^3\./; '-DRUBY19'
+ when /^3\./; '-DRUBY19 -DRUBY30'
else; ''
end
diff --git a/pwd/shadow.c b/pwd/shadow.c
index eeb96d4..e73e0db 100644
--- a/pwd/shadow.c
+++ b/pwd/shadow.c
@@ -56,8 +56,13 @@ static VALUE convert_pw_struct( struct passwd *entry )
{
/* Hmm. Why custom pw_change instead of sp_lstchg? */
return rb_struct_new(rb_sPasswdEntry,
+#if defined(RUBY30)
+ rb_str_new2(entry->pw_name), /* sp_namp */
+ rb_str_new2(entry->pw_passwd), /* sp_pwdp, encryped password */
+#else
rb_tainted_str_new2(entry->pw_name), /* sp_namp */
rb_tainted_str_new2(entry->pw_passwd), /* sp_pwdp, encryped password */
+#endif
Qnil, /* sp_lstchg, date when the password was last changed (in days since Jan 1, 1970) */
Qnil, /* sp_min, days that password must stay same */
Qnil, /* sp_max, days until password changes. */
@@ -66,7 +71,11 @@ static VALUE convert_pw_struct( struct passwd *entry )
INT2FIX(difftime(entry->pw_change, 0) / (24*60*60)), /* pw_change */
INT2FIX(difftime(entry->pw_expire, 0) / (24*60*60)), /* sp_expire */
Qnil, /* sp_flag */
+#if defined(RUBY30)
+ rb_str_new2(entry->pw_class), /* sp_loginclass, user access class */
+#else
rb_tainted_str_new2(entry->pw_class), /* sp_loginclass, user access class */
+#endif
NULL);
}
diff --git a/shadow/shadow.c b/shadow/shadow.c
index 35a77a1..5202ce5 100644
--- a/shadow/shadow.c
+++ b/shadow/shadow.c
@@ -34,8 +34,13 @@ static VALUE rb_eFileLock;
static VALUE convert_pw_struct( struct spwd *entry )
{
return rb_struct_new(rb_sPasswdEntry,
+#if defined(RUBY30)
+ rb_str_new2(entry->sp_namp),
+ rb_str_new2(entry->sp_pwdp),
+#else
rb_tainted_str_new2(entry->sp_namp),
rb_tainted_str_new2(entry->sp_pwdp),
+#endif
INT2FIX(entry->sp_lstchg),
INT2FIX(entry->sp_min),
INT2FIX(entry->sp_max),

View file

@ -2,13 +2,19 @@
Name: rubygem-%{gem_name}
Version: 2.5.1
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Ruby shadow password module
License: Public Domain
URL: https://github.com/apalmblad/ruby-shadow
Source0: http://rubygems.org/gems/%{gem_name}-%{version}.gem
Source1: https://raw.githubusercontent.com/apalmblad/ruby-shadow/master/test/basic_test.rb
Patch0: ruby-shadow-2.5.1-cflags.patch
# https://github.com/apalmblad/ruby-shadow/pull/29
# Ruby3.2 completely removes taintedness function
Patch1: ruby-shadow-2.5.1-taintedness-ruby32-removal.patch
# https://github.com/apalmblad/ruby-shadow/pull/31
# Ruby3.2 mkmf CONFIG uses reference for other variables yet more
Patch2: ruby-shadow-2.5.1-extconf-ruby32-fix.patch
BuildRequires: gcc
BuildRequires: ruby(release)
BuildRequires: rubygems-devel
@ -32,11 +38,13 @@ Documentation for %{name}.
gem unpack %{SOURCE0}
%setup -q -D -T -n %{gem_name}-%{version}
gem spec %{SOURCE0} -l --ruby > %{gem_name}.gemspec
%patch1 -p1
%patch2 -p1
%patch0 -p1
cp %{SOURCE1} .
%build
export CONFIGURE_ARGS="--with-cflags='%{optflags}'"
export CONFIGURE_ARGS="--with-cflags='%{optflags} -Werror=implicit-function-declaration'"
gem build %{gem_name}.gemspec
# %%gem_install compiles any C extensions and installs the gem into ./%%gem_dir
@ -83,6 +91,10 @@ popd
%doc %{gem_instdir}/README.euc
%changelog
* Thu Dec 1 2022 Mamoru TASAKA <mtasaka@fedoraproject.org> - 2.5.1-2
- Backport upstream pull request for ruby3.2 build issue
- Add -Werror=implicit-function explicitly to detect such function
* Thu Dec 1 2022 Mamoru TASAKA <mtasaka@fedoraproject.org> - 2.5.1-1
- 2.5.1