Browse Source

Add macro WITH_GMOCK()
b82821a13a9efe8887d6166de64a0dc6c03bf2fe

dimdim11 10 months ago
parent
commit
e5d4b7bde2
1 changed files with 26 additions and 10 deletions
  1. 26 10
      build/conf/proto.conf

+ 26 - 10
build/conf/proto.conf

@@ -219,13 +219,13 @@ HAS_CPP_PROTOBUF_PEERS=no
 CPP_PROTOBUF_PEERS=
 
 # tag:proto tag:cpp-specific
-### @usage: CPP_PROTO_PLUGIN0(Name Tool DEPS <Dependencies>)
+### @usage: CPP_PROTO_PLUGIN0(Name Tool [DEPS <Dependencies>] [EXTRA_OUT_FLAG <ExtraOutFlag>])
 ###
 ### Define protoc plugin for C++ with given Name that emits code into regular outputs
 ### using Tool. Extra dependencies are passed via DEPS.
-macro CPP_PROTO_PLUGIN0(NAME, TOOL, DEPS[]) {
+macro CPP_PROTO_PLUGIN0(NAME, TOOL, DEPS[], EXTRA_OUT_FLAG="") {
     .SEM=target_proto_plugin $NAME ${tool;rootrel:TOOL} ${output;hide;suf=.fake.o:NAME}
-    SET_APPEND(CPP_PROTO_OPTS $_PROTO_PLUGIN_ARGS_BASE($NAME $TOOL))
+    SET_APPEND(CPP_PROTO_OPTS $_PROTO_PLUGIN_ARGS_BASE($NAME $TOOL $EXTRA_OUT_FLAG))
 
     # XXX fix variable expansion in plugins
     ENABLE(HAS_CPP_PROTOBUF_PEERS)
@@ -233,23 +233,23 @@ macro CPP_PROTO_PLUGIN0(NAME, TOOL, DEPS[]) {
 }
 
 # tag:proto tag:cpp-specific
-### @usage: CPP_PROTO_PLUGIN(Name Tool Suf DEPS <Dependencies>)
+### @usage: CPP_PROTO_PLUGIN(Name Tool Suf [DEPS <Dependencies>] [EXTRA_OUT_FLAG <ExtraOutFlag>])
 ###
 ### Define protoc plugin for C++ with given Name that emits code into 1 extra output
 ### using Tool. Extra dependencies are passed via DEPS.
-macro CPP_PROTO_PLUGIN(NAME, TOOL, SUF, DEPS[]) {
-    CPP_PROTO_PLUGIN0($NAME $TOOL DEPS $DEPS)
+macro CPP_PROTO_PLUGIN(NAME, TOOL, SUF, DEPS[], EXTRA_OUT_FLAG="") {
+    CPP_PROTO_PLUGIN0($NAME $TOOL DEPS $DEPS ${pre=EXTRA_OUT_FLAG :EXTRA_OUT_FLAG})
 
     _ADD_CPP_PROTO_OUT($SUF)
 }
 
 # tag:proto tag:cpp-specific
-### @usage: CPP_PROTO_PLUGIN2(Name Tool Suf1 Suf2 DEPS <Dependencies>)
+### @usage: CPP_PROTO_PLUGIN2(Name Tool Suf1 Suf2 [DEPS <Dependencies>] [EXTRA_OUT_FLAG <ExtraOutFlag>])
 ###
 ### Define protoc plugin for C++ with given Name that emits code into 2 extra outputs
 ### using Tool. Extra dependencies are passed via DEPS.
-macro CPP_PROTO_PLUGIN2(NAME, TOOL, SUF1, SUF2, DEPS[]) {
-    CPP_PROTO_PLUGIN($NAME $TOOL $SUF1 DEPS $DEPS)
+macro CPP_PROTO_PLUGIN2(NAME, TOOL, SUF1, SUF2, DEPS[], EXTRA_OUT_FLAG="") {
+    CPP_PROTO_PLUGIN($NAME $TOOL $SUF1 DEPS $DEPS ${pre=EXTRA_OUT_FLAG :EXTRA_OUT_FLAG})
 
     _ADD_CPP_PROTO_OUT($SUF2)
     SET_APPEND(CPP_PROTO_OUTS_SEM \${output;hide;norel;nopath;noext;suf=$SUF2:File})
@@ -535,6 +535,8 @@ macro _JAVA_EVLOG_CMD(File) {
 
 # tag:proto tag:grpc
 _GRPC_ENABLED=no
+_GRPC_SUF_CC=.grpc.pb.cc
+_GRPC_SUF_H=.grpc.pb.h
 
 # tag:proto tag:grpc
 ### @usage: GRPC()
@@ -545,7 +547,7 @@ macro GRPC() {
     ENABLE(_GRPC_ENABLED)
 
     # C++
-    CPP_PROTO_PLUGIN2(grpc_cpp contrib/tools/protoc/plugins/grpc_cpp .grpc.pb.cc .grpc.pb.h DEPS contrib/libs/grpc)
+    CPP_PROTO_PLUGIN2(grpc_cpp contrib/tools/protoc/plugins/grpc_cpp $_GRPC_SUF_CC $_GRPC_SUF_H DEPS contrib/libs/grpc $_GRPC_GMOCK_OUTFLAG)
 
     # Python
     PY_PROTO_PLUGIN(grpc_py _pb2_grpc.py contrib/tools/protoc/plugins/grpc_python DEPS contrib/python/grpcio)
@@ -555,6 +557,20 @@ macro GRPC() {
     SET_APPEND(JAVA_PROTOBUF_PEERS contrib/java/javax/annotation/javax.annotation-api/1.3.1)
 }
 
+# tag:proto tag:grpc
+_GRPC_GMOCK_OUTFLAG=
+
+# tag:proto tag:grpc
+### @usage: WITH_GMOCK()
+###
+### Enable generating *_mock.grpc.pb.cc/h files
+macro GRPC_WITH_GMOCK() {
+    SET(_GRPC_GMOCK_OUTFLAG EXTRA_OUT_FLAG generate_mock_code=true)
+    GRPC()
+    _ADD_CPP_PROTO_OUT(_mock$_GRPC_SUF_H)
+    SET_APPEND(CPP_PROTO_OUTS_SEM ${output;hide;norel;nopath;noext;suf=_mock$_GRPC_SUF_H:File})
+}
+
 macro GO_PROTO_USE_V2() {
     ENABLE(GO_PROTO_V2)
 }