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 21if (ohos_indep_compiler_enable) { 22 grpc_dir_plugin = rebase_path("//binarys/third_party") 23 grpc_cpp_plugin = "$grpc_dir_plugin/grpc/innerapis/grpc_cpp_plugin/clang_x64/libs/grpc_cpp_plugin" 24} else { 25 grpc_cpp_plugin = "$subsys_x64_out/grpc_cpp_plugin" 26} 27 28ipc_cpp_plugin = "$proto_gen_ipc_dir/protoc_gen_ipc" 29 30config("public_configs") { 31 include_dirs = [ "$proto_out_dir" ] 32} 33 34####################################################### 35all_type_proto = [ 36 "./common_types.proto", 37 "./profiler_service_types.proto", 38 "./plugin_service_types.proto", 39] 40 41common_type_proto = [ "./common_types.proto" ] 42 43all_type_codegen = [] 44foreach(proto, all_type_proto) { 45 name = get_path_info(proto, "name") 46 all_type_codegen += [ 47 "$proto_out_dir/$name.pb.h", 48 "$proto_out_dir/$name.pb.cc", 49 ] 50} 51 52lite_codegen = [] 53foreach(proto, common_type_proto) { 54 name = get_path_info(proto, "name") 55 lite_codegen += [ 56 "$proto_out_dir/${name}_lite.pb.h", 57 "$proto_out_dir/${name}_lite.pb.cc", 58 ] 59} 60 61action("all_type_gen") { 62 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 63 sources = all_type_proto 64 outputs = all_type_codegen 65 outputs += lite_codegen 66 args = [ 67 "$libc_dir_proto", 68 "$root_output_dir_proto", 69 "$proto_rel_out_dir", # standard proto file destination path 70 "--cpp_out", 71 "$proto_rel_out_dir", 72 "--proto_path", 73 rebase_path(".", root_build_dir), 74 ] 75 args += rebase_path(sources, root_build_dir) 76 args += [ "$ohos_indep_compiler_enable" ] 77 deps = [ "${OHOS_PROFILER_DIR}/device/services/ipc:protoencoder_plugin(${host_toolchain})" ] 78 external_deps = [ 79 "grpc:grpc_cpp_plugin(${host_toolchain})", 80 "protobuf:protoc(${host_toolchain})", 81 ] 82} 83 84######################################################## 85profiler_service_type_proto = [ 86 "./common_types.proto", 87 "./profiler_service_types.proto", 88] 89 90profiler_service_type_codegen = [] 91foreach(proto, profiler_service_type_proto) { 92 name = get_path_info(proto, "name") 93 profiler_service_type_codegen += [ 94 "$proto_out_dir/$name.pb.h", 95 "$proto_out_dir/$name.pb.cc", 96 ] 97} 98 99ohos_source_set("profiler_service_type_source") { 100 deps = [ ":all_type_gen" ] 101 external_deps = [ 102 "protobuf:protobuf", 103 "protobuf:protobuf_lite", 104 ] 105 include_dirs = [ "$proto_out_dir" ] 106 public_configs = [ ":public_configs" ] 107 sources = profiler_service_type_codegen 108 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 109 part_name = "${OHOS_PROFILER_PART_NAME}" 110} 111 112ohos_source_set("profiler_service_all_type_source") { 113 deps = [ ":all_type_gen" ] 114 external_deps = [ 115 "protobuf:protobuf", 116 "protobuf:protobuf_lite", 117 ] 118 include_dirs = [ "$proto_out_dir" ] 119 public_configs = [ ":public_configs" ] 120 sources = all_type_codegen 121 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 122 part_name = "${OHOS_PROFILER_PART_NAME}" 123} 124 125######################################################## 126profiler_service_interface_proto = [ "./profiler_service.proto" ] 127 128profiler_service_interface_codegen = [] 129foreach(proto, profiler_service_interface_proto) { 130 name = get_path_info(proto, "name") 131 profiler_service_interface_codegen += [ 132 "$proto_out_dir/$name.pb.h", 133 "$proto_out_dir/$name.pb.cc", 134 "$proto_out_dir/$name.grpc.pb.h", 135 "$proto_out_dir/$name.grpc.pb.cc", 136 ] 137} 138 139action("profiler_service_interface_gen") { 140 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 141 sources = profiler_service_interface_proto 142 outputs = profiler_service_interface_codegen 143 args = [ 144 "$libc_dir_proto", 145 "$root_output_dir_proto", 146 "$proto_rel_out_dir", # standard proto file destination path 147 "--plugin=protoc-gen-grpc=$grpc_cpp_plugin", 148 "--grpc_out", 149 "$proto_rel_out_dir", 150 "--cpp_out", 151 "$proto_rel_out_dir", 152 "--proto_path", 153 rebase_path(".", root_build_dir), 154 ] 155 args += rebase_path(sources, root_build_dir) 156 args += [ "$ohos_indep_compiler_enable" ] 157 deps = [ ":all_type_gen" ] 158 external_deps = [ 159 "grpc:grpc_cpp_plugin(//build/toolchain/linux:clang_${host_cpu})", 160 "protobuf:protoc(//build/toolchain/linux:clang_${host_cpu})", 161 ] 162} 163 164ohos_source_set("profiler_service_proto") { 165 deps = [ 166 ":all_type_gen", 167 ":profiler_service_interface_gen", 168 ] 169 external_deps = [ 170 "abseil-cpp:absl_sync", 171 "grpc:grpc", 172 "grpc:grpcxx", 173 "protobuf:protobuf", 174 "protobuf:protobuf_lite", 175 ] 176 include_dirs = [ "$proto_out_dir" ] 177 public_configs = [ ":public_configs" ] 178 sources = profiler_service_interface_codegen 179 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 180 part_name = "${OHOS_PROFILER_PART_NAME}" 181} 182 183######################################################## 184plugin_service_type_proto = [ 185 "./common_types.proto", 186 "./plugin_service_types.proto", 187] 188 189plugin_service_type_codegen = [] 190foreach(proto, plugin_service_type_proto) { 191 name = get_path_info(proto, "name") 192 plugin_service_type_codegen += [ 193 "$proto_out_dir/$name.pb.h", 194 "$proto_out_dir/$name.pb.cc", 195 ] 196} 197 198######################################################## 199plugin_service_interface_proto = [ "./plugin_service.proto" ] 200 201plugin_service_interface_codegen = [] 202foreach(proto, plugin_service_interface_proto) { 203 name = get_path_info(proto, "name") 204 plugin_service_interface_codegen += [ 205 "$proto_out_dir/$name.pb.h", 206 "$proto_out_dir/$name.pb.cc", 207 "$proto_out_dir/$name.ipc.h", 208 "$proto_out_dir/$name.ipc.cc", 209 ] 210} 211 212action("plugin_service_interface_proto_gen") { 213 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 214 sources = plugin_service_interface_proto 215 outputs = plugin_service_interface_codegen 216 args = [ 217 "$libc_dir_proto", 218 "$root_output_dir_proto", 219 "$proto_rel_out_dir", # standard proto file destination path 220 "--plugin=protoc-gen-ipc=$ipc_cpp_plugin", 221 "--ipc_out", 222 "$proto_rel_out_dir", 223 "--cpp_out", 224 "$proto_rel_out_dir", 225 "--proto_path", 226 rebase_path(".", root_build_dir), 227 ] 228 args += rebase_path(sources, root_build_dir) 229 args += [ "$ohos_indep_compiler_enable" ] 230 deps = [ 231 ":all_type_gen", 232 "${OHOS_PROFILER_DIR}/device/services/ipc:protoc_gen_ipc(${host_toolchain})", 233 ] 234 external_deps = [ "protobuf:protoc(${host_toolchain})" ] 235} 236 237ohos_source_set("plugin_service_proto") { 238 deps = [ 239 ":all_type_gen", 240 ":plugin_service_interface_proto_gen", 241 ] 242 public_deps = [ "${OHOS_PROFILER_DIR}/device/services/ipc:ipc" ] 243 external_deps = [ 244 "protobuf:protobuf", 245 "protobuf:protobuf_lite", 246 ] 247 include_dirs = [ 248 "$proto_out_dir", 249 "${OHOS_PROFILER_DIR}/device/services/ipc/include", 250 ] 251 public_configs = [ ":public_configs" ] 252 sources = plugin_service_interface_codegen 253 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 254 part_name = "${OHOS_PROFILER_PART_NAME}" 255} 256 257####################################################### 258ohos_source_set("proto_services_cpp") { 259 public_deps = [ 260 ":plugin_service_proto", 261 ":profiler_service_all_type_source", 262 ":profiler_service_proto", 263 ] 264 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 265 part_name = "${OHOS_PROFILER_PART_NAME}" 266} 267 268ohos_source_set("common_types_lite_proto") { 269 deps = [ ":all_type_gen" ] 270 external_deps = [ 271 "protobuf:protobuf", 272 "protobuf:protobuf_lite", 273 ] 274 include_dirs = [ "$proto_out_dir" ] 275 public_configs = [ ":public_configs" ] 276 sources = lite_codegen 277 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 278 part_name = "${OHOS_PROFILER_PART_NAME}" 279} 280