From 5387c6b7a2978d67e1cda90e4c7d043e1a162474 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 11 Jan 2022 16:14:20 +0100 Subject: [PATCH] Make the gem a noop on Rubies older than 2.6 Ref: https://github.com/mikel/mail/pull/1439 Some gems depend on io-wait, but still support older rubies, so they have to chose between droping support or not listing io-wait. But io-wait could act a a noop on older rubies. --- .github/workflows/test.yml | 24 ++++++++++++++++++++---- .gitignore | 2 ++ Rakefile | 21 +++++++++++++++++---- ext/io/wait/extconf.rb | 32 ++++++++++++++++++-------------- io-wait.gemspec | 6 +++++- 5 files changed, 62 insertions(+), 23 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2327256..1853194 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,11 +3,11 @@ name: ci on: [push, pull_request] jobs: - build: + test: runs-on: ${{ matrix.os }}-latest strategy: matrix: - ruby: [ 'head', '3.0', '2.7', '2.6' ] + ruby: [ 'head', '3.1', '3.0', '2.7', '2.6' ] os: [ ubuntu, macos, windows ] steps: - uses: actions/checkout@v2 @@ -16,6 +16,22 @@ jobs: with: ruby-version: ${{ matrix.ruby }} - name: Set up Bundler - run: gem install rake-compiler --no-document + run: bundle install - name: Run test - run: rake + run: bundle exec rake + build: + runs-on: ${{ matrix.os }}-latest + strategy: + matrix: + ruby: [ '2.5' ] + os: [ ubuntu, macos, windows ] + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - name: Set up Bundler + run: bundle install + - name: Install gem + run: bundle exec rake instal diff --git a/.gitignore b/.gitignore index 0f80caf..3612be8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ *.dll *.so ChangeLog +Gemfile.lock + diff --git a/Rakefile b/Rakefile index 83dc449..2ae431f 100644 --- a/Rakefile +++ b/Rakefile @@ -3,12 +3,25 @@ require "rake/testtask" name = "io/wait" -require 'rake/extensiontask' -extask = Rake::ExtensionTask.new(name) do |x| - x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}") +if RUBY_VERSION < "2.6" + task :compile do + # noop + end + + task :clean do + # noop + end + libs = [] +else + require 'rake/extensiontask' + extask = Rake::ExtensionTask.new(name) do |x| + x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}") + end + libs = ["lib/#{RUBY_VERSION}/#{extask.platform}"] end + Rake::TestTask.new(:test) do |t| - t.libs = ["lib/#{RUBY_VERSION}/#{extask.platform}"] + t.libs = libs t.libs << "test/lib" t.ruby_opts << "-rhelper" t.test_files = FileList["test/**/test_*.rb"] diff --git a/ext/io/wait/extconf.rb b/ext/io/wait/extconf.rb index d20ff45..eecdcce 100644 --- a/ext/io/wait/extconf.rb +++ b/ext/io/wait/extconf.rb @@ -1,20 +1,24 @@ # frozen_string_literal: false require 'mkmf' -target = "io/wait" -have_func("rb_io_wait") -unless macro_defined?("DOSISH", "#include ") - have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil - fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h| - have_macro("FIONREAD", [h, ioctl_h].compact) - end - if fionread - $defs << "-DFIONREAD_HEADER=\"<#{fionread}>\"" - create_makefile(target) - end +if RUBY_VERSION < "2.6" + File.write("Makefile", dummy_makefile($srcdir).join("")) else - if have_func("rb_w32_ioctlsocket", "ruby.h") - have_func("rb_w32_is_socket", "ruby.h") - create_makefile(target) + target = "io/wait" + have_func("rb_io_wait") + unless macro_defined?("DOSISH", "#include ") + have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil + fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h| + have_macro("FIONREAD", [h, ioctl_h].compact) + end + if fionread + $defs << "-DFIONREAD_HEADER=\"<#{fionread}>\"" + create_makefile(target) + end + else + if have_func("rb_w32_ioctlsocket", "ruby.h") + have_func("rb_w32_is_socket", "ruby.h") + create_makefile(target) + end end end diff --git a/io-wait.gemspec b/io-wait.gemspec index ec7c05d..1cdb0cd 100644 --- a/io-wait.gemspec +++ b/io-wait.gemspec @@ -10,7 +10,6 @@ Gem::Specification.new do |spec| spec.description = %q{Waits until IO is readable or writable without blocking.} spec.homepage = "https://github.com/ruby/io-wait" spec.licenses = ["Ruby", "BSD-2-Clause"] - spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0") spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage @@ -24,4 +23,9 @@ Gem::Specification.new do |spec| spec.bindir = "exe" spec.executables = [] spec.require_paths = ["lib"] + + spec.add_development_dependency "bundler" + spec.add_development_dependency "rake" + spec.add_development_dependency "rake-compiler" + spec.add_development_dependency "test-unit" end