1# Copyright (c) 2021 Huawei Device Co., Ltd. 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 35all_type_codegen = [] 36foreach(proto, all_type_proto) { 37 name = get_path_info(proto, "name") 38 all_type_codegen += [ 39 "$proto_out_dir/$name.pb.h", 40 "$proto_out_dir/$name.pb.cc", 41 ] 42} 43 44action("all_type_gen") { 45 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 46 sources = all_type_proto 47 outputs = all_type_codegen 48 args = [ 49 "$libc_dir_proto", 50 "$root_output_dir_proto", 51 "$proto_rel_out_dir", # standard proto file destination path 52 "--cpp_out", 53 "$proto_rel_out_dir", 54 "--proto_path", 55 rebase_path(".", root_build_dir), 56 ] 57 args += rebase_path(sources, root_build_dir) 58 deps = [ 59 "${OHOS_PROFILER_3RDPARTY_GRPC_DIR}:grpc_cpp_plugin(${host_toolchain})", 60 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc(${host_toolchain})", 61 ] 62} 63 64######################################################## 65profiler_service_type_proto = [ 66 "./common_types.proto", 67 "./profiler_service_types.proto", 68] 69 70profiler_service_type_codegen = [] 71foreach(proto, profiler_service_type_proto) { 72 name = get_path_info(proto, "name") 73 profiler_service_type_codegen += [ 74 "$proto_out_dir/$name.pb.h", 75 "$proto_out_dir/$name.pb.cc", 76 ] 77} 78 79ohos_source_set("profiler_service_type_source") { 80 deps = [ ":all_type_gen" ] 81 public_deps = [ 82 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf", 83 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite", 84 ] 85 include_dirs = [ "$proto_out_dir" ] 86 public_configs = [ ":public_configs" ] 87 sources = profiler_service_type_codegen 88 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 89 part_name = "${OHOS_PROFILER_PART_NAME}" 90} 91 92ohos_source_set("profiler_service_all_type_source") { 93 deps = [ ":all_type_gen" ] 94 public_deps = [ 95 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf", 96 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite", 97 ] 98 include_dirs = [ "$proto_out_dir" ] 99 public_configs = [ ":public_configs" ] 100 sources = all_type_codegen 101 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 102 part_name = "${OHOS_PROFILER_PART_NAME}" 103} 104 105######################################################## 106profiler_service_interface_proto = [ "./profiler_service.proto" ] 107 108profiler_service_interface_codegen = [] 109foreach(proto, profiler_service_interface_proto) { 110 name = get_path_info(proto, "name") 111 profiler_service_interface_codegen += [ 112 "$proto_out_dir/$name.pb.h", 113 "$proto_out_dir/$name.pb.cc", 114 "$proto_out_dir/$name.grpc.pb.h", 115 "$proto_out_dir/$name.grpc.pb.cc", 116 ] 117} 118 119action("profiler_service_interface_gen") { 120 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 121 sources = profiler_service_interface_proto 122 outputs = profiler_service_interface_codegen 123 args = [ 124 "$libc_dir_proto", 125 "$root_output_dir_proto", 126 "$proto_rel_out_dir", # standard proto file destination path 127 "--plugin=protoc-gen-grpc=$grpc_cpp_plugin", 128 "--grpc_out", 129 "$proto_rel_out_dir", 130 "--cpp_out", 131 "$proto_rel_out_dir", 132 "--proto_path", 133 rebase_path(".", root_build_dir), 134 ] 135 args += rebase_path(sources, root_build_dir) 136 deps = [ 137 ":all_type_gen", 138 "${OHOS_PROFILER_3RDPARTY_GRPC_DIR}:grpc_cpp_plugin(//build/toolchain/linux:clang_x64)", 139 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc(//build/toolchain/linux:clang_x64)", 140 ] 141} 142 143ohos_source_set("profiler_service_proto") { 144 deps = [ 145 ":all_type_gen", 146 ":profiler_service_interface_gen", 147 ] 148 public_deps = [ 149 "${OHOS_PROFILER_3RDPARTY_GRPC_DIR}:grpc", 150 "${OHOS_PROFILER_3RDPARTY_GRPC_DIR}:grpcxx", 151 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf", 152 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite", 153 ] 154 include_dirs = [ "$proto_out_dir" ] 155 public_configs = [ ":public_configs" ] 156 sources = profiler_service_interface_codegen 157 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 158 part_name = "${OHOS_PROFILER_PART_NAME}" 159} 160 161######################################################## 162plugin_service_type_proto = [ 163 "./common_types.proto", 164 "./plugin_service_types.proto", 165] 166 167plugin_service_type_codegen = [] 168foreach(proto, plugin_service_type_proto) { 169 name = get_path_info(proto, "name") 170 plugin_service_type_codegen += [ 171 "$proto_out_dir/$name.pb.h", 172 "$proto_out_dir/$name.pb.cc", 173 ] 174} 175 176######################################################## 177plugin_service_interface_proto = [ "./plugin_service.proto" ] 178 179plugin_service_interface_codegen = [] 180foreach(proto, plugin_service_interface_proto) { 181 name = get_path_info(proto, "name") 182 plugin_service_interface_codegen += [ 183 "$proto_out_dir/$name.pb.h", 184 "$proto_out_dir/$name.pb.cc", 185 "$proto_out_dir/$name.ipc.h", 186 "$proto_out_dir/$name.ipc.cc", 187 ] 188} 189 190action("plugin_service_interface_proto_gen") { 191 script = "${OHOS_PROFILER_DIR}/build/protoc.sh" 192 sources = plugin_service_interface_proto 193 outputs = plugin_service_interface_codegen 194 args = [ 195 "$libc_dir_proto", 196 "$root_output_dir_proto", 197 "$proto_rel_out_dir", # standard proto file destination path 198 "--plugin=protoc-gen-ipc=$ipc_cpp_plugin", 199 "--ipc_out", 200 "$proto_rel_out_dir", 201 "--cpp_out", 202 "$proto_rel_out_dir", 203 "--proto_path", 204 rebase_path(".", root_build_dir), 205 ] 206 args += rebase_path(sources, root_build_dir) 207 deps = [ 208 ":all_type_gen", 209 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc(${host_toolchain})", 210 "${OHOS_PROFILER_DIR}/device/services/ipc:protoc_gen_ipc(${host_toolchain})", 211 ] 212} 213 214ohos_source_set("plugin_service_proto") { 215 deps = [ 216 ":all_type_gen", 217 ":plugin_service_interface_proto_gen", 218 ] 219 public_deps = [ 220 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf", 221 "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite", 222 "${OHOS_PROFILER_DIR}/device/services/ipc:ipc", 223 ] 224 include_dirs = [ 225 "$proto_out_dir", 226 "${OHOS_PROFILER_DIR}/device/services/ipc/include", 227 ] 228 public_configs = [ ":public_configs" ] 229 sources = plugin_service_interface_codegen 230 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 231 part_name = "${OHOS_PROFILER_PART_NAME}" 232} 233 234####################################################### 235ohos_source_set("proto_services_cpp") { 236 public_deps = [ 237 ":plugin_service_proto", 238 ":profiler_service_all_type_source", 239 ":profiler_service_proto", 240 ] 241 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 242 part_name = "${OHOS_PROFILER_PART_NAME}" 243} 244