1# Copyright (c) 2021-2024 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") 15 16hdf_fwk_path = "//drivers/hdf_core/framework" 17hdf_uhdf_path = "//drivers/hdf_core/adapter/uhdf2" 18idl_tool_path = "//foundation/ability/idl_tool/idl_tool_2" 19 20idl_root = "//foundation/ability/idl_tool" 21idl_build_deps = "" 22 23build_root = "//build" 24toolchain_linux = "$build_root/toolchain/linux:clang_x64" 25if (host_cpu == "arm64") { 26 toolchain_mac = "$build_root/toolchain/mac:clang_arm64" 27} else { 28 toolchain_mac = "$build_root/toolchain/mac:clang_x64" 29} 30toolchain_win = "$build_root/toolchain/mingw:mingw_x86_64" 31 32if (host_toolchain == toolchain_mac) { 33 idl_out_root = get_label_info("idl_tool:idl($toolchain_mac)", "root_out_dir") 34 idl_build_deps = [ "idl_tool:idl($toolchain_mac)" ] 35} else if (host_toolchain == toolchain_win) { 36 idl_out_root = get_label_info("idl_tool:idl($toolchain_win)", "root_out_dir") 37 idl_build_deps = [ "idl_tool:idl($toolchain_win)" ] 38} else { 39 idl_out_root = 40 get_label_info("idl_tool:idl($toolchain_linux)", "root_out_dir") 41 idl_build_deps = [ "idl_tool:idl($toolchain_linux)" ] 42} 43idl_build_path = idl_out_root + "/ability/idl_tool" 44 45template("hdi") { 46 assert(defined(invoker.sources), "sources must be set") 47 assert(defined(invoker.language), "language must be set") 48 assert(defined(invoker.subsystem_name), "subsystem_name must be set") 49 assert(defined(invoker.part_name), "part_name must be set") 50 51 # the module_name is an obsolete option 52 if (defined(invoker.module_name)) { 53 print(invoker.module_name) 54 } 55 56 # system type 57 system = "full" 58 59 # generate mode, the default value is "ipc", the optional values are "ipc" or "passthrough" 60 mode = "ipc" 61 if (defined(invoker.mode)) { 62 assert(invoker.mode == "ipc" || invoker.mode == "passthrough", 63 "hdi mode must be 'ipc' or 'passthrough'") 64 mode = invoker.mode 65 } 66 67 assert(invoker.language == "c" || invoker.language == "cpp", 68 "the language must be set to 'c' or 'cpp'") 69 language = invoker.language 70 71 imports = [] 72 if (defined(invoker.imports)) { 73 imports += invoker.imports 74 } 75 76 root_package = "ohos.hdi" 77 root_path = rebase_path("//drivers/interface") 78 if (defined(invoker.root)) { 79 package_path_map = string_split(invoker.root, ":") 80 root_package = package_path_map[0] 81 root_path = rebase_path(package_path_map[1]) 82 } 83 root_package_path = "${root_package}:${root_path}" 84 85 # set base directory of hdi files, set this parameter to your component name if you are using external idl files. 86 if (defined(invoker.base_dir)) { 87 root_path += invoker.base_dir 88 } 89 90 sources_gen_dir = get_path_info("${root_path}/", "gen_dir") 91 get_build_info_args = [ 92 "-s", 93 system, 94 "-m", 95 mode, 96 "-l", 97 invoker.language, 98 "-o", 99 sources_gen_dir, 100 "-r", 101 root_package_path, 102 ] 103 foreach(idl_file, invoker.sources) { 104 get_build_info_args += [ "-f" ] 105 get_build_info_args += [ rebase_path(idl_file) ] 106 } 107 108 foreach(import_info, imports) { 109 get_build_info_args += [ 110 "--import", 111 import_info, 112 ] 113 } 114 115 hdi_build_info = exec_script( 116 rebase_path("//build/config/components/hdi/build_hdi_files_info.py"), 117 get_build_info_args, 118 "json") 119 assert(defined(hdi_build_info.include_dirs), "missing include_dirs") 120 assert(defined(hdi_build_info.out_dir), "out_dir") 121 assert(defined(hdi_build_info.version), "missing version") 122 assert(defined(hdi_build_info.sources), "missing sources") 123 assert(defined(hdi_build_info.proxy_sources), "missing proxy_sources") 124 assert(defined(hdi_build_info.stub_sources), "missing stub_sources") 125 assert(defined(hdi_build_info.proxy_deps), "missing proxy_deps") 126 assert(defined(hdi_build_info.stub_deps), "missing stub_deps") 127 assert(defined(hdi_build_info.header_deps), "missing header_deps") 128 129 idl_headers_config = "$target_name" + "_idl_headers_config" 130 config("$idl_headers_config") { 131 include_dirs = hdi_build_info.include_dirs 132 133 include_dirs += [ 134 "$hdf_uhdf_path/ipc/include", 135 "//drivers/hdf_core/interfaces/inner_api/utils", 136 "//drivers/hdf_core/interfaces/inner_api/osal/uhdf", 137 "//drivers/hdf_core/interfaces/inner_api/hdi", 138 ] 139 } 140 141 action("idl_gen") { 142 external_deps = idl_build_deps 143 script = "/usr/bin/env" 144 if (defined(ohos_lite)) { 145 script = "//build/lite/run_shell_cmd.py" 146 } 147 148 idl_sources = invoker.sources 149 inputs = invoker.sources 150 outputs = hdi_build_info.sources 151 152 args = [ 153 rebase_path("${idl_build_path}") + "/idl", 154 "--intf-type", 155 "hdi", 156 "--system", 157 system, 158 "--mode", 159 mode, 160 "-d", 161 rebase_path(hdi_build_info.out_dir), 162 ] 163 164 if (language == "c") { 165 args += [ "--gen-c" ] 166 } else if (language == "cpp") { 167 args += [ "--gen-cpp" ] 168 } 169 170 foreach(idl_file, idl_sources) { 171 args += [ "-c" ] 172 args += [ rebase_path(idl_file) ] 173 } 174 args += [ 175 "-r", 176 root_package_path, 177 ] 178 } 179 180 lib_client = "lib" + target_name + "_proxy" + "_" + hdi_build_info.version 181 ohos_shared_library(lib_client) { 182 if (defined(invoker.sources)) { 183 sources = hdi_build_info.proxy_sources 184 public_configs = [ ":$idl_headers_config" ] 185 deps = [ ":idl_gen" ] 186 if (is_standard_system) { 187 if (defined(invoker.deps)) { 188 deps += invoker.deps 189 } 190 191 if (defined(invoker.proxy_deps)) { 192 deps += invoker.proxy_deps 193 } 194 195 public_deps = [] 196 if (defined(invoker.sequenceable_pub_deps)) { 197 public_deps += invoker.sequenceable_pub_deps 198 } 199 200 public_deps += hdi_build_info.proxy_deps 201 202 external_deps = [ 203 "c_utils:utils", 204 "hdf_core:libhdf_utils", 205 "hdf_core:libhdi", 206 "hdf_core:libpub_utils", 207 "hilog:libhilog", 208 ] 209 if (defined(invoker.sequenceable_ext_deps)) { 210 external_deps += invoker.sequenceable_ext_deps 211 } 212 if (invoker.language == "c") { 213 external_deps += [ "hdf_core:libhdf_ipc_adapter" ] 214 } else if (invoker.language == "cpp") { 215 external_deps += [ "ipc:ipc_single" ] 216 } 217 } else { 218 external_deps = [ "hilog:libhilog" ] 219 } 220 221 if (defined(invoker.innerapi_tags)) { 222 innerapi_tags = invoker.innerapi_tags 223 } 224 shlib_type = "hdi_proxy" 225 if (defined(invoker.install_images)) { 226 install_images = invoker.install_images 227 } else { 228 install_images = [ system_base_dir ] 229 } 230 231 subsystem_name = invoker.subsystem_name 232 partname_list = string_split(invoker.part_name, "_") 233 if (partname_list[0] == "drivers") { 234 part_name = invoker.part_name 235 } else { 236 part_name = invoker.part_name + "_interface" 237 } 238 239 if (defined(invoker.stack_protector_ret)) { 240 stack_protector_ret = invoker.stack_protector_ret 241 } 242 243 if (defined(invoker.sanitize)) { 244 sanitize = invoker.sanitize 245 } 246 247 if (defined(invoker.cflags)) { 248 cflags = invoker.cflags 249 } 250 251 if (defined(invoker.cflags_cc)) { 252 cflags_cc = invoker.cflags_cc 253 } 254 255 if (defined(invoker.branch_protector_ret)) { 256 branch_protector_ret = invoker.branch_protector_ret 257 } 258 } 259 } 260 261 if (mode == "ipc") { 262 lib_server = "lib" + target_name + "_stub" + "_" + hdi_build_info.version 263 ohos_shared_library(lib_server) { 264 if (defined(invoker.sources)) { 265 sources = hdi_build_info.stub_sources 266 public_configs = [ ":$idl_headers_config" ] 267 268 deps = [ ":idl_gen" ] 269 if (is_standard_system) { 270 if (defined(invoker.deps)) { 271 deps += invoker.deps 272 } 273 274 if (defined(invoker.stub_deps)) { 275 deps += invoker.stub_deps 276 } 277 278 public_deps = [] 279 if (defined(invoker.sequenceable_pub_deps)) { 280 public_deps += invoker.sequenceable_pub_deps 281 } 282 283 public_deps += hdi_build_info.stub_deps 284 285 external_deps = [ 286 "c_utils:utils", 287 "hdf_core:libhdf_utils", 288 "hdf_core:libhdi", 289 "hilog:libhilog", 290 ] 291 if (defined(invoker.sequenceable_ext_deps)) { 292 external_deps += invoker.sequenceable_ext_deps 293 } 294 if (invoker.language == "c") { 295 external_deps += [ 296 "hdf_core:libhdf_ipc_adapter", 297 "hdf_core:libhdf_utils", 298 ] 299 } else if (invoker.language == "cpp") { 300 external_deps += [ "ipc:ipc_single" ] 301 } 302 } else { 303 external_deps = [ "hilog:libhilog" ] 304 } 305 306 shlib_type = "hdi_stub" 307 install_images = [ chipset_base_dir ] 308 subsystem_name = invoker.subsystem_name 309 part_name = invoker.part_name 310 311 if (defined(invoker.stack_protector_ret)) { 312 stack_protector_ret = invoker.stack_protector_ret 313 } 314 315 if (defined(invoker.sanitize)) { 316 sanitize = invoker.sanitize 317 } 318 319 if (defined(invoker.cflags)) { 320 cflags = invoker.cflags 321 } 322 323 if (defined(invoker.cflags_cc)) { 324 cflags_cc = invoker.cflags_cc 325 } 326 327 if (defined(invoker.branch_protector_ret)) { 328 branch_protector_ret = invoker.branch_protector_ret 329 } 330 } 331 } 332 } 333 334 # generate code and shared library 335 group("$target_name" + "_idl_target") { 336 deps = [ ":$lib_client" ] 337 if (mode == "ipc") { 338 deps += [ ":$lib_server" ] 339 } 340 } 341 342 # only generate code and provide header file path 343 # usage example: external_deps = [ "drivers_interface_xxx:xxx_idl_headers" ] 344 # this target has been replaced by 'idl_headers_target', please use 'idl_headers_target' 345 group("$target_name" + "_idl_headers") { 346 public_configs = [ ":$idl_headers_config" ] 347 deps = [ ":idl_gen" ] 348 } 349 350 # only generate code and provide header file path 351 # usage example: external_deps = [ "drivers_interface_xxx:xxx_idl_headers_1.0" ] 352 idl_headers_target = target_name + "_idl_headers_" + hdi_build_info.version 353 group(idl_headers_target) { 354 public_configs = [ ":$idl_headers_config" ] 355 deps = [ ":idl_gen" ] 356 deps += hdi_build_info.header_deps 357 } 358} 359