Skip to content

Commit

Permalink
Add JRuby 9.3 and 9.4 to the test matrix under both Bazel versions. (p…
Browse files Browse the repository at this point in the history
…rotocolbuffers#13296)

Prepare for 9.2 to be removed.

Closes protocolbuffers#13296

COPYBARA_INTEGRATE_REVIEW=protocolbuffers#13296 from protocolbuffers:jruby_version_bump 82924ab
PiperOrigin-RevId: 548279470
  • Loading branch information
JasonLunn authored and copybara-github committed Jul 15, 2023
1 parent cf304cb commit 59e19a7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/test_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions protobuf_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
8 changes: 5 additions & 3 deletions ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,8 +20,10 @@ def test_acts_like_an_array
: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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public RubyRepeatedField(
@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)) {
Expand Down Expand Up @@ -141,14 +144,20 @@ public IRubyObject index(ThreadContext context, IRubyObject[] args) {
} 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 */
Expand Down
6 changes: 4 additions & 2 deletions ruby/tests/repeated_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ def test_acts_like_an_array
: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
Expand Down

0 comments on commit 59e19a7

Please sign in to comment.