From 423b369be57ab0ff2e44fc4e67c56a4bdb6b4f56 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 14 Jul 2023 13:56:08 -0400 Subject: [PATCH 1/3] YARP gem supports ruby >= 3.0 and add test coverage to ensure compatibility --- .github/workflows/main.yml | 2 +- Gemfile | 2 +- yarp.gemspec | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9353787658..97a78d6fdb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -144,7 +144,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ["3.2", "head"] + ruby: ["2.7", "3.0", "3.1", "3.2", "head"] os: [ ubuntu-latest, macos-latest, windows-latest ] runs-on: ${{ matrix.os }} steps: diff --git a/Gemfile b/Gemfile index 90102c5b77..b1787eb654 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -ruby ">= 3.1.0" +ruby ">= 2.7.0" gemspec diff --git a/yarp.gemspec b/yarp.gemspec index 2fccd20e23..3bc1ca61f7 100644 --- a/yarp.gemspec +++ b/yarp.gemspec @@ -10,6 +10,8 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/ruby/yarp" spec.license = "MIT" + spec.required_ruby_version = ">= 2.7.0" + spec.require_paths = ["lib"] spec.files = [ "CODE_OF_CONDUCT.md", From 7ec4fc739b32f55fc1c4d9cce940b2f2fc888987 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 14 Jul 2023 17:49:28 -0400 Subject: [PATCH 2/3] squash --- .github/workflows/main.yml | 2 +- Gemfile | 2 +- yarp.gemspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 97a78d6fdb..d6db93fc57 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -144,7 +144,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ["2.7", "3.0", "3.1", "3.2", "head"] + ruby: ["3.0", "3.1", "3.2", "head"] os: [ ubuntu-latest, macos-latest, windows-latest ] runs-on: ${{ matrix.os }} steps: diff --git a/Gemfile b/Gemfile index b1787eb654..ecf21e2ec6 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -ruby ">= 2.7.0" +ruby ">= 3.0.0" gemspec diff --git a/yarp.gemspec b/yarp.gemspec index 3bc1ca61f7..d4b8008831 100644 --- a/yarp.gemspec +++ b/yarp.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/ruby/yarp" spec.license = "MIT" - spec.required_ruby_version = ">= 2.7.0" + spec.required_ruby_version = ">= 3.0.0" spec.require_paths = ["lib"] spec.files = [ From 00459b82319dae3027414de7edd807d5463a50b9 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 14 Jul 2023 17:48:01 -0400 Subject: [PATCH 3/3] Avoid use of String#unpack1 offset with Ruby < 3.1 --- templates/lib/yarp/serialize.rb.erb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/templates/lib/yarp/serialize.rb.erb b/templates/lib/yarp/serialize.rb.erb index 27bd13fb4a..9458253f6e 100644 --- a/templates/lib/yarp/serialize.rb.erb +++ b/templates/lib/yarp/serialize.rb.erb @@ -89,8 +89,13 @@ module YARP unless constant offset = constant_pool_offset + index * 8 - start = serialized.unpack1("L", offset: offset) - length = serialized.unpack1("L", offset: offset + 4) + if RUBY_VERSION >= "3.1" + start = serialized.unpack1("L", offset: offset) + length = serialized.unpack1("L", offset: offset + 4) + else + start = serialized[offset..].unpack1("L") + length = serialized[offset+4..].unpack1("L") + end constant = input.byteslice(start, length).to_sym constant_pool[index] = constant