Skip to content

Instantly share code, notes, and snippets.

@pvalena
Created January 18, 2022 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvalena/ff668b0472061112822c75dd69fd02a5 to your computer and use it in GitHub Desktop.
Save pvalena/ff668b0472061112822c75dd69fd02a5 to your computer and use it in GitHub Desktop.
--- rubygem-puma/.generated.spec 2022-01-18 13:02:43.566268649 +0100
+++ rubygem-puma/rubygem-puma.spec 2022-01-18 12:49:17.975355833 +0100
@@ -1,25 +1,54 @@
-Downloaded puma-5.5.2
-# Generated from puma-5.5.2.gem by gem2rpm -*- rpm-spec -*-
+# Generated from puma-3.6.0.gem by gem2rpm -*- rpm-spec -*-
%global gem_name puma
+# For testing purposes
+#%%global prerelease
+
+# Allow to use precompiled version of parser, because Ragel not always
+# behaves correctly.
+%bcond_without ragel
+%bcond_without help2man
+
Name: rubygem-%{gem_name}
Version: 5.5.2
Release: 1%{?dist}
-Summary: Puma is a simple, fast, threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications
-License: BSD-3-Clause
-URL: https://puma.io
+Summary: A simple, fast, threaded, and highly concurrent HTTP 1.1 server
+License: BSD
+URL: http://puma.io
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
+# The puma gem doesn't ship with the test suite.
+# git clone https://github.com/puma/puma --no-checkout
+# cd puma && git archive -v -o puma-5.5.2-tests.txz v5.5.2 test
+Source1: %{gem_name}-%{version}%{?prerelease}-tests.txz
+# The puma gem doesn't ship with the examples used in test suite.
+# git archive -v -o puma-5.5.2-examples.txz v5.5.2 examples
+Source3: %{gem_name}-%{version}%{?prerelease}-examples.txz
+# Set the default cipher list "PROFILE=SYSTEM".
+# https://fedoraproject.org/wiki/Packaging:CryptoPolicies
+Patch2: rubygem-puma-3.6.0-fedora-crypto-policy-cipher-list.patch
+
+BuildRequires: openssl-devel
BuildRequires: ruby(release)
BuildRequires: rubygems-devel
-BuildRequires: ruby-devel >= 2.2
+BuildRequires: ruby-devel
+BuildRequires: rubygem(rack)
+BuildRequires: rubygem(minitest)
+BuildRequires: rubygem(minitest-stub-const)
+BuildRequires: rubygem(nio4r)
+%if %{with ragel}
+BuildRequires: %{_bindir}/ragel
+%endif
+%if %{with help2man}
+BuildRequires: help2man
+%endif
# Compiler is required for build of gem binary extension.
# https://fedoraproject.org/wiki/Packaging:C_and_C++#BuildRequires_and_Requires
BuildRequires: gcc
%description
-Puma is a simple, fast, threaded, and highly parallel HTTP 1.1 server for
+Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for
Ruby/Rack applications. Puma is intended for use in both development and
-production environments. It's great for highly parallel Ruby implementations
+production environments. It's great for highly concurrent Ruby implementations
such as Rubinius and JRuby as well as as providing process worker support to
support CRuby well.
@@ -33,14 +62,26 @@
Documentation for %{name}.
%prep
-%setup -q -n %{gem_name}-%{version}
+%setup -q -n %{gem_name}-%{version}%{?prerelease} -b 1 -b 3
-%build
-# Create the gem as gem install only works on a gem file
-gem build ../%{gem_name}-%{version}.gemspec
+%patch2 -p1
-# %%gem_install compiles any C extensions and installs the gem into ./%%gem_dir
-# by default, so that we can move it into the buildroot in %%install
+%if %{with ragel}
+# Test suite on s390x fails on various places with following error:
+# ext/puma_http11/http11_parser.rl:123: puma_parser_execute: Assertion `parser->nread <= len && "nread longer than length"' failed.
+# Keep the upstream generated parser which appears to work.
+# https://github.com/adrian-thurston/ragel/issues/51
+%ifnarch s390x
+# Regenarate the parser.
+# https://fedoraproject.org/wiki/Packaging:Guidelines#Use_of_pregenerated_code
+rm -f ext/puma_http11/http11_parser.c
+ragel ext/puma_http11/http11_parser.rl -G2 -I ext/puma_http11 \
+ -o ext/puma_http11/http11_parser.c
+%endif
+%endif
+
+%build
+gem build ../%{gem_name}-%{version}%{?prerelease}.gemspec
%gem_install
%install
@@ -48,8 +89,9 @@
cp -a .%{gem_dir}/* \
%{buildroot}%{gem_dir}/
-mkdir -p %{buildroot}%{gem_extdir_mri}
-cp -a .%{gem_extdir_mri}/{gem.build_complete,*.so} %{buildroot}%{gem_extdir_mri}/
+mkdir -p %{buildroot}%{gem_extdir_mri}/puma
+cp -a .%{gem_extdir_mri}/gem.build_complete %{buildroot}%{gem_extdir_mri}/
+cp -a .%{gem_extdir_mri}/puma/*.so %{buildroot}%{gem_extdir_mri}/puma
# Prevent dangling symlink in -debuginfo (rhbz#878863).
rm -rf %{buildroot}%{gem_instdir}/ext/
@@ -60,9 +102,92 @@
find %{buildroot}%{gem_instdir}/bin -type f | xargs chmod a+x
+find %{buildroot}%{gem_instdir}/bin -type f | \
+ xargs sed -i 's|^#!/usr/bin/env ruby$|#!/usr/bin/ruby|'
+
+%if %{with help2man}
+# Turn `puma --help` into man page.
+export RUBYOPT="-I%{buildroot}%{gem_extdir_mri}:%{buildroot}%{gem_libdir}"
+mkdir -p %{buildroot}%{_mandir}/man1
+help2man --no-discard-stderr -N -s1 -o %{buildroot}%{_mandir}/man1/%{gem_name}.1 \
+ %{buildroot}/usr/share/gems/gems/%{gem_name}-%{version}/bin/%{gem_name}
+%endif
+
+
+# Run the test suite
%check
pushd .%{gem_instdir}
-# Run the test suite.
+cp -a %{_builddir}/test .
+ln -s %{_builddir}/examples .
+
+# We do not ship minitest-retry, minitest-proveit.
+sed -i -e "/require..minitest\/\(retry\|proveit\)./ s/^/#/" test/helper.rb
+sed -i "/Minitest::Retry/ s/^/#/" test/helper.rb
+sed -i '/prove_it!/ s/^/#/' test/helper.rb
+
+# Increase timeout seconds to avoid the timeout for every test case on Koji.
+# TimeoutEveryTestCase::TestTookTooLong: execution expired
+sed -i '/::Timeout.timeout/ s/45/300/' test/helper.rb
+
+# Tests use bundler
+mv test/test_preserve_bundler_env.rb{,.disable}
+mv test/test_worker_gem_independence.rb{,.disable}
+sed -i '/^\s*def test_prune_bundler_with_multiple_workers$/a\
+ skip' test/test_integration_pumactl.rb
+sed -i '/^\s*def test_prune_bundler_with_multiple_workers$/a\
+ skip' test/test_integration_cluster.rb
+
+# Tests require systemd (sd_notify gem)
+mv test/test_integration_systemd.rb{,.disable}
+
+# We don't have localhost gem in Fedora.
+mv test/test_puma_localhost_authority.rb{,.disable}
+
+# Disable unstable tests
+# TestIntegrationSingle#test_closed_listener
+# TestIntegrationSingle#test_puma_started_log_writing
+# TestIntegrationSingle#test_write_to_log
+# TestIntegrationCluster#test_refork
+# TestIntegrationCluster#test_hot_restart_does_not_drop_connections
+# e.g. Errno::EMFILE: Too many open files - /usr/bin/ruby
+mv test/test_integration_single.rb{,.disable}
+# https://github.com/puma/puma/issues/2209
+mv test/test_integration_cluster.rb{,.disable}
+
+# Skip an unstable test on Koji.
+# TestCLI#test_control failing with "pool_capacity": 0
+# https://github.com/puma/puma/issues/2212
+%ifarch ppc64le s390x aarch64
+sed -i '/^ def test_control$/,/^ end$/ s/^/#/' test/test_cli.rb
+%endif
+
+# These test often timeouts on Koji.
+sed -i '/^ def test_timeout_in_data_phase$/a\
+ skip' test/test_puma_server.rb
+sed -i '/^ def test_plugin$/a\
+ skip' test/test_plugin.rb
+
+# Skip a randomly failed SSL test.
+# Errno::ECONNRESET: Connection reset by peer
+# /usr/share/ruby/openssl/buffering.rb:182:in `sysread_nonblock'
+# /usr/share/ruby/openssl/buffering.rb:182:in `read_nonblock'
+sed -i '/^ def test_verify_fail_if_client_unknown_ca$/a\
+ skip' test/test_puma_server_ssl.rb
+
+# Make binary exension available in Ruby load path.
+# Enable verbose mode to check unstable tests easily.
+RUBYOPT="-Ilib:$(dirs +1 -l)%{gem_extdir_mri}" \
+CI=1 \
+LC_ALL=C.UTF-8 \
+ruby -e 'Dir.glob "./test/**/test_*.rb", &method(:require)' \
+ -- -v
+
+%if %{with help2man}
+# Check `--help` output, using which man page is created
+export RUBYOPT="-I%{buildroot}%{gem_extdir_mri}:%{buildroot}%{gem_libdir}"
+%{buildroot}/usr/share/gems/gems/%{gem_name}-%{version}/bin/%{gem_name} --help 2> /dev/null \
+ | grep -q '^puma <options> <rackup file>'
+%endif
popd
%files
@@ -73,16 +198,142 @@
%license %{gem_instdir}/LICENSE
%{gem_instdir}/bin
%{gem_libdir}
-%{gem_instdir}/tools
%exclude %{gem_cache}
%{gem_spec}
+%if %{with help2man}
+%{_mandir}/man1/%{gem_name}.1*
+%endif
%files doc
%doc %{gem_docdir}
%doc %{gem_instdir}/History.md
%doc %{gem_instdir}/README.md
%doc %{gem_instdir}/docs
+%{gem_instdir}/tools
%changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment