From 377871f10403c7b4e1cc6f769b9443b5197aecc8 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 16 Dec 2018 14:32:14 -0800 Subject: Got test_decoder working! --- build_defs.bzl | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'build_defs.bzl') diff --git a/build_defs.bzl b/build_defs.bzl index 8251014..3867976 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -217,7 +217,7 @@ def _remove_up(string): return _remove_suffix(string, ".proto") -def _upb_proto_library_srcs_impl(ctx): +def _upb_proto_srcs_impl(ctx, suffix): sources = [] outs = [] include_dirs = {} @@ -225,14 +225,19 @@ def _upb_proto_library_srcs_impl(ctx): if hasattr(dep, 'proto'): for src in dep.proto.transitive_sources: sources.append(src) - include_dirs[_remove_suffix(src.path, _remove_up(src.short_path) + "." + src.extension)] = True - outs.append(ctx.actions.declare_file(_remove_up(src.short_path) + ".upb.h")) - outs.append(ctx.actions.declare_file(_remove_up(src.short_path) + ".upb.c")) - outdir = _remove_suffix(outs[-1].path, _remove_up(src.short_path) + ".upb.c") + include_dir = _remove_suffix(src.path, _remove_up(src.short_path) + "." + src.extension) + if include_dir: + include_dirs[include_dir] = True + outs.append(ctx.actions.declare_file(_remove_up(src.short_path) + suffix + ".h")) + outs.append(ctx.actions.declare_file(_remove_up(src.short_path) + suffix + ".c")) + outdir = _remove_suffix(outs[-1].path, _remove_up(src.short_path) + suffix + ".c") source_paths = [d.path for d in sources] include_args = ["-I" + root for root in include_dirs.keys()] + print(source_paths) + print(include_args) + ctx.actions.run( inputs = [ctx.executable.upbc] + sources, outputs = outs, @@ -243,6 +248,12 @@ def _upb_proto_library_srcs_impl(ctx): return [DefaultInfo(files = depset(outs))] +def _upb_proto_library_srcs_impl(ctx): + return _upb_proto_srcs_impl(ctx, ".upb") + +def _upb_proto_reflection_library_srcs_impl(ctx): + return _upb_proto_srcs_impl(ctx, ".upbdefs") + _upb_proto_library_srcs = rule( implementation = _upb_proto_library_srcs_impl, attrs = { @@ -272,3 +283,33 @@ def upb_proto_library(name, deps, upbc): deps = [":upb"], copts = ["-Ibazel-out/k8-fastbuild/bin"], ) + +_upb_proto_reflection_library_srcs = rule( + implementation = _upb_proto_reflection_library_srcs_impl, + attrs = { + "upbc": attr.label( + executable = True, + cfg = "host", + ), + "protoc": attr.label( + executable = True, + cfg = "host", + default = "@com_google_protobuf//:protoc", + ), + "deps": attr.label_list(), + } +) + +def upb_proto_reflection_library(name, deps, upbc): + srcs_rule = name + "_defsrcs.cc" + _upb_proto_reflection_library_srcs( + name = srcs_rule, + upbc = upbc, + deps = deps, + ) + native.cc_library( + name = name, + srcs = [":" + srcs_rule], + deps = [":upb"], + copts = ["-Ibazel-out/k8-fastbuild/bin"], + ) -- cgit v1.2.3 From 9dd2446531827a9848983a2dbe3bfb612ed7047e Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Mon, 17 Dec 2018 10:07:00 -0800 Subject: test_cpp is working! --- BUILD | 44 ++---- build_defs.bzl | 3 - tests/test_cpp.cc | 414 +++++------------------------------------------------- upb/def.c | 8 +- 4 files changed, 57 insertions(+), 412 deletions(-) (limited to 'build_defs.bzl') diff --git a/BUILD b/BUILD index 0f4231a..bf988f9 100644 --- a/BUILD +++ b/BUILD @@ -209,10 +209,24 @@ cc_test( ], ) +proto_library( + name = "test_cpp_proto", + srcs = [ + "tests/test_cpp.proto" + ] +) + +upb_proto_reflection_library( + name = "test_cpp_upbproto", + deps = ["test_cpp_proto"], + upbc = ":protoc-gen-upb", +) + cc_test( name = "test_cpp", srcs = ["tests/test_cpp.cc"], deps = [ + ":test_cpp_upbproto", ":upb", ":upb_pb", ":upb_test", @@ -331,17 +345,6 @@ lua_library( strip_prefix = "upb/bindings/lua", ) -lua_library( - name = "lua/upbc_lib", - srcs = [ - "tools/dump_cinit.lua", - ], - luadeps = [ - "lua/upb", - ], - strip_prefix = "tools", -) - # Lua tests. ################################################################### lua_test( @@ -358,14 +361,6 @@ lua_test( # upb compiler ################################################################# -lua_binary( - name = "lua_upbc", - luadeps = [ - "lua/upbc_lib", - ], - luamain = "tools/upbc.lua", -) - cc_library( name = "upbc_generator", hdrs = ["upbc/generator.h"], @@ -491,17 +486,6 @@ genrule( cmd = "cp $< $@", ) -#genrule( -# name = "generated_json_test_proto_upbdefs", -# srcs = ["generated/tests/json/test.proto.pb"], -# outs = [ -# "generated/tests/json/test.upbdefs.h", -# "generated/tests/json/test.upbdefs.c", -# ], -# cmd = "UPBC=$$PWD/$(location :lua_upbc); INFILE=$$PWD/$<; cd $(GENDIR)/generated && $$UPBC --generate-upbdefs $$INFILE", -# tools = [":lua_upbc"], -#) - genrule( name = "generate_json_ragel", srcs = ["upb/json/parser.rl"], diff --git a/build_defs.bzl b/build_defs.bzl index 3867976..717a0e7 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -235,9 +235,6 @@ def _upb_proto_srcs_impl(ctx, suffix): source_paths = [d.path for d in sources] include_args = ["-I" + root for root in include_dirs.keys()] - print(source_paths) - print(include_args) - ctx.actions.run( inputs = [ctx.executable.upbc] + sources, outputs = outs, diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index 2cd9802..b6d8212 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -11,13 +11,12 @@ #include #include +#include "tests/test_cpp.upbdefs.h" #include "upb/def.h" -#include "upb/descriptor/reader.h" #include "upb/handlers.h" #include "upb/pb/decoder.h" -#include "upb/pb/glue.h" -#include "upb_test.h" #include "upb/upb.h" +#include "upb_test.h" template void AssertInsert(T* const container, const typename T::value_type& val) { @@ -25,182 +24,6 @@ void AssertInsert(T* const container, const typename T::value_type& val) { ASSERT(inserted); } -static void TestCastsUpDown() { - upb::reffed_ptr reffed_md(upb::MessageDef::New()); - const upb::MessageDef* md = reffed_md.get(); - - // Upcast to reffed_ptr implicitly. - upb::reffed_ptr reffed_def = reffed_md; - ASSERT(reffed_def.get() == upb::upcast(reffed_md.get())); - - // Upcast to raw pointer must be explicit. - const upb::Def* def = upb::upcast(md); - ASSERT(def == reffed_def.get()); - const upb::Def* def2 = upb::upcast(reffed_md.get()); - ASSERT(def2 == reffed_def.get()); - - // Downcast/dyncast of raw pointer uses upb::down_cast/upb::dyn_cast. - const upb::MessageDef* md2 = upb::down_cast(def); - const upb::MessageDef* md3 = upb::dyn_cast(def); - ASSERT(md == md2); - ASSERT(md == md3); - - // Downcast/dyncast of reffed_ptr uses down_cast/dyn_cast members. - upb::reffed_ptr md4( - reffed_def.down_cast()); - upb::reffed_ptr md5( - reffed_def.dyn_cast()); - ASSERT(md == md4.get()); - ASSERT(md == md5.get()); - - // Failed dyncast returns NULL. - ASSERT(upb::dyn_cast(def) == NULL); - ASSERT(reffed_def.dyn_cast().get() == NULL); -} - -static void TestCastsConst0() { - // Should clean up properly even if it is not assigned to anything. - upb::MessageDef::New(); -} - -static void TestCastsConst1() { - // Test reffed mutable -> reffed mutable construction/assignment. - upb::reffed_ptr md(upb::MessageDef::New()); - upb::MessageDef *md2 = md.get(); - md = upb::MessageDef::New(); - ASSERT(md.get()); - ASSERT(md.get() != md2); -} - -static void TestCastsConst2() { - // Test reffed mutable -> reffed mutable upcast construction/assignment. - upb::reffed_ptr md(upb::MessageDef::New()); - upb::reffed_ptr def = md; - ASSERT(upb::upcast(md.get()) == def.get()); - def = md; - ASSERT(upb::upcast(md.get()) == def.get()); -} - -static void TestCastsConst3() { - // Test reffed mutable -> reffed mutable downcast. - upb::reffed_ptr def(upb::MessageDef::New()); - upb::reffed_ptr md = def.down_cast(); - ASSERT(upb::upcast(md.get()) == def.get()); -} - -static void TestCastsConst4() { - // Test reffed mutable -> reffed mutable dyncast. - upb::reffed_ptr def(upb::MessageDef::New()); - upb::reffed_ptr md = def.dyn_cast(); - ASSERT(upb::upcast(md.get()) == def.get()); -} - -static void TestCastsConst5() { - // Test reffed mutable -> reffed const construction/assignment. - upb::reffed_ptr md(upb::MessageDef::New()); - const upb::MessageDef *md2 = md.get(); - md = upb::MessageDef::New(); - ASSERT(md.get()); - ASSERT(md.get() != md2); -} - -static void TestCastsConst6() { - // Test reffed mutable -> reffed const upcast construction/assignment. - upb::reffed_ptr md(upb::MessageDef::New()); - upb::reffed_ptr def = md; - ASSERT(upb::upcast(md.get()) == def.get()); - def = md; - ASSERT(upb::upcast(md.get()) == def.get()); -} - -static void TestCastsConst7() { - // Test reffed mutable -> reffed const downcast. - upb::reffed_ptr def(upb::MessageDef::New()); - upb::reffed_ptr md = - def.down_cast(); - ASSERT(upb::upcast(md.get()) == def.get()); -} - -static void TestCastsConst8() { - // Test reffed mutable -> reffed const dyncast. - upb::reffed_ptr def(upb::MessageDef::New()); - upb::reffed_ptr md = - def.dyn_cast(); - ASSERT(upb::upcast(md.get()) == def.get()); -} - -static void TestCastsConst9() { - // Test plain mutable -> plain mutable upcast - upb::reffed_ptr md(upb::MessageDef::New()); - upb::Def* def = upb::upcast(md.get()); - ASSERT(upb::down_cast(def) == md.get()); -} - -static void TestCastsConst10() { - // Test plain const -> plain const upcast - upb::reffed_ptr md(upb::MessageDef::New()); - const upb::Def* def = upb::upcast(md.get()); - ASSERT(upb::down_cast(def) == md.get()); -} - -static void TestSymbolTable(const char *descriptor_file) { - upb::Status status; - std::ifstream file_in(descriptor_file, std::ios::binary); - std::string descriptor((std::istreambuf_iterator(file_in)), - (std::istreambuf_iterator())); - std::vector > files; - if (!upb::LoadDescriptor(descriptor, &status, &files)) { - std::cerr << "Couldn't load descriptor: " << status.error_message(); - exit(1); - } - - upb::SymbolTable* s = upb::SymbolTable::New(); - - for (size_t i = 0; i < files.size(); i++) { - ASSERT(s->AddFile(files[i].get(), &status)); - } - - upb::reffed_ptr md(s->LookupMessage("C")); - ASSERT(md.get()); - - // We want a def that satisfies this to test iteration. - ASSERT(md->field_count() > 1); - -#ifdef UPB_CXX11 - // Test range-based for. - std::set fielddefs; - for (const upb::FieldDef* f : md.get()->fields()) { - AssertInsert(&fielddefs, f); - ASSERT(f->containing_type() == md.get()); - } - ASSERT(fielddefs.size() == md->field_count()); -#endif - - ASSERT(md.get()); - upb::SymbolTable::Free(s); -} - -static void TestCasts1() { - upb::reffed_ptr md(upb::MessageDef::New()); - const upb::Def* def = upb::upcast(md.get()); - const upb::MessageDef* md2 = upb::down_cast(def); - const upb::MessageDef* md3 = upb::dyn_cast(def); - - ASSERT(md.get() == md2); - ASSERT(md.get() == md3); - - const upb::EnumDef* ed = upb::dyn_cast(def); - ASSERT(!ed); -} - -static void TestCasts2() { - // Test mutable -> const cast. - upb::reffed_ptr md(upb::MessageDef::New()); - upb::Def* def = upb::upcast(md.get()); - const upb::MessageDef* const_md = upb::down_cast(def); - ASSERT(const_md == md.get()); -} - // // Tests for registering and calling handlers in all their variants. // This test code is very repetitive because we have to declare each @@ -225,7 +48,7 @@ static const int kExpectedHandlerData = 1232323; class StringBufTesterBase { public: - static const upb::FieldDef::Type kFieldType = UPB_TYPE_STRING; + static const int kFieldNumber = 3; StringBufTesterBase() : seen_(false), handler_data_val_(0) {} @@ -461,7 +284,7 @@ class StartMsgTesterBase { public: // We don't need the FieldDef it will create, but the test harness still // requires that we provide one. - static const upb::FieldDef::Type kFieldType = UPB_TYPE_STRING; + static const int kFieldNumber = 3; StartMsgTesterBase() : seen_(false), handler_data_val_(0) {} @@ -612,7 +435,7 @@ class StartMsgTesterBoolMethodWithHandlerData : public StartMsgTesterBase { class Int32ValueTesterBase { public: - static const upb::FieldDef::Type kFieldType = UPB_TYPE_INT32; + static const int kFieldNumber = 1; Int32ValueTesterBase() : seen_(false), val_(0), handler_data_val_(0) {} @@ -770,21 +593,20 @@ class ValueTesterInt32BoolMethodWithHandlerData : public Int32ValueTesterBase { template void TestHandler() { - upb::reffed_ptr md(upb::MessageDef::New()); - upb::reffed_ptr f(upb::FieldDef::New()); - f->set_type(T::kFieldType); - ASSERT(f->set_name("test", NULL)); - ASSERT(f->set_number(1, NULL)); - ASSERT(md->AddField(f, NULL)); - ASSERT(md->Freeze(NULL)); - - upb::reffed_ptr h(upb::Handlers::New(md.get())); + upb::SymbolTable* symtab = upb::SymbolTable::New(); + const upb::MessageDef* md = upb_test_TestMessage_getmsgdef(symtab); + ASSERT(md); + const upb::FieldDef* f = md->FindFieldByNumber(T::kFieldNumber); + ASSERT(f); + + upb::reffed_ptr h(upb::Handlers::New(md)); T tester; - tester.Register(h.get(), f.get()); + tester.Register(h.get(), f); ASSERT(h->Freeze(NULL)); upb::Sink sink(h.get(), &tester); - tester.CallAndVerify(&sink, f.get()); + tester.CallAndVerify(&sink, f); + upb::SymbolTable::Free(symtab); } class T1 {}; @@ -850,59 +672,24 @@ void DoNothingEndMessageHandler(C* closure, upb::Status *status) { void TestMismatchedTypes() { // First create a schema for our test. - upb::reffed_ptr md(upb::MessageDef::New()); - - upb::reffed_ptr f(upb::FieldDef::New()); - f->set_type(UPB_TYPE_INT32); - ASSERT(f->set_name("i32", NULL)); - ASSERT(f->set_number(1, NULL)); - ASSERT(md->AddField(f, NULL)); - const upb::FieldDef* i32 = f.get(); - - f = upb::FieldDef::New(); - f->set_type(UPB_TYPE_INT32); - ASSERT(f->set_name("r_i32", NULL)); - ASSERT(f->set_number(2, NULL)); - f->set_label(UPB_LABEL_REPEATED); - ASSERT(md->AddField(f, NULL)); - const upb::FieldDef* r_i32 = f.get(); - - f = upb::FieldDef::New(); - f->set_type(UPB_TYPE_STRING); - ASSERT(f->set_name("str", NULL)); - ASSERT(f->set_number(3, NULL)); - ASSERT(md->AddField(f, NULL)); - const upb::FieldDef* str = f.get(); - - f = upb::FieldDef::New(); - f->set_type(UPB_TYPE_STRING); - ASSERT(f->set_name("r_str", NULL)); - ASSERT(f->set_number(4, NULL)); - f->set_label(UPB_LABEL_REPEATED); - ASSERT(md->AddField(f, NULL)); - const upb::FieldDef* r_str = f.get(); - - f = upb::FieldDef::New(); - f->set_type(UPB_TYPE_MESSAGE); - ASSERT(f->set_name("msg", NULL)); - ASSERT(f->set_number(5, NULL)); - ASSERT(f->set_message_subdef(md.get(), NULL)); - ASSERT(md->AddField(f, NULL)); - const upb::FieldDef* msg = f.get(); - - f = upb::FieldDef::New(); - f->set_type(UPB_TYPE_MESSAGE); - ASSERT(f->set_name("r_msg", NULL)); - ASSERT(f->set_number(6, NULL)); - ASSERT(f->set_message_subdef(md.get(), NULL)); - f->set_label(UPB_LABEL_REPEATED); - ASSERT(md->AddField(f, NULL)); - const upb::FieldDef* r_msg = f.get(); - - ASSERT(md->Freeze(NULL)); + upb::SymbolTable* symtab = upb::SymbolTable::New(); + const upb::MessageDef* md = upb_test_TestMessage_getmsgdef(symtab); + ASSERT(md); + const upb::FieldDef* i32 = md->FindFieldByName("i32"); + const upb::FieldDef* r_i32 = md->FindFieldByName("r_i32"); + const upb::FieldDef* str = md->FindFieldByName("str"); + const upb::FieldDef* r_str = md->FindFieldByName("r_str"); + const upb::FieldDef* msg = md->FindFieldByName("msg"); + const upb::FieldDef* r_msg = md->FindFieldByName("r_msg"); + ASSERT(i32); + ASSERT(r_i32); + ASSERT(str); + ASSERT(r_str); + ASSERT(msg); + ASSERT(r_msg); // Now test the type-checking in handler registration. - upb::reffed_ptr h(upb::Handlers::New(md.get())); + upb::reffed_ptr h(upb::Handlers::New(md)); // Establish T1 as the top-level closure type. ASSERT(h->SetInt32Handler(i32, UpbMakeHandler(DoNothingInt32Handler))); @@ -1007,7 +794,7 @@ void TestMismatchedTypes() { // For our second test we do the same in reverse. We directly set the type of // the frame and then observe failures at registering a Start* handler that // returns a different type. - h = upb::Handlers::New(md.get()); + h = upb::Handlers::New(md); // First establish the type of a sequence frame directly. ASSERT(h->SetInt32Handler(r_i32, UpbMakeHandler(DoNothingInt32Handler))); @@ -1040,7 +827,7 @@ void TestMismatchedTypes() { // should exist to return the closure type of the inner frame but no // StartSequence/StartString handler is registered. - h = upb::Handlers::New(md.get()); + h = upb::Handlers::New(md); // Establish T1 as top-level closure type. ASSERT(h->SetInt32Handler(i32, UpbMakeHandler(DoNothingInt32Handler))); @@ -1061,7 +848,7 @@ void TestMismatchedTypes() { ASSERT(h->Freeze(NULL)); // Test for a broken chain that is two deep. - h = upb::Handlers::New(md.get()); + h = upb::Handlers::New(md); // Establish T1 as top-level closure type. ASSERT(h->SetInt32Handler(i32, UpbMakeHandler(DoNothingInt32Handler))); @@ -1104,145 +891,24 @@ class IntIncrementer { void TestHandlerDataDestruction() { - upb::reffed_ptr md(upb::MessageDef::New()); - upb::reffed_ptr f(upb::FieldDef::New()); - f->set_type(UPB_TYPE_INT32); - ASSERT(f->set_name("test", NULL)); - ASSERT(f->set_number(1, NULL)); - ASSERT(md->AddField(f, NULL)); - ASSERT(md->Freeze(NULL)); + upb::SymbolTable* symtab = upb::SymbolTable::New(); + const upb::MessageDef* md = upb_test_TestMessage_getmsgdef(symtab); + const upb::FieldDef* f = md->FindFieldByName("i32"); int x = 0; { - upb::reffed_ptr h(upb::Handlers::New(md.get())); + upb::reffed_ptr h(upb::Handlers::New(md)); h->SetInt32Handler( - f.get(), UpbBind(&IntIncrementer::Handler, new IntIncrementer(&x))); + f, UpbBind(&IntIncrementer::Handler, new IntIncrementer(&x))); ASSERT(x == 1); } ASSERT(x == 0); } -void TestOneofs() { - upb::Status status; - upb::reffed_ptr md(upb::MessageDef::New()); - upb::reffed_ptr o(upb::OneofDef::New()); - - o->set_name("test_oneof", &status); - ASSERT(status.ok()); - - for (int i = 0; i < 5; i++) { - std::ostringstream fieldname; - fieldname << "field_" << i; - upb::reffed_ptr f(upb::FieldDef::New()); - f->set_name(fieldname.str(), &status); - ASSERT(status.ok()); - f->set_type(UPB_TYPE_INT32); - f->set_number(i + 1, &status); - ASSERT(status.ok()); - f->set_label(UPB_LABEL_OPTIONAL); - - o->AddField(f.get(), &status); - ASSERT(status.ok()); - } - - md->AddOneof(o.get(), &status); - ASSERT(status.ok()); - - int field_count = 0; - for (upb::OneofDef::iterator it = o->begin(); it != o->end(); ++it) { - upb::FieldDef* f = *it; - ASSERT(f->type() == UPB_TYPE_INT32); - field_count++; - } - ASSERT(field_count == 5); - - upb::MessageDef::oneof_iterator msg_it = md->oneof_begin(); - ASSERT(msg_it != md->oneof_end()); - ASSERT((*msg_it) == o.get()); - -#ifdef UPB_CXX11 - // Test range-based for on both fields and oneofs (with the iterator adaptor). - field_count = 0; - for (auto* field : md->fields()) { - UPB_UNUSED(field); - field_count++; - } - ASSERT(field_count == 5); - - int oneof_count = 0; - for (auto* oneof : md->oneofs()) { - UPB_UNUSED(oneof); - oneof_count++; - } - ASSERT(oneof_count == 1); -#endif // UPB_CXX11 - - // Test that we can add a new field to the oneof and that it becomes a member - // of the msgdef as well. - upb::reffed_ptr newf(upb::FieldDef::New()); - newf->set_name("new_field_10", &status); - ASSERT(status.ok()); - newf->set_number(10, &status); - ASSERT(status.ok()); - newf->set_label(UPB_LABEL_OPTIONAL); - newf->set_type(UPB_TYPE_INT32); - o->AddField(newf.get(), &status); - ASSERT(status.ok()); - ASSERT(newf->containing_type() == md.get()); - - // Test that we can add a new field to the msgdef first and then to the oneof. - upb::reffed_ptr newf2(upb::FieldDef::New()); - newf2->set_name("new_field_11", &status); - ASSERT(status.ok()); - newf2->set_number(11, &status); - ASSERT(status.ok()); - newf2->set_label(UPB_LABEL_OPTIONAL); - newf2->set_type(UPB_TYPE_INT32); - md->AddField(newf2.get(), &status); - ASSERT(status.ok()); - o->AddField(newf2.get(), &status); - ASSERT(status.ok()); - ASSERT(newf2->containing_oneof() == o.get()); - - // Test that we cannot add REQUIRED or REPEATED fields to the oneof. - upb::reffed_ptr newf3(upb::FieldDef::New()); - newf3->set_name("new_field_12", &status); - ASSERT(status.ok()); - newf3->set_number(12, &status); - ASSERT(status.ok()); - newf3->set_label(UPB_LABEL_REQUIRED); - newf3->set_type(UPB_TYPE_INT32); - o->AddField(newf3.get(), &status); - ASSERT(!status.ok()); - newf->set_label(UPB_LABEL_REPEATED); - o->AddField(newf3.get(), &status); - ASSERT(!status.ok()); -} - extern "C" { int run_tests(int argc, char *argv[]) { - if (argc < 2) { - fprintf(stderr, "Usage: test_cpp \n"); - return 1; - } - TestSymbolTable(argv[1]); - TestCastsUpDown(); - TestCasts1(); - TestCasts2(); - TestCastsConst0(); - TestCastsConst1(); - TestCastsConst2(); - TestCastsConst3(); - TestCastsConst4(); - TestCastsConst5(); - TestCastsConst6(); - TestCastsConst7(); - TestCastsConst8(); - TestCastsConst9(); - TestCastsConst10(); - TestHandler(); TestHandler(); TestHandler(); @@ -1276,8 +942,6 @@ int run_tests(int argc, char *argv[]) { TestHandlerDataDestruction(); - TestOneofs(); - return 0; } diff --git a/upb/def.c b/upb/def.c index c10394e..ccbf407 100644 --- a/upb/def.c +++ b/upb/def.c @@ -921,12 +921,12 @@ static char* strviewdup(const symtab_addctx *ctx, upb_stringview view) { return upb_strdup2(view.data, view.size, ctx->alloc); } -static bool streql(const char *a, size_t n, const char *b) { +static bool streql2(const char *a, size_t n, const char *b) { return n == strlen(b) && memcmp(a, b, n) == 0; } static bool streql_view(upb_stringview view, const char *b) { - return streql(view.data, view.size, b); + return streql2(view.data, view.size, b); } static const char *makefullname(const symtab_addctx *ctx, const char *prefix, @@ -1077,9 +1077,9 @@ static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len, break; } case UPB_TYPE_BOOL: { - if (streql(str, len, "false")) { + if (streql2(str, len, "false")) { f->defaultval.boolean = false; - } else if (streql(str, len, "true")) { + } else if (streql2(str, len, "true")) { f->defaultval.boolean = true; } else { return false; -- cgit v1.2.3 From 7f9f7222bf5ab3ad3720b1afd55370b0e473109f Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 23 Jan 2019 17:10:22 -0800 Subject: Changes for google3 import. --- BUILD | 35 ++++++++++++++++++++--------------- build_defs.bzl | 25 ++++++++++++++----------- tools/make_cmakelists.py | 3 +++ 3 files changed, 37 insertions(+), 26 deletions(-) (limited to 'build_defs.bzl') diff --git a/BUILD b/BUILD index 0a8a684..9593936 100644 --- a/BUILD +++ b/BUILD @@ -1,6 +1,7 @@ load( ":build_defs.bzl", "generated_file_staleness_test", + "licenses", # copybara:strip_for_google3 "lua_binary", "lua_cclibrary", "lua_library", @@ -11,6 +12,21 @@ load( "upb_proto_reflection_library", ) +licenses(["notice"]) # BSD (Google-authored w/ possible external contributions) + +exports_files([ + "LICENSE", + "build_defs", +]) + +COPTS = [ + # copybara:strip_for_google3_begin + "-std=c89", + "-pedantic", + "-Wno-long-long", + # copybara:strip_end +] + # C/C++ rules ################################################################## cc_library( @@ -44,11 +60,7 @@ cc_library( "upb/sink.h", "upb/upb.h", ], - copts = [ - "-std=c89", - "-pedantic", - "-Wno-long-long", - ], + copts = COPTS, visibility = ["//visibility:public"], ) @@ -68,11 +80,7 @@ cc_library( "upb/pb/encoder.h", "upb/pb/textprinter.h", ], - copts = [ - "-std=c89", - "-pedantic", - "-Wno-long-long", - ], + copts = COPTS, deps = [ ":upb", ], @@ -88,11 +96,7 @@ cc_library( "upb/json/parser.h", "upb/json/printer.h", ], - copts = [ - "-std=c89", - "-pedantic", - "-Wno-long-long", - ], + copts = COPTS, deps = [ ":upb", ":upb_pb", @@ -309,6 +313,7 @@ cc_library( name = "amalgamation", srcs = ["upb.c"], hdrs = ["upb.h"], + copts = COPTS, ) # Lua libraries. ############################################################### diff --git a/build_defs.bzl b/build_defs.bzl index da21e86..bb4d6f8 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -1,4 +1,3 @@ - _shell_find_runfiles = """ # --- begin runfiles.bash initialization --- # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). @@ -100,7 +99,7 @@ BASE=$(dirname $(rlocation upb/upb_c.so)) export LUA_CPATH="$BASE/?.so" export LUA_PATH="$BASE/?.lua" $(rlocation lua/lua) $(rlocation upb/tools/upbc.lua) "$@" -""" +""", ) rule( @@ -109,10 +108,10 @@ $(rlocation lua/lua) $(rlocation upb/tools/upbc.lua) "$@" data = ["@lua//:lua", "@bazel_tools//tools/bash/runfiles", luamain] + luadeps, ) -def lua_binary(name, luamain, luadeps=[]): +def lua_binary(name, luamain, luadeps = []): _lua_binary_or_test(name, luamain, luadeps, native.sh_binary) -def lua_test(name, luamain, luadeps=[]): +def lua_test(name, luamain, luadeps = []): _lua_binary_or_test(name, luamain, luadeps, native.sh_test) def generated_file_staleness_test(name, outs, generated_pattern): @@ -163,9 +162,9 @@ def generated_file_staleness_test(name, outs, generated_pattern): SrcList = provider( fields = { - 'srcs' : 'list of srcs', - 'hdrs' : 'list of hdrs', - } + "srcs": "list of srcs", + "hdrs": "list of hdrs", + }, ) def _file_list_aspect_impl(target, ctx): @@ -205,7 +204,7 @@ upb_amalgamation = rule( ), "libs": attr.label_list(aspects = [_file_list_aspect]), "outs": attr.output_list(), - } + }, ) # upb_proto_library() rule @@ -223,7 +222,7 @@ def _upb_proto_srcs_impl(ctx, suffix): outs = [] include_dirs = {} for dep in ctx.attr.deps: - if hasattr(dep, 'proto'): + if hasattr(dep, "proto"): for src in dep.proto.transitive_sources: sources.append(src) include_dir = _remove_suffix(src.path, _remove_up(src.short_path) + "." + src.extension) @@ -265,7 +264,7 @@ _upb_proto_library_srcs = rule( default = "@com_google_protobuf//:protoc", ), "deps": attr.label_list(), - } + }, ) def upb_proto_library(name, deps, upbc): @@ -295,7 +294,7 @@ _upb_proto_reflection_library_srcs = rule( default = "@com_google_protobuf//:protoc", ), "deps": attr.label_list(), - } + }, ) def upb_proto_reflection_library(name, deps, upbc): @@ -311,3 +310,7 @@ def upb_proto_reflection_library(name, deps, upbc): deps = [":upb"], copts = ["-Ibazel-out/k8-fastbuild/bin"], ) + +def licenses(*args): + # No-op (for Google-internal usage). + pass diff --git a/tools/make_cmakelists.py b/tools/make_cmakelists.py index c2700b6..1e1c1ee 100755 --- a/tools/make_cmakelists.py +++ b/tools/make_cmakelists.py @@ -137,6 +137,9 @@ class BuildFileFunctions(object): def glob(*args): return [] + def licenses(*args): + pass + class WorkspaceFileFunctions(object): def __init__(self, converter): -- cgit v1.2.3 From ca5f951137a121e55ca21ee162afd1be596775ba Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 24 Jan 2019 12:19:08 -0800 Subject: More fixes for google3 import. --- BUILD | 17 +++++++++++++---- build_defs.bzl | 19 +++++++++++++++++-- tools/make_cmakelists.py | 7 +++++-- 3 files changed, 35 insertions(+), 8 deletions(-) (limited to 'build_defs.bzl') diff --git a/BUILD b/BUILD index 9593936..1c6cdef 100644 --- a/BUILD +++ b/BUILD @@ -7,6 +7,7 @@ load( "lua_library", "lua_test", "make_shell_script", + "map_dep", "upb_amalgamation", "upb_proto_library", "upb_proto_reflection_library", @@ -122,9 +123,9 @@ cc_library( ], hdrs = ["upbc/generator.h"], deps = [ - "@absl//absl/strings", - "@com_google_protobuf//:protobuf", - "@com_google_protobuf//:protoc_lib", + map_dep("@absl//absl/strings"), + map_dep("@com_google_protobuf//:protobuf"), + map_dep("@com_google_protobuf//:protoc_lib"), ], ) @@ -133,10 +134,16 @@ cc_binary( srcs = ["upbc/main.cc"], deps = [ ":upbc_generator", - "@com_google_protobuf//:protoc_lib", + map_dep("@com_google_protobuf//:protoc_lib"), ], ) + +# We strip the tests and remaining rules from google3 until the upb_proto_library() +# and upb_proto_reflection_library() rules are fixed. + +# copybara:strip_for_google3_begin + # C/C++ tests ################################################################## cc_library( @@ -487,3 +494,5 @@ generated_file_staleness_test( ], generated_pattern = "generated/%s", ) + +# copybara:strip_end diff --git a/build_defs.bzl b/build_defs.bzl index bb4d6f8..1c26a00 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -207,6 +207,21 @@ upb_amalgamation = rule( }, ) +is_bazel = not hasattr(native, "genmpm") + +google3_dep_map = { + "@absl//absl/strings": "//third_party/absl/strings", + "@com_google_protobuf//:protoc": "//third_party/protobuf:protoc", + "@com_google_protobuf//:protobuf": "//third_party/protobuf:protobuf", + "@com_google_protobuf//:protoc_lib": "//third_party/protobuf:libprotoc", +} + +def map_dep(dep): + if is_bazel: + return dep + else: + return google3_dep_map[dep] + # upb_proto_library() rule def _remove_up(string): @@ -261,7 +276,7 @@ _upb_proto_library_srcs = rule( "protoc": attr.label( executable = True, cfg = "host", - default = "@com_google_protobuf//:protoc", + default = map_dep("@com_google_protobuf//:protoc"), ), "deps": attr.label_list(), }, @@ -291,7 +306,7 @@ _upb_proto_reflection_library_srcs = rule( "protoc": attr.label( executable = True, cfg = "host", - default = "@com_google_protobuf//:protoc", + default = map_dep("@com_google_protobuf//:protoc"), ), "deps": attr.label_list(), }, diff --git a/tools/make_cmakelists.py b/tools/make_cmakelists.py index 1e1c1ee..86544cb 100755 --- a/tools/make_cmakelists.py +++ b/tools/make_cmakelists.py @@ -134,12 +134,15 @@ class BuildFileFunctions(object): def select(self, arg_dict): return [] - def glob(*args): + def glob(self, *args): return [] - def licenses(*args): + def licenses(self, *args): pass + def map_dep(self, arg): + return arg + class WorkspaceFileFunctions(object): def __init__(self, converter): -- cgit v1.2.3