iSulad/0003-Add-macro-for-protoc-cmake.patch
zhangxiaoyu 70385f208a upgrade from upstream
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
2023-02-22 15:28:57 +08:00

136 lines
7.0 KiB
Diff

From 466309bc0aafe61ebed5c71012e28b9912783b60 Mon Sep 17 00:00:00 2001
From: Xuepeng Xu <xuxuepeng1@huawei.com>
Date: Thu, 9 Feb 2023 14:32:59 +0800
Subject: [PATCH 03/22] Add macro for protoc cmake
Signed-off-by: Xuepeng Xu <xuxuepeng1@huawei.com>
---
cmake/protoc.cmake | 98 +++++++++++++---------------------------------
1 file changed, 28 insertions(+), 70 deletions(-)
diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake
index 5c433e5c..23b8c077 100644
--- a/cmake/protoc.cmake
+++ b/cmake/protoc.cmake
@@ -11,89 +11,47 @@ if (ENABLE_NATIVE_NETWORK)
set(NETWORK_PROTOS_OUT_PATH ${GRPC_OUT_PRE_PATH}/src/api/services/network)
endif()
+macro(PROTOC_CPP_GEN proto_name cpp_out_path proto_path)
+ execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/${proto_name} --cpp_out=${cpp_out_path} ${proto_path} ERROR_VARIABLE cpp_err)
+ if (cpp_err)
+ message("Parse ${proto_path} failed: ")
+ message(FATAL_ERROR ${cpp_err})
+ endif()
+endmacro(PROTOC_CPP_GEN)
+
+macro(PROTOC_GRPC_GEN proto_name grpc_out_path proto_path)
+ execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/${proto_name} --grpc_out=${grpc_out_path} --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${proto_path} ERROR_VARIABLE grpc_err)
+ if (grpc_err)
+ message("Parse ${proto_path} failed: ")
+ message(FATAL_ERROR ${grpc_err})
+ endif()
+endmacro(PROTOC_GRPC_GEN)
+
if (GRPC_CONNECTOR)
execute_process(COMMAND mkdir -p ${CONTAINER_PROTOS_OUT_PATH})
execute_process(COMMAND mkdir -p ${IMAGE_PROTOS_OUT_PATH})
execute_process(COMMAND mkdir -p ${VOLUME_PROTOS_OUT_PATH})
execute_process(COMMAND mkdir -p ${CRI_PROTOS_OUT_PATH})
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/containers --cpp_out=${CONTAINER_PROTOS_OUT_PATH}
- ${PROTOS_PATH}/containers/container.proto ERROR_VARIABLE containers_err)
- if (containers_err)
- message("Parse ${PROTOS_PATH}/containers/container.proto failed: ")
- message(FATAL_ERROR ${containers_err})
- endif()
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/containers --grpc_out=${CONTAINER_PROTOS_OUT_PATH} --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/containers/container.proto ERROR_VARIABLE containers_err)
- if (containers_err)
- message("Parse ${PROTOS_PATH}/containers/container.proto plugin failed: ")
- message(FATAL_ERROR ${containers_err})
- endif()
+ PROTOC_CPP_GEN(containers ${CONTAINER_PROTOS_OUT_PATH} ${PROTOS_PATH}/containers/container.proto)
+ PROTOC_GRPC_GEN(containers ${CONTAINER_PROTOS_OUT_PATH} ${PROTOS_PATH}/containers/container.proto)
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/images --cpp_out=${IMAGE_PROTOS_OUT_PATH} ${PROTOS_PATH}/images/images.proto ERROR_VARIABLE images_err)
- if (images_err)
- message("Parse ${PROTOS_PATH}/images/images.proto failed: ")
- message(FATAL_ERROR ${images_err})
- endif()
+ PROTOC_CPP_GEN(images ${IMAGE_PROTOS_OUT_PATH} ${PROTOS_PATH}/images/images.proto)
+ PROTOC_GRPC_GEN(images ${IMAGE_PROTOS_OUT_PATH} ${PROTOS_PATH}/images/images.proto)
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/images --grpc_out=${IMAGE_PROTOS_OUT_PATH} --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/images/images.proto ERROR_VARIABLE images_err)
- if (images_err)
- message("Parse ${PROTOS_PATH}/images/images.proto plugin failed: ")
- message(FATAL_ERROR ${images_err})
- endif()
+ PROTOC_CPP_GEN(volumes ${VOLUME_PROTOS_OUT_PATH} ${PROTOS_PATH}/volumes/volumes.proto)
+ PROTOC_GRPC_GEN(volumes ${VOLUME_PROTOS_OUT_PATH} ${PROTOS_PATH}/volumes/volumes.proto)
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/volumes --cpp_out=${VOLUME_PROTOS_OUT_PATH} ${PROTOS_PATH}/volumes/volumes.proto ERROR_VARIABLE volumes_err)
- if (volumes_err)
- message("Parse ${PROTOS_PATH}/volumes/volumes.proto failed: ")
- message(FATAL_ERROR ${volumes_err})
- endif()
+ PROTOC_CPP_GEN(cri ${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/api.proto)
+ PROTOC_GRPC_GEN(cri ${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/api.proto)
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/volumes --grpc_out=${VOLUME_PROTOS_OUT_PATH} --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/volumes/volumes.proto ERROR_VARIABLE volumes_err)
- if (volumes_err)
- message("Parse ${PROTOS_PATH}/volumes/volumes.proto plugin failed: ")
- message(FATAL_ERROR ${volumes_err})
- endif()
-
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --cpp_out=${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/api.proto
- ERROR_VARIABLE cri_err)
- if (cri_err)
- message("Parse ${PROTOS_PATH}/cri/api.proto failed: ")
- message(FATAL_ERROR ${cri_err})
- endif()
-
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --grpc_out=${CRI_PROTOS_OUT_PATH}
- --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/cri/api.proto ERROR_VARIABLE cri_err)
- if (cri_err)
- message("Parse ${PROTOS_PATH}/cri/api.proto plugin failed: ")
- message(FATAL_ERROR ${cri_err})
- endif()
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --cpp_out=${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/gogo.proto
- ERROR_VARIABLE cri_err)
- if (cri_err)
- message("Parse ${PROTOS_PATH}/cri/gogo.proto failed: ")
- message(FATAL_ERROR ${cri_err})
- endif()
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --grpc_out=${CRI_PROTOS_OUT_PATH}
- --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/cri/gogo.proto ERROR_VARIABLE cri_err)
- if (cri_err)
- message("Parse ${PROTOS_PATH}/cri/gogo.proto plugin failed: ")
- message(FATAL_ERROR ${cri_err})
- endif()
+ PROTOC_CPP_GEN(cri ${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/gogo.proto)
+ PROTOC_GRPC_GEN(cri ${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/gogo.proto)
if (ENABLE_NATIVE_NETWORK)
execute_process(COMMAND mkdir -p ${NETWORK_PROTOS_OUT_PATH})
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/network
- --cpp_out=${NETWORK_PROTOS_OUT_PATH} ${PROTOS_PATH}/network/network.proto ERROR_VARIABLE network_err)
- if (network_err)
- message("Parse ${PROTOS_PATH}/network/network.proto failed: ")
- message(FATAL_ERROR ${network_err})
- endif()
-
- execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/network --grpc_out=${NETWORK_PROTOS_OUT_PATH}
- --plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/network/network.proto ERROR_VARIABLE network_err)
- if (network_err)
- message("Parse ${PROTOS_PATH}/network/network.proto plugin failed: ")
- message(FATAL_ERROR ${network_err})
- endif()
+ PROTOC_CPP_GEN(network ${NETWORK_PROTOS_OUT_PATH} ${PROTOS_PATH}/network/network.proto)
+ PROTOC_GRPC_GEN(network ${NETWORK_PROTOS_OUT_PATH} ${PROTOS_PATH}/network/network.proto)
endif()
endif()
--
2.25.1