ADD: added new version of protobuf

This commit is contained in:
Henry Winkel
2022-12-20 10:09:28 +01:00
parent 4a79559129
commit 1e2b3dda7b
1513 changed files with 123720 additions and 83381 deletions

View File

@@ -3,204 +3,30 @@
# See also code generation logic under /src/google/protobuf/compiler/ruby.
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//build_defs:internal_shell.bzl", "inline_sh_test")
load("//conformance:defs.bzl", "conformance_test")
load("//:protobuf.bzl", "internal_ruby_proto_library")
load(":internal.bzl", "internal_ruby_extension")
################################################################################
# Ruby Runtime
################################################################################
config_setting(
name = "java_ruby",
values = {"define": "ruby_platform=java"},
)
config_setting(
name = "c_ruby",
values = {"define": "ruby_platform=c"},
)
filegroup(
name = "srcs",
srcs = glob([
"lib/**/*.rb",
"src/**/*.proto",
]) + [
"Gemfile",
"Rakefile",
"google-protobuf.gemspec",
"pom.xml",
],
)
internal_ruby_extension(
name = "protobuf_c_mac",
extension = "lib/google/protobuf_c.bundle",
deps = glob(["ext/google/protobuf_c/*"]),
target_compatible_with = select({
":java_ruby": ["@platforms//:incompatible"],
"//conditions:default": ["@platforms//os:osx"],
}),
)
internal_ruby_extension(
name = "protobuf_c",
extension = "lib/google/protobuf_c.so",
deps = glob(["ext/google/protobuf_c/*"]),
target_compatible_with = select({
":java_ruby": ["@platforms//:incompatible"],
"@platforms//os:osx": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
internal_ruby_extension(
name = "protobuf_java",
extension = "lib/google/protobuf_java.jar",
deps = glob(["src/**/*.java"]),
target_compatible_with = select({
":java_ruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
filegroup(
name = "protobuf",
srcs = [
":srcs",
"@utf8_range//:utf8_range_srcs",
] + select({
":java_ruby": [":protobuf_java"],
"@bazel_tools//src/conditions:darwin": [":protobuf_c_mac"],
"//conditions:default": [":protobuf_c"],
}),
visibility = [
"//conformance:__subpackages__",
"//ruby:__subpackages__",
],
)
################################################################################
# Tests
################################################################################
filegroup(
name = "tests",
srcs = glob(["tests/*.rb"]),
)
filegroup(
name = "test_protos",
srcs = glob(["tests/*.proto"]),
)
internal_ruby_proto_library(
name = "test_ruby_protos",
srcs = [":test_protos"],
proto_deps = ["//:well_known_protos"],
includes = [".", "src", "ruby/tests"],
)
inline_sh_test(
name = "test",
srcs = [
"Rakefile",
],
deps = [
":protobuf",
":test_ruby_protos",
":tests",
"//:well_known_ruby_protos",
],
cmd = """
pushd `dirname $(location Rakefile)`
RUBYLIB=../src:tests:. BAZEL=true rake test
popd
""",
)
inline_sh_test(
name = "gc_test",
srcs = [
"Rakefile",
],
deps = [
":protobuf",
":test_ruby_protos",
":tests",
"//:well_known_ruby_protos",
],
cmd = """
pushd `dirname $(location Rakefile)`
RUBYLIB=../src:tests:. BAZEL=true rake gc_test
popd
""",
)
conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_ruby.txt",
testee = "//conformance:conformance_ruby",
text_format_failure_list = "//conformance:text_format_failure_list_ruby.txt",
target_compatible_with = select({
":java_ruby": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
conformance_test(
name = "conformance_test_jruby",
failure_list = "//conformance:failure_list_jruby.txt",
testee = "//conformance:conformance_ruby",
text_format_failure_list = "//conformance:text_format_failure_list_jruby.txt",
target_compatible_with = select({
":java_ruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
genrule(
name = "copy_ruby_amalgamation_h",
srcs = ["@upb//:ruby-upb.h"],
outs = ["generated-in/ext/google/protobuf_c/ruby-upb.h"],
cmd = "cp $< $@",
)
genrule(
name = "copy_ruby_amalgamation_c",
srcs = ["@upb//:ruby-upb.c"],
outs = ["generated-in/ext/google/protobuf_c/ruby-upb.c"],
cmd = "cp $< $@",
)
staleness_test(
name = "test_amalgamation_staleness",
outs = [
"ext/google/protobuf_c/ruby-upb.h",
"ext/google/protobuf_c/ruby-upb.c",
],
generated_pattern = "generated-in/%s",
)
################################################################################
# Distribution files
################################################################################
pkg_files(
name = "dist_files",
srcs = glob([
"compatibility_tests/v3.0.0/**/*",
"ext/google/protobuf_c/*",
"src/main/java/com/google/protobuf/jruby/*.java",
"tests/*.proto",
"tests/*.rb",
]) + [
":srcs",
".gitignore",
"BUILD.bazel",
"internal.bzl",
"Gemfile",
"README.md",
"Rakefile",
"google-protobuf.gemspec",
"lib/google/protobuf.rb",
"lib/google/protobuf/descriptor_dsl.rb",
"lib/google/protobuf/message_exts.rb",
"lib/google/protobuf/repeated_field.rb",
"lib/google/protobuf/well_known_types.rb",
"pom.xml",
"src/main/java/google/ProtobufJavaService.java",
"src/main/sentinel.proto",
"travis-test.sh",
],
strip_prefix = strip_prefix.from_root(""),

View File

@@ -9,7 +9,7 @@ install protoc as well to have Ruby code generation functionality.
Installation from Gem
---------------------
In Gemfile (Please check which version of Protocol Buffers you need: [RubyGems](https://rubygems.org/gems/google-protobuf)):
In Gemfile (Please check a version of Protocol Buffers you needed [RubyGems](https://rubygems.org/gems/google-protobuf)):
gem 'google-protobuf'

View File

@@ -39,8 +39,8 @@ proto2_protos = %w[
if !ENV['PROTOC'].nil?
protoc_command = ENV['PROTOC']
elsif system('../bazel-bin/protoc --version')
protoc_command = '../bazel-bin/protoc'
elsif system('../src/protoc --version')
protoc_command = '../src/protoc'
else
protoc_command = 'protoc'
end
@@ -49,7 +49,7 @@ genproto_output = []
# We won't have access to .. from within docker, but the proto files
# will be there, thanks to the :genproto rule dependency for gem:native.
unless ENV['IN_DOCKER'] == 'true' or ENV['BAZEL'] == 'true'
unless ENV['IN_DOCKER'] == 'true'
well_known_protos.each do |proto_file|
input_file = "../src/" + proto_file
output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb")
@@ -84,16 +84,12 @@ if RUBY_PLATFORM == "java"
else
unless ENV['IN_DOCKER'] == 'true'
# We need utf8_range in-tree.
if ENV['BAZEL'] == 'true'
utf8_root = '../external/utf8_range'
else
utf8_root = '../third_party/utf8_range'
end
FileUtils.mkdir_p("ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp(utf8_root+"/utf8_range.h", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp(utf8_root+"/naive.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp(utf8_root+"/range2-neon.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp(utf8_root+"/range2-sse.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp("../third_party/utf8_range/utf8_range.h", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp("../third_party/utf8_range/naive.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp("../third_party/utf8_range/range2-neon.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp("../third_party/utf8_range/range2-sse.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp("../third_party/utf8_range/LICENSE", "ext/google/protobuf_c/third_party/utf8_range")
end
Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
@@ -157,15 +153,13 @@ end
Gem::PackageTask.new(spec) do |pkg|
end
# Skip build/genproto in Bazel builds, where we expect this to
# be done already.
Rake::TestTask.new(:test => ENV['BAZEL'] == 'true' ? [] : [:build, :genproto]) do |t|
Rake::TestTask.new(:test => [:build, :genproto]) do |t|
t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb", "tests/common_tests.rb")
end
# gc_test needs to be split out to ensure the generated file hasn't been
# imported by other tests.
Rake::TestTask.new(:gc_test => ENV['BAZEL'] == 'true' ? [] : :build) do |t|
Rake::TestTask.new(:gc_test => :build) do |t|
t.test_files = FileList["tests/gc_test.rb"]
end

View File

@@ -1,56 +0,0 @@
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:internal_shell.bzl", "inline_sh_test")
load("//:protobuf.bzl", "internal_ruby_proto_library")
filegroup(
name = "tests",
srcs = glob(["tests/*.rb"]),
)
filegroup(
name = "test_protos",
srcs = glob(["tests/*.proto"]),
)
internal_ruby_proto_library(
name = "test_ruby_protos",
srcs = [":test_protos"],
includes = ["."],
)
inline_sh_test(
name = "test",
srcs = [
"Rakefile",
],
deps = [
":test_ruby_protos",
":tests",
"//:well_known_ruby_protos",
"//ruby:protobuf",
],
cmd = """
pushd `dirname $(location Rakefile)`
RUBYLIB=.:tests:../../lib:../../../src BAZEL=true rake test
popd
""",
)
################################################################################
# Distribution files
############################################################################
pkg_files(
name = "dist_files",
srcs = glob([
"**/*.rb",
"**/*.proto"
]) + [
"BUILD.bazel",
"Rakefile",
"README.md",
"test.sh",
],
strip_prefix = strip_prefix.from_root(""),
visibility = ["//pkg:__pkg__"],
)

View File

@@ -2,17 +2,14 @@ require "rake/testtask"
# Proto for tests.
genproto_output = []
genproto_output << "tests/generated_code.rb"
genproto_output << "tests/test_import.rb"
file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
sh "./protoc --ruby_out=. tests/generated_code.proto"
end
unless ENV['BAZEL'] == 'true'
genproto_output << "tests/generated_code.rb"
genproto_output << "tests/test_import.rb"
file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
sh "./protoc --ruby_out=. tests/generated_code.proto"
end
file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
sh "./protoc --ruby_out=. tests/test_import.proto"
end
file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
sh "./protoc --ruby_out=. tests/test_import.proto"
end
task :genproto => genproto_output

View File

@@ -25,4 +25,4 @@ $srcs = ["protobuf.c", "convert.c", "defs.c", "message.c",
"repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
"naive.c", "range2-neon.c", "range2-sse.c"]
create_makefile(ext_name, Dir.pwd+"/../../../../ext/google/protobuf_c")
create_makefile(ext_name)

View File

@@ -37,7 +37,6 @@
#include "repeated_field.h"
static VALUE cParseError = Qnil;
static VALUE cAbstractMessage = Qnil;
static ID descriptor_instancevar_interned;
static VALUE initialize_rb_class_with_no_args(VALUE klass) {
@@ -696,20 +695,15 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
if (m1 == m2) return true;
size_t size1, size2;
int encode_opts =
kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
int encode_opts = kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic;
upb_Arena* arena_tmp = upb_Arena_New();
const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
// Compare deterministically serialized payloads with no unknown fields.
char* data1;
char* data2;
upb_EncodeStatus status1 =
upb_Encode(m1, layout, encode_opts, arena_tmp, &data1, &size1);
upb_EncodeStatus status2 =
upb_Encode(m2, layout, encode_opts, arena_tmp, &data2, &size2);
char* data1 = upb_Encode(m1, layout, encode_opts, arena_tmp, &size1);
char* data2 = upb_Encode(m2, layout, encode_opts, arena_tmp, &size2);
if (status1 == kUpb_EncodeStatus_Ok && status2 == kUpb_EncodeStatus_Ok) {
if (data1 && data2) {
bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
upb_Arena_Free(arena_tmp);
return ret;
@@ -741,16 +735,15 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
uint64_t seed) {
upb_Arena* arena = upb_Arena_New();
char* data;
const char* data;
size_t size;
// Hash a deterministically serialized payloads with no unknown fields.
upb_EncodeStatus status = upb_Encode(
msg, upb_MessageDef_MiniTable(m),
kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic, arena,
&data, &size);
data = upb_Encode(msg, upb_MessageDef_MiniTable(m),
kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic, arena,
&size);
if (status == kUpb_EncodeStatus_Ok) {
if (data) {
uint64_t ret = _upb_Hash(data, size, seed);
upb_Arena_Free(arena);
return ret;
@@ -976,8 +969,7 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
rb_raise(rb_eArgError, "Expected hash arguments.");
}
VALUE depth =
rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
@@ -991,10 +983,9 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
VALUE msg_rb = initialize_rb_class_with_no_args(klass);
Message* msg = ruby_to_Message(msg_rb);
upb_DecodeStatus status =
upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
upb_MessageDef_MiniTable(msg->msgdef), NULL, options,
Arena_get(msg->arena));
upb_DecodeStatus status = upb_Decode(
RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
upb_MessageDef_MiniTable(msg->msgdef), NULL, options, Arena_get(msg->arena));
if (status != kUpb_DecodeStatus_Ok) {
rb_raise(cParseError, "Error occurred during parsing");
@@ -1078,7 +1069,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
Message* msg = ruby_to_Message(argv[0]);
int options = 0;
char* data;
const char* data;
size_t size;
if (CLASS_OF(argv[0]) != klass) {
@@ -1094,21 +1085,19 @@ static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
if (TYPE(hash_args) != T_HASH) {
rb_raise(rb_eArgError, "Expected hash arguments.");
}
VALUE depth =
rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
}
}
upb_Arena* arena = upb_Arena_New();
upb_Arena *arena = upb_Arena_New();
upb_EncodeStatus status =
upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), options,
arena, &data, &size);
data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef),
options, arena, &size);
if (status == kUpb_EncodeStatus_Ok) {
if (data) {
VALUE ret = rb_str_new(data, size);
rb_enc_associate(ret, rb_ascii8bit_encoding());
upb_Arena_Free(arena);
@@ -1146,8 +1135,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
if (argc == 2) {
VALUE hash_args = argv[1];
if (TYPE(hash_args) != T_HASH) {
if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1,
rb_str_new2("to_h")))) {
if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1, rb_str_new2("to_h")))) {
hash_args = rb_funcall(hash_args, rb_intern("to_h"), 0);
} else {
rb_raise(rb_eArgError, "Expected hash arguments.");
@@ -1213,8 +1201,36 @@ VALUE build_class_from_descriptor(VALUE descriptor) {
klass = rb_define_class_id(
// Docs say this parameter is ignored. User will assign return value to
// their own toplevel constant class name.
rb_intern("Message"), cAbstractMessage);
rb_intern("Message"), rb_cObject);
rb_ivar_set(klass, descriptor_instancevar_interned, descriptor);
rb_define_alloc_func(klass, Message_alloc);
rb_require("google/protobuf/message_exts");
rb_include_module(klass, rb_eval_string("::Google::Protobuf::MessageExts"));
rb_extend_object(
klass, rb_eval_string("::Google::Protobuf::MessageExts::ClassMethods"));
rb_define_method(klass, "method_missing", Message_method_missing, -1);
rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing,
-1);
rb_define_method(klass, "initialize", Message_initialize, -1);
rb_define_method(klass, "dup", Message_dup, 0);
// Also define #clone so that we don't inherit Object#clone.
rb_define_method(klass, "clone", Message_dup, 0);
rb_define_method(klass, "==", Message_eq, 1);
rb_define_method(klass, "eql?", Message_eq, 1);
rb_define_method(klass, "freeze", Message_freeze, 0);
rb_define_method(klass, "hash", Message_hash, 0);
rb_define_method(klass, "to_h", Message_to_h, 0);
rb_define_method(klass, "inspect", Message_inspect, 0);
rb_define_method(klass, "to_s", Message_inspect, 0);
rb_define_method(klass, "[]", Message_index, 1);
rb_define_method(klass, "[]=", Message_index_set, 2);
rb_define_singleton_method(klass, "decode", Message_decode, -1);
rb_define_singleton_method(klass, "encode", Message_encode, -1);
rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);
return klass;
}
@@ -1274,7 +1290,9 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
int n = upb_EnumDef_ValueCount(e);
for (int i = 0; i < n; i++) {
const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i);
char* name = strdup(upb_EnumValueDef_Name(ev));
upb_Arena* arena = upb_Arena_New();
const char* src_name = upb_EnumValueDef_Name(ev);
char* name = upb_strdup2(src_name, strlen(src_name), arena);
int32_t value = upb_EnumValueDef_Number(ev);
if (name[0] < 'A' || name[0] > 'Z') {
if (name[0] >= 'a' && name[0] <= 'z') {
@@ -1287,7 +1305,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
}
}
rb_define_const(mod, name, INT2NUM(value));
free(name);
upb_Arena_Free(arena);
}
rb_define_singleton_method(mod, "lookup", enum_lookup, 1);
@@ -1306,13 +1324,11 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
size_t size;
char* data = upb_Encode(msg, layout, 0, tmp_arena, &size);
upb_Message* new_msg = upb_Message_New(m, arena);
char* data;
if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
kUpb_EncodeStatus_Ok ||
upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
if (!data || upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
upb_Arena_Free(tmp_arena);
rb_raise(cParseError, "Error occurred copying proto");
}
@@ -1383,42 +1399,11 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
return self->msg;
}
static void Message_define_class(VALUE klass) {
rb_define_alloc_func(klass, Message_alloc);
rb_require("google/protobuf/message_exts");
rb_define_method(klass, "method_missing", Message_method_missing, -1);
rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing,
-1);
rb_define_method(klass, "initialize", Message_initialize, -1);
rb_define_method(klass, "dup", Message_dup, 0);
// Also define #clone so that we don't inherit Object#clone.
rb_define_method(klass, "clone", Message_dup, 0);
rb_define_method(klass, "==", Message_eq, 1);
rb_define_method(klass, "eql?", Message_eq, 1);
rb_define_method(klass, "freeze", Message_freeze, 0);
rb_define_method(klass, "hash", Message_hash, 0);
rb_define_method(klass, "to_h", Message_to_h, 0);
rb_define_method(klass, "inspect", Message_inspect, 0);
rb_define_method(klass, "to_s", Message_inspect, 0);
rb_define_method(klass, "[]", Message_index, 1);
rb_define_method(klass, "[]=", Message_index_set, 2);
rb_define_singleton_method(klass, "decode", Message_decode, -1);
rb_define_singleton_method(klass, "encode", Message_encode, -1);
rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);
}
void Message_register(VALUE protobuf) {
cParseError = rb_const_get(protobuf, rb_intern("ParseError"));
cAbstractMessage =
rb_define_class_under(protobuf, "AbstractMessage", rb_cObject);
Message_define_class(cAbstractMessage);
rb_gc_register_address(&cAbstractMessage);
// Ruby-interned string: "descriptor". We use this identifier to store an
// instance variable on message classes we create in order to link them back
// to their descriptors.
descriptor_instancevar_interned = rb_intern("@descriptor");
descriptor_instancevar_interned = rb_intern("descriptor");
}

11324
libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "google-protobuf"
s.version = "3.21.8"
s.version = "3.21.12"
git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag
s.licenses = ["BSD-3-Clause"]
s.summary = "Protocol Buffers"

View File

@@ -1,35 +0,0 @@
def internal_ruby_extension(
name,
extension,
deps = [],
**kwargs):
"""Bazel rule to wrap up a generated ruby extension.
NOTE: the rule is only an internal workaround. The interface may change and
the rule may be removed when everything is properly "Bazelified".
Args:
name: the name of the target.
extension: the path of the extension file.
deps: extra dependencies to add.
**kwargs: extra arguments to forward to the genrule.
"""
native.genrule(
name = name,
srcs = deps + [
"Rakefile",
":srcs",
":test_ruby_protos",
":tests",
"@utf8_range//:utf8_range_srcs",
],
tags = ["manual"],
outs = [extension],
cmd = "pushd `dirname $(location Rakefile)`\n" +
"BAZEL=true rake\n" +
"popd\n" +
"cp `dirname $(location Rakefile)`/%s $(OUTS)\n" % extension,
**kwargs,
)

View File

@@ -49,10 +49,5 @@ module Google
end
end
class AbstractMessage
include MessageExts
extend MessageExts::ClassMethods
end
private_constant :AbstractMessage
end
end

View File

@@ -9,7 +9,7 @@
<groupId>com.google.protobuf.jruby</groupId>
<artifactId>protobuf-jruby</artifactId>
<version>3.21.8</version>
<version>3.21.12</version>
<name>Protocol Buffer JRuby native extension</name>
<description>
Protocol Buffers are a way of encoding structured data in an efficient yet
@@ -76,7 +76,7 @@
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.21.8</version>
<version>3.21.12</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>

View File

@@ -1,33 +0,0 @@
#!/usr/bin/ruby
# Test that Kokoro is using the expected version of ruby.
require 'test/unit'
class RubyVersionTest < Test::Unit::TestCase
def test_ruby_version
return if RUBY_PLATFORM == "java"
if not ENV["KOKORO_RUBY_VERSION"]
STDERR.puts("No kokoro ruby version found, skipping check")
return
end
actual = RUBY_VERSION
expected = ENV["KOKORO_RUBY_VERSION"].delete_prefix("ruby-")
assert actual.start_with?(expected), "Version #{actual} found, expecting #{expected}"
end
def test_jruby_version
return if RUBY_PLATFORM != "java"
if not ENV["KOKORO_RUBY_VERSION"]
STDERR.puts("No kokoro ruby version found, skipping check")
return
end
expected = ENV["KOKORO_RUBY_VERSION"].delete_prefix("jruby-")
actual = JRUBY_VERSION
assert actual.start_with?(expected), "Version #{actual} found, expecting #{expected}"
end
end

View File

@@ -5,12 +5,8 @@ set -ex
test_version() {
version=$1
bazel_args="\
$(../kokoro/common/bazel_flags.sh) \
--action_env=PATH \
--action_env=GEM_PATH \
--action_env=GEM_HOME \
--test_env=KOKORO_RUBY_VERSION=$version"
RUBY_CONFORMANCE=test_ruby
if [[ $version == jruby-9* ]] ; then
bash --login -c \
@@ -18,14 +14,21 @@ test_version() {
which ruby && \
git clean -f && \
gem install --no-document bundler && bundle && \
bazel test //ruby/... $bazel_args --define=ruby_platform=java"
rake test && \
rake gc_test && \
cd ../conformance && make test_jruby && \
cd ../ruby/compatibility_tests/v3.0.0 && ./test.sh"
else
bash --login -c \
"rvm install $version && rvm use $version && \
which ruby && \
git clean -f && \
gem install --no-document bundler -v 1.17.3 && bundle && \
bazel test //ruby/... $bazel_args --define=ruby_platform=c"
rake test && \
rake gc_test && \
cd ../conformance && make ${RUBY_CONFORMANCE} && \
cd ../ruby/compatibility_tests/v3.0.0 && \
cp -R ../../lib lib && ./test.sh"
fi
}