From 3b173aca5749b5eb5950a5feb36aef13dfb26e2f Mon Sep 17 00:00:00 2001 From: Vesa Laakso <482561+valscion@users.noreply.github.com> Date: Wed, 7 May 2025 09:29:28 +0300 Subject: [PATCH 1/2] Regenerate protobuf files with libprotoc 26.0 Result of: ``` cd lib/ protoc **/*.proto --ruby_out=. ``` --- lib/google/type/date_pb.rb | 23 +---------------------- lib/protobuf_nested_struct/struct_pb.rb | 25 +------------------------ 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/lib/google/type/date_pb.rb b/lib/google/type/date_pb.rb index cc21100..0d3d80c 100644 --- a/lib/google/type/date_pb.rb +++ b/lib/google/type/date_pb.rb @@ -8,28 +8,7 @@ descriptor_data = "\n\x16google/type/date.proto\x12\x0bgoogle.type\"0\n\x04\x44\x61te\x12\x0c\n\x04year\x18\x01 \x01(\x05\x12\r\n\x05month\x18\x02 \x01(\x05\x12\x0b\n\x03\x64\x61y\x18\x03 \x01(\x05\x42]\n\x0f\x63om.google.typeB\tDateProtoP\x01Z4google.golang.org/genproto/googleapis/type/date;date\xf8\x01\x01\xa2\x02\x03GTPb\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ - ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) module Google module Type diff --git a/lib/protobuf_nested_struct/struct_pb.rb b/lib/protobuf_nested_struct/struct_pb.rb index 0eaa102..369f315 100644 --- a/lib/protobuf_nested_struct/struct_pb.rb +++ b/lib/protobuf_nested_struct/struct_pb.rb @@ -11,30 +11,7 @@ descriptor_data = "\n#protobuf_nested_struct/struct.proto\x12\x16protobuf_nested_struct\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x16google/type/date.proto\"\xaa\x01\n\x12HashMapStringValue\x12\x46\n\x06\x66ields\x18\x01 \x03(\x0b\x32\x36.protobuf_nested_struct.HashMapStringValue.FieldsEntry\x1aL\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12,\n\x05value\x18\x02 \x01(\x0b\x32\x1d.protobuf_nested_struct.Value:\x02\x38\x01\"\x84\x03\n\x05Value\x12\x37\n\nnull_value\x18\x01 \x01(\x0e\x32!.protobuf_nested_struct.NullValueH\x00\x12\x16\n\x0c\x64ouble_value\x18\x02 \x01(\x01H\x00\x12\x13\n\tint_value\x18\x03 \x01(\x03H\x00\x12\x16\n\x0cstring_value\x18\x04 \x01(\tH\x00\x12\x14\n\nbool_value\x18\x05 \x01(\x08H\x00\x12\'\n\ndate_value\x18\x06 \x01(\x0b\x32\x11.google.type.DateH\x00\x12\x35\n\x0ftimestamp_value\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x12\x46\n\x10string_map_value\x18\x14 \x01(\x0b\x32*.protobuf_nested_struct.HashMapStringValueH\x00\x12\x37\n\nlist_value\x18\x15 \x01(\x0b\x32!.protobuf_nested_struct.ListValueH\x00\x42\x06\n\x04kind\":\n\tListValue\x12-\n\x06values\x18\x01 \x03(\x0b\x32\x1d.protobuf_nested_struct.Value*\x1b\n\tNullValue\x12\x0e\n\nNULL_VALUE\x10\x00\x62\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ - ["google.type.Date", "google/type/date.proto"], - ["google.protobuf.Timestamp", "google/protobuf/timestamp.proto"], - ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) module ProtobufNestedStruct HashMapStringValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.HashMapStringValue").msgclass From 5b2ca3b64854f047e937a2daee511df483979ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Wed, 14 May 2025 09:05:24 +0200 Subject: [PATCH 2/2] Jump on last major release as a minimal requirement Makes sense long term, one can prefer older releases when stuck with ancient proto versions. --- .../workflows/protobuf_nested_struct_test.yml | 4 +- Gemfile.google_protobuf_3_25 | 10 --- Gemfile.google_protobuf_3_25.lock | 62 ------------------- Gemfile.lock | 2 +- protobuf_nested_struct.gemspec | 2 +- 5 files changed, 3 insertions(+), 77 deletions(-) delete mode 100644 Gemfile.google_protobuf_3_25 delete mode 100644 Gemfile.google_protobuf_3_25.lock diff --git a/.github/workflows/protobuf_nested_struct_test.yml b/.github/workflows/protobuf_nested_struct_test.yml index 724b74a..f8029cb 100644 --- a/.github/workflows/protobuf_nested_struct_test.yml +++ b/.github/workflows/protobuf_nested_struct_test.yml @@ -17,15 +17,13 @@ jobs: fail-fast: false matrix: ruby: [ruby-3.4, ruby-3.3, ruby-3.2] - gemfile: [Gemfile, Gemfile.google_protobuf_3_25] env: - BUNDLE_GEMFILE: "${{ matrix.gemfile }}" RUBYOPT: "--enable-frozen-string-literal" steps: - uses: actions/checkout@v4 with: fetch-depth: 1 - - run: test -e "${{ matrix.gemfile }}.lock" + - run: test -e Gemfile.lock - uses: ruby/setup-ruby@v1 with: ruby-version: "${{ matrix.ruby }}" diff --git a/Gemfile.google_protobuf_3_25 b/Gemfile.google_protobuf_3_25 deleted file mode 100644 index c4d0cb9..0000000 --- a/Gemfile.google_protobuf_3_25 +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -gemspec - -gem "google-protobuf", ">= 3.25.7", "< 4" -gem "mutant-rspec" -gem "rspec" -gem "rake" diff --git a/Gemfile.google_protobuf_3_25.lock b/Gemfile.google_protobuf_3_25.lock deleted file mode 100644 index c190511..0000000 --- a/Gemfile.google_protobuf_3_25.lock +++ /dev/null @@ -1,62 +0,0 @@ -PATH - remote: . - specs: - protobuf_nested_struct (1.2.1) - google-protobuf (>= 3.25.7) - -GEM - remote: https://rubygems.org/ - specs: - ast (2.4.3) - diff-lcs (1.6.2) - google-protobuf (3.25.7) - mutant (0.13.1) - diff-lcs (~> 1.3) - parser (~> 3.3.0) - regexp_parser (~> 2.10) - sorbet-runtime (~> 0.5.0) - unparser (~> 0.7.0) - mutant-rspec (0.13.1) - mutant (= 0.13.1) - rspec-core (>= 3.8.0, < 4.0.0) - parser (3.3.8.0) - ast (~> 2.4.1) - racc - racc (1.8.1) - rake (13.2.1) - regexp_parser (2.10.0) - rspec (3.13.0) - rspec-core (~> 3.13.0) - rspec-expectations (~> 3.13.0) - rspec-mocks (~> 3.13.0) - rspec-core (3.13.3) - rspec-support (~> 3.13.0) - rspec-expectations (3.13.4) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-mocks (3.13.4) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-support (3.13.3) - sorbet-runtime (0.5.12087) - unparser (0.7.0) - diff-lcs (~> 1.6) - parser (>= 3.3.0) - -PLATFORMS - aarch64-linux - arm64-darwin - ruby - x86-linux - x86_64-darwin - x86_64-linux - -DEPENDENCIES - google-protobuf (>= 3.25.7, < 4) - mutant-rspec - protobuf_nested_struct! - rake - rspec - -BUNDLED WITH - 2.6.9 diff --git a/Gemfile.lock b/Gemfile.lock index 9c633f7..443b454 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: protobuf_nested_struct (1.2.1) - google-protobuf (>= 3.25.7) + google-protobuf (>= 4.26.0) GEM remote: https://rubygems.org/ diff --git a/protobuf_nested_struct.gemspec b/protobuf_nested_struct.gemspec index 9ad1274..e8d6770 100644 --- a/protobuf_nested_struct.gemspec +++ b/protobuf_nested_struct.gemspec @@ -29,5 +29,5 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 2.7" - spec.add_dependency "google-protobuf", ">= 3.25.7" + spec.add_dependency "google-protobuf", ">= 4.26.0" end