From 2402814db66ba8a00c8ff108fec7e5d837e06a2b Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Fri, 14 Jul 2023 20:09:15 -0700 Subject: [PATCH 1/3] Add JRuby 9.3 and 9.4 to the test matrix under both Bazel versions. (#13296) Prepare for 9.2 to be removed. Closes #13296 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/13296 from protocolbuffers:jruby_version_bump 82924ab6b38b97073dada29539b5f697ef34cd4c PiperOrigin-RevId: 548279470 --- .github/workflows/test_ruby.yml | 10 ++++++---- protobuf_deps.bzl | 4 ++-- .../v3.0.0/tests/repeated_field_test.rb | 8 +++++--- .../protobuf/jruby/RubyRepeatedField.java | 17 +++++++++++++---- ruby/tests/repeated_field_test.rb | 6 ++++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test_ruby.yml b/.github/workflows/test_ruby.yml index a401c32dc5..3dfa6b43ce 100644 --- a/.github/workflows/test_ruby.yml +++ b/.github/workflows/test_ruby.yml @@ -22,9 +22,10 @@ jobs: - { name: Ruby 3.1, ruby: ruby-3.1.0, bazel: 5.1.1} - { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1} - { name: JRuby 9.2, ruby: jruby-9.2.20.1, bazel: 5.1.1} - - { name: JRuby 9.3, ruby: jruby-9.3.4.0, bazel: 5.1.1} + - { name: JRuby 9.3, ruby: jruby-9.3.10.0, bazel: 5.1.1} + - { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1} - { name: Ruby 2.7 (Bazel6), ruby: ruby-2.7.0, bazel: 6.0.0} - - { name: JRuby 9.2 (Bazel6), ruby: jruby-9.2.20.1, bazel: 6.0.0} + - { name: JRuby 9.4 (Bazel6), ruby: jruby-9.4.3.0, bazel: 6.0.0} name: Linux ${{ matrix.name }} runs-on: ubuntu-latest @@ -113,9 +114,10 @@ jobs: - { name: Ruby 3.1, ruby: ruby-3.1.0, bazel: 5.1.1} - { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1} - { name: JRuby 9.2, ruby: jruby-9.2.20.1, bazel: 5.1.1} - - { name: JRuby 9.3, ruby: jruby-9.3.4.0, bazel: 5.1.1} + - { name: JRuby 9.3, ruby: jruby-9.3.10.0, bazel: 5.1.1} + - { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1} - { name: Ruby 2.7 (Bazel6), ruby: ruby-2.7.0, bazel: 6.0.0} - - { name: JRuby 9.2 (Bazel6), ruby: jruby-9.2.20.1, bazel: 6.0.0} + - { name: JRuby 9.4 (Bazel6), ruby: jruby-9.4.3.0, bazel: 6.0.0} name: Install ${{ matrix.name }} runs-on: ubuntu-latest steps: diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index b39ef74bd3..d89139a4cb 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -110,8 +110,8 @@ def protobuf_deps(): _github_archive( name = "rules_ruby", repo = "https://github.com/protocolbuffers/rules_ruby", - commit = "5cf6ff74161d7f985b9bf86bb3c5fb16cef6337b", - sha256 = "c88dd69eb50fcfd7fbc5d7db79adc6631ef0e1d80b3c94efe33ac5ee3ccc37f7", + commit = "8fca842a3006c3d637114aba4f6bf9695bb3a432", + sha256 = "2619f9a23cee6f6a198d9ef284b6f6cbc901545ee9a9aac9ffa6b83dbf17cf0c", ) if not native.existing_rule("rules_jvm_external"): diff --git a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb index 5fd943b996..56fa7fe41b 100755 --- a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb +++ b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb @@ -8,7 +8,7 @@ class RepeatedFieldTest < Test::Unit::TestCase def test_acts_like_enumerator m = TestMessage.new (Enumerable.instance_methods - TestMessage.new.repeated_string.methods).each do |method_name| - assert_equal "does not respond to #{method_name}", m.repeated_string.respond_to?(method_name), true + assert_respond_to m.repeated_string, method_name end end @@ -20,8 +20,10 @@ class RepeatedFieldTest < Test::Unit::TestCase :iter_for_each_with_index, :dimensions, :copy_data, :copy_data_simple, :nitems, :iter_for_reverse_each, :indexes, :append, :prepend] arr_methods -= [:union, :difference, :filter!] - arr_methods -= [:intersection, :deconstruct] # ruby 2.7 methods we can ignore - arr_methods -= [:intersect?] # ruby 3.1 methods we can ignore + # ruby 2.7 methods we can ignore + arr_methods -= [:intersection, :deconstruct, :resolve_feature_path] + # ruby 3.1 methods we can ignore + arr_methods -= [:intersect?] arr_methods.each do |method_name| assert_respond_to m.repeated_string, method_name end diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java index 77842d1290..90ab541518 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java @@ -74,6 +74,9 @@ public class RubyRepeatedField extends RubyObject { @JRubyMethod(required = 1, optional = 2) public IRubyObject initialize(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; + // Workaround for https://github.com/jruby/jruby/issues/7851. Can be removed when JRuby 9.4.3.0 + // is no longer supported. + if (args.length < 1) throw runtime.newArgumentError("Expected at least 1 argument"); this.storage = runtime.newArray(); IRubyObject ary = null; if (!(args[0] instanceof RubySymbol)) { @@ -141,14 +144,20 @@ public class RubyRepeatedField extends RubyObject { } else if (arg instanceof RubyRange) { RubyRange range = ((RubyRange) arg); - int first = normalizeArrayIndex(range.first(context)); - int last = normalizeArrayIndex(range.last(context)); + boolean beginless = range.begin(context).isNil(); + int first = + normalizeArrayIndex( + beginless ? RubyNumeric.int2fix(context.runtime, 0) : range.begin(context)); + boolean endless = range.end(context).isNil(); + int last = + normalizeArrayIndex( + endless ? RubyNumeric.int2fix(context.runtime, -1) : range.end(context)); if (last - first < 0) { return context.runtime.newEmptyArray(); } - - return this.storage.subseq(first, last - first + (range.isExcludeEnd() ? 0 : 1)); + boolean excludeEnd = range.isExcludeEnd() && !endless; + return this.storage.subseq(first, last - first + (excludeEnd ? 0 : 1)); } } /* assume 2 arguments */ diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 45909d374b..8e49fdce35 100755 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -20,8 +20,10 @@ class RepeatedFieldTest < Test::Unit::TestCase :iter_for_each_with_index, :dimensions, :copy_data, :copy_data_simple, :nitems, :iter_for_reverse_each, :indexes, :append, :prepend] arr_methods -= [:union, :difference, :filter!] - arr_methods -= [:intersection, :deconstruct] # ruby 2.7 methods we can ignore - arr_methods -= [:intersect?] # ruby 3.1 methods we can ignore + # ruby 2.7 methods we can ignore + arr_methods -= [:intersection, :deconstruct, :resolve_feature_path] + # ruby 3.1 methods we can ignore + arr_methods -= [:intersect?] arr_methods.each do |method_name| assert_respond_to m.repeated_string, method_name end From 14ea2cb2966f6ede44b91d5594d46d8ea45b64ef Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Mon, 17 Jul 2023 15:19:18 -0400 Subject: [PATCH 2/3] Update ruby gemspec required ruby version to >=2.7 --- ruby/google-protobuf.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index e20bcaac01..331b58c033 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.files += Dir.glob('ext/**/*') s.extensions= ["ext/google/protobuf_c/extconf.rb"] s.add_development_dependency "rake-compiler-dock", "= 1.2.1" end - s.required_ruby_version = '>= 2.5' + s.required_ruby_version = '>= 2.7' s.add_development_dependency "rake-compiler", "~> 1.1.0" s.add_development_dependency "test-unit", '~> 3.0', '>= 3.0.9' end From 2278f6db94519cf24eb94739809cda14dc6a95c5 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Mon, 17 Jul 2023 15:32:30 -0400 Subject: [PATCH 3/3] Drop JRuby 9.2 and 9.3 from GHA test matrix --- .github/workflows/test_ruby.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test_ruby.yml b/.github/workflows/test_ruby.yml index 3dfa6b43ce..b9b21bfd0c 100644 --- a/.github/workflows/test_ruby.yml +++ b/.github/workflows/test_ruby.yml @@ -21,8 +21,6 @@ jobs: - { name: Ruby 3.0, ruby: ruby-3.0.2, bazel: 5.1.1} - { name: Ruby 3.1, ruby: ruby-3.1.0, bazel: 5.1.1} - { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1} - - { name: JRuby 9.2, ruby: jruby-9.2.20.1, bazel: 5.1.1} - - { name: JRuby 9.3, ruby: jruby-9.3.10.0, bazel: 5.1.1} - { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1} - { name: Ruby 2.7 (Bazel6), ruby: ruby-2.7.0, bazel: 6.0.0} - { name: JRuby 9.4 (Bazel6), ruby: jruby-9.4.3.0, bazel: 6.0.0} @@ -113,8 +111,6 @@ jobs: - { name: Ruby 3.0, ruby: ruby-3.0.2, bazel: 5.1.1} - { name: Ruby 3.1, ruby: ruby-3.1.0, bazel: 5.1.1} - { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1} - - { name: JRuby 9.2, ruby: jruby-9.2.20.1, bazel: 5.1.1} - - { name: JRuby 9.3, ruby: jruby-9.3.10.0, bazel: 5.1.1} - { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1} - { name: Ruby 2.7 (Bazel6), ruby: ruby-2.7.0, bazel: 6.0.0} - { name: JRuby 9.4 (Bazel6), ruby: jruby-9.4.3.0, bazel: 6.0.0}