From 88c2ac1b4e8ba0f8c3afef96fb567ce1bb18672f Mon Sep 17 00:00:00 2001 From: Kybxd <627940450@qq.com> Date: Tue, 15 Jul 2025 14:30:55 +0800 Subject: [PATCH] feat: do not generate import for not-generated *.pc.h, remove unused variable --- .../embed/load.pc.cc | 1 - cmd/protoc-gen-cpp-tableau-loader/hub.go | 3 +- .../src/protoconf/load.pc.cc | 1 - test/proto/union_conf.proto | 44 +++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/proto/union_conf.proto diff --git a/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc b/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc index 52a44b99..0454b53c 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc +++ b/cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc @@ -63,7 +63,6 @@ bool PatchMessage(google::protobuf::Message& dst, const google::protobuf::Messag // Reference: // https://github.com/protocolbuffers/protobuf/blob/95ef4134d3f65237b7adfb66e5e7aa10fcfa1fa3/src/google/protobuf/map_field.cc#L500 auto key_fd = fd->message_type()->map_key(); - auto value_fd = fd->message_type()->map_value(); int src_count = src_reflection->FieldSize(src, fd); int dst_count = dst_reflection->FieldSize(dst, fd); switch (key_fd->cpp_type()) { diff --git a/cmd/protoc-gen-cpp-tableau-loader/hub.go b/cmd/protoc-gen-cpp-tableau-loader/hub.go index 2efe93e6..00cd1b90 100644 --- a/cmd/protoc-gen-cpp-tableau-loader/hub.go +++ b/cmd/protoc-gen-cpp-tableau-loader/hub.go @@ -6,6 +6,7 @@ import ( "github.com/iancoleman/strcase" "github.com/tableauio/loader/cmd/protoc-gen-cpp-tableau-loader/helper" + "github.com/tableauio/loader/internal/options" "github.com/tableauio/tableau/proto/tableaupb" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/proto" @@ -15,7 +16,7 @@ import ( func getAllOrderedFilesAndMessagers(gen *protogen.Plugin) (protofiles []string, fileMessagers map[string][]string) { fileMessagers = map[string][]string{} for _, f := range gen.Files { - if !f.Generate { + if !options.NeedGenFile(f) { continue } opts := f.Desc.Options().(*descriptorpb.FileOptions) diff --git a/test/cpp-tableau-loader/src/protoconf/load.pc.cc b/test/cpp-tableau-loader/src/protoconf/load.pc.cc index 90e3ee39..1020552f 100644 --- a/test/cpp-tableau-loader/src/protoconf/load.pc.cc +++ b/test/cpp-tableau-loader/src/protoconf/load.pc.cc @@ -68,7 +68,6 @@ bool PatchMessage(google::protobuf::Message& dst, const google::protobuf::Messag // Reference: // https://github.com/protocolbuffers/protobuf/blob/95ef4134d3f65237b7adfb66e5e7aa10fcfa1fa3/src/google/protobuf/map_field.cc#L500 auto key_fd = fd->message_type()->map_key(); - auto value_fd = fd->message_type()->map_value(); int src_count = src_reflection->FieldSize(src, fd); int dst_count = dst_reflection->FieldSize(dst, fd); switch (key_fd->cpp_type()) { diff --git a/test/proto/union_conf.proto b/test/proto/union_conf.proto new file mode 100644 index 00000000..71b7d246 --- /dev/null +++ b/test/proto/union_conf.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; + +package protoconf; + +import "tableau/protobuf/tableau.proto"; + +option go_package = "github.com/tableauio/loader/test/go-tableau-loader/protoconf"; +option (tableau.workbook) = { + name: "Union.xlsx" +}; + +message HeroTarget { + option (tableau.union) = { + name: "UnionType" + note: "HeroTarget note" + }; + + Type type = 9999 [(tableau.field) = { name: "Type" }]; + oneof value { + option (tableau.oneof) = { + note: "HeroTarget note" + field: "Field" + }; + + StarUp star_up = 1; // Bound to enum value: TYPE_STAR_UP. + LevelUp level_up = 2; // Bound to enum value: TYPE_LEVEL_UP. + } + + enum Type { + TYPE_INVALID = 0; + TYPE_STAR_UP = 1 [(tableau.evalue).name = "HeroStarUp"]; // HeroStarUp + TYPE_LEVEL_UP = 2 [(tableau.evalue).name = "HeroLevelUp"]; // HeroLevelUp + } + + message StarUp { + uint32 id = 1 [(tableau.field) = { name: "ID" }]; + int32 star = 2 [(tableau.field) = { name: "Star" }]; + } + message LevelUp { + repeated uint32 id_list = 1 [(tableau.field) = { name: "ID" layout: LAYOUT_INCELL }]; + int32 level = 2 [(tableau.field) = { name: "Level" }]; + bool super = 3 [(tableau.field) = { name: "Super" }]; + } +} \ No newline at end of file