1# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("//build/ohos.gni") 15import("../protos.gni") 16 17####################################################### 18proto_out_dir = "$root_gen_dir/cpp/" + rebase_path(".", "//") 19proto_rel_out_dir = rebase_path(proto_out_dir, root_build_dir) 20 21grpc_cpp_plugin = "$subsys_x64_out/grpc_cpp_plugin" 22ipc_cpp_plugin = "$proto_gen_ipc_dir/protoc_gen_ipc" 23 24config("public_configs") { 25 include_dirs = [ "$proto_out_dir" ] 26} 27 28####################################################### 29all_type_proto = [ 30 "./common_types.proto", 31 "./profiler_service_types.proto", 32 "./plugin_service_types.proto", 33] 34 35common_type_proto = [ "./common_types.proto" ] 36 37all_type_codegen = [] 38foreach(proto, all_type_proto) { 39 name = get_path_info(proto, "name") 40 all_type_codegen += [ 41 "$proto_out_dir/$name.pb.h", 42 "$proto_out_dir/$name.pb.cc", 43 ] 44} 45 46lite_codegen = [] 47foreach(proto, common_type_proto) { 48 name = get_path_info(proto, "name") 49 lite_codegen += [ 50 "$proto_out_dir/${name}_lite.pb.h", 51 "$proto_out_dir/${name}_lite.pb.cc", 52 ] 53} 54 55action("all_type_gen") { 56 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 57 sources = all_type_proto 58 outputs = all_type_codegen 59 outputs += lite_codegen 60 args = [ 61 "$libc_dir_proto", 62 "$root_output_dir_proto", 63 "$proto_rel_out_dir", # standard proto file destination path 64 "--cpp_out", 65 "$proto_rel_out_dir", 66 "--proto_path", 67 rebase_path(".", root_build_dir), 68 ] 69 args += rebase_path(sources, root_build_dir) 70 deps = [ 71 "${OHOS_PROFILER_3RDPARTY_GRPC_DIR}:grpc_cpp_plugin(${host_toolchain})", 72 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc(${host_toolchain})", 73 "${OHOS_PROFILER_DIR}/device/services/ipc:protoencoder_plugin(${host_toolchain})", 74 ] 75} 76 77######################################################## 78profiler_service_type_proto = [ 79 "./common_types.proto", 80 "./profiler_service_types.proto", 81] 82 83profiler_service_type_codegen = [] 84foreach(proto, profiler_service_type_proto) { 85 name = get_path_info(proto, "name") 86 profiler_service_type_codegen += [ 87 "$proto_out_dir/$name.pb.h", 88 "$proto_out_dir/$name.pb.cc", 89 ] 90} 91 92ohos_source_set("profiler_service_type_source") { 93 deps = [ ":all_type_gen" ] 94 external_deps = [ 95 "protobuf:protobuf", 96 "protobuf:protobuf_lite", 97 ] 98 include_dirs = [ "$proto_out_dir" ] 99 public_configs = [ ":public_configs" ] 100 sources = profiler_service_type_codegen 101 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 102 part_name = "${OHOS_PROFILER_PART_NAME}" 103} 104 105ohos_source_set("profiler_service_all_type_source") { 106 deps = [ ":all_type_gen" ] 107 external_deps = [ 108 "protobuf:protobuf", 109 "protobuf:protobuf_lite", 110 ] 111 include_dirs = [ "$proto_out_dir" ] 112 public_configs = [ ":public_configs" ] 113 sources = all_type_codegen 114 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 115 part_name = "${OHOS_PROFILER_PART_NAME}" 116} 117 118######################################################## 119profiler_service_interface_proto = [ "./profiler_service.proto" ] 120 121profiler_service_interface_codegen = [] 122foreach(proto, profiler_service_interface_proto) { 123 name = get_path_info(proto, "name") 124 profiler_service_interface_codegen += [ 125 "$proto_out_dir/$name.pb.h", 126 "$proto_out_dir/$name.pb.cc", 127 "$proto_out_dir/$name.grpc.pb.h", 128 "$proto_out_dir/$name.grpc.pb.cc", 129 ] 130} 131 132action("profiler_service_interface_gen") { 133 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 134 sources = profiler_service_interface_proto 135 outputs = profiler_service_interface_codegen 136 args = [ 137 "$libc_dir_proto", 138 "$root_output_dir_proto", 139 "$proto_rel_out_dir", # standard proto file destination path 140 "--plugin=protoc-gen-grpc=$grpc_cpp_plugin", 141 "--grpc_out", 142 "$proto_rel_out_dir", 143 "--cpp_out", 144 "$proto_rel_out_dir", 145 "--proto_path", 146 rebase_path(".", root_build_dir), 147 ] 148 args += rebase_path(sources, root_build_dir) 149 deps = [ 150 ":all_type_gen", 151 "${OHOS_PROFILER_3RDPARTY_GRPC_DIR}:grpc_cpp_plugin(//build/toolchain/linux:clang_x64)", 152 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc(//build/toolchain/linux:clang_x64)", 153 ] 154} 155 156ohos_source_set("profiler_service_proto") { 157 deps = [ 158 ":all_type_gen", 159 ":profiler_service_interface_gen", 160 ] 161 external_deps = [ 162 "grpc:grpc", 163 "grpc:grpcxx", 164 "protobuf:protobuf", 165 "protobuf:protobuf_lite", 166 ] 167 include_dirs = [ "$proto_out_dir" ] 168 public_configs = [ ":public_configs" ] 169 sources = profiler_service_interface_codegen 170 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 171 part_name = "${OHOS_PROFILER_PART_NAME}" 172} 173 174######################################################## 175plugin_service_type_proto = [ 176 "./common_types.proto", 177 "./plugin_service_types.proto", 178] 179 180plugin_service_type_codegen = [] 181foreach(proto, plugin_service_type_proto) { 182 name = get_path_info(proto, "name") 183 plugin_service_type_codegen += [ 184 "$proto_out_dir/$name.pb.h", 185 "$proto_out_dir/$name.pb.cc", 186 ] 187} 188 189######################################################## 190plugin_service_interface_proto = [ "./plugin_service.proto" ] 191 192plugin_service_interface_codegen = [] 193foreach(proto, plugin_service_interface_proto) { 194 name = get_path_info(proto, "name") 195 plugin_service_interface_codegen += [ 196 "$proto_out_dir/$name.pb.h", 197 "$proto_out_dir/$name.pb.cc", 198 "$proto_out_dir/$name.ipc.h", 199 "$proto_out_dir/$name.ipc.cc", 200 ] 201} 202 203action("plugin_service_interface_proto_gen") { 204 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 205 sources = plugin_service_interface_proto 206 outputs = plugin_service_interface_codegen 207 args = [ 208 "$libc_dir_proto", 209 "$root_output_dir_proto", 210 "$proto_rel_out_dir", # standard proto file destination path 211 "--plugin=protoc-gen-ipc=$ipc_cpp_plugin", 212 "--ipc_out", 213 "$proto_rel_out_dir", 214 "--cpp_out", 215 "$proto_rel_out_dir", 216 "--proto_path", 217 rebase_path(".", root_build_dir), 218 ] 219 args += rebase_path(sources, root_build_dir) 220 deps = [ 221 ":all_type_gen", 222 "${OHOS_PROFILER_DIR}/device/services/ipc:protoc_gen_ipc(${host_toolchain})", 223 ] 224 external_deps = [ "protobuf:protoc(${host_toolchain})" ] 225} 226 227ohos_source_set("plugin_service_proto") { 228 deps = [ 229 ":all_type_gen", 230 ":plugin_service_interface_proto_gen", 231 ] 232 public_deps = [ "${OHOS_PROFILER_DIR}/device/services/ipc:ipc" ] 233 external_deps = [ 234 "protobuf:protobuf", 235 "protobuf:protobuf_lite", 236 ] 237 include_dirs = [ 238 "$proto_out_dir", 239 "${OHOS_PROFILER_DIR}/device/services/ipc/include", 240 ] 241 public_configs = [ ":public_configs" ] 242 sources = plugin_service_interface_codegen 243 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 244 part_name = "${OHOS_PROFILER_PART_NAME}" 245} 246 247####################################################### 248ohos_source_set("proto_services_cpp") { 249 public_deps = [ 250 ":plugin_service_proto", 251 ":profiler_service_all_type_source", 252 ":profiler_service_proto", 253 ] 254 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 255 part_name = "${OHOS_PROFILER_PART_NAME}" 256} 257 258ohos_source_set("common_types_lite_proto") { 259 deps = [ ":all_type_gen" ] 260 external_deps = [ 261 "protobuf:protobuf", 262 "protobuf:protobuf_lite", 263 ] 264 include_dirs = [ "$proto_out_dir" ] 265 public_configs = [ ":public_configs" ] 266 sources = lite_codegen 267 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 268 part_name = "${OHOS_PROFILER_PART_NAME}" 269} 270