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("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") 16 17hdf_fwk_path = "//drivers/hdf_core/framework" 18 19template("hdi") { 20 assert(defined(invoker.sources), "sources are must") 21 assert(defined(invoker.language), "language are must") 22 assert(defined(invoker.subsystem_name), "subsystem_name are must") 23 assert(defined(invoker.part_name), "part_name are must") 24 25 mode = "ipc" 26 if (defined(invoker.mode)) { 27 assert(invoker.mode == "ipc" || invoker.mode == "passthrough", 28 "hdi mode must be ipc or passthrough") 29 mode = invoker.mode 30 } 31 32 root_package = "ohos.hdi" 33 root_path = rebase_path("//drivers/interface") 34 if (defined(invoker.root)) { 35 package_path_map = string_split(invoker.root, ":") 36 root_package = package_path_map[0] 37 root_path = rebase_path(package_path_map[1]) 38 } 39 root_package_path = "${root_package}:${root_path}" 40 41 sources_gen_dir = get_path_info("${root_path}/", "gen_dir") 42 get_build_info_args = [ 43 "-m", 44 mode, 45 "-l", 46 invoker.language, 47 "-o", 48 sources_gen_dir, 49 "-r", 50 root_package_path, 51 ] 52 foreach(idl_file, invoker.sources) { 53 get_build_info_args += [ "-f" ] 54 get_build_info_args += [ rebase_path(idl_file) ] 55 } 56 hdi_build_info = 57 exec_script("$hdf_fwk_path/tools/hdi-gen/build_hdi_files_info.py", 58 get_build_info_args, 59 "json") 60 assert(defined(hdi_build_info.include_dirs), "missing include_dirs") 61 assert(defined(hdi_build_info.out_dir), "out_dir") 62 assert(defined(hdi_build_info.version), "missing version") 63 assert(defined(hdi_build_info.sources), "missing sources") 64 assert(defined(hdi_build_info.proxy_sources), "missing proxy_sources") 65 assert(defined(hdi_build_info.stub_sources), "missing stub_sources") 66 67 idl_headers_config = "$target_name" + "_idl_headers_config" 68 config("$idl_headers_config") { 69 include_dirs = [ 70 "$hdf_uhdf_path/include/hdi", 71 "$hdf_uhdf_path/osal/include", 72 "$hdf_uhdf_path/ipc/include", 73 "$hdf_framework_path/include/utils", 74 ] 75 include_dirs += hdi_build_info.include_dirs 76 } 77 78 action("hdi_gen") { 79 deps = [ "$hdf_fwk_path/tools/hdi-gen:build_hdi_gen" ] 80 script = "/usr/bin/env" 81 if (defined(ohos_lite)) { 82 script = "//build/lite/run_shell_cmd.py" 83 } 84 85 idl_sources = invoker.sources 86 inputs = invoker.sources 87 language = "--gen-" + invoker.language 88 outputs = hdi_build_info.sources 89 90 args = [ 91 rebase_path(get_path_info("$hdf_fwk_path/tools/hdi-gen/", "out_dir") + 92 "/hdi-gen"), 93 "$language", 94 "-d", 95 rebase_path(hdi_build_info.out_dir), 96 ] 97 98 if (defined(invoker.module_name)) { 99 args += [ 100 "--module-name", 101 invoker.module_name, 102 ] 103 } 104 105 foreach(idl_file, idl_sources) { 106 args += [ "-c" ] 107 args += [ rebase_path(idl_file) ] 108 } 109 args += [ 110 "-r", 111 root_package_path, 112 ] 113 114 if (mode == "passthrough") { 115 args += [ "--passthrough" ] 116 } 117 } 118 119 lib_client = "lib" + target_name + "_proxy" + "_" + hdi_build_info.version 120 ohos_shared_library(lib_client) { 121 if (defined(invoker.sources)) { 122 sources = hdi_build_info.proxy_sources 123 124 public_configs = [ ":$idl_headers_config" ] 125 deps = [ ":hdi_gen" ] 126 if (is_standard_system) { 127 if (defined(invoker.sequenceable)) { 128 public_deps = invoker.sequenceable 129 } 130 131 external_deps = [ 132 "c_utils:utils", 133 "hdf_core:libhdi", 134 "hiviewdfx_hilog_native:libhilog", 135 ] 136 137 if (invoker.language == "c") { 138 external_deps += [ 139 "hdf_core:libhdf_ipc_adapter", 140 "hdf_core:libhdf_utils", 141 ] 142 } else if (invoker.language == "cpp") { 143 external_deps += [ "ipc:ipc_single" ] 144 } 145 } else { 146 external_deps = [ "hilog:libhilog" ] 147 } 148 149 install_images = [ system_base_dir ] 150 subsystem_name = invoker.subsystem_name 151 partname_list = string_split(invoker.part_name, "_") 152 if (partname_list[0] == "drivers") { 153 part_name = invoker.part_name 154 } else { 155 part_name = invoker.part_name + "_interface" 156 } 157 } 158 } 159 160 if (mode == "ipc") { 161 lib_server = "lib" + target_name + "_stub" + "_" + hdi_build_info.version 162 ohos_shared_library(lib_server) { 163 if (defined(invoker.sources)) { 164 sources = hdi_build_info.stub_sources 165 public_configs = [ ":$idl_headers_config" ] 166 167 deps = [ ":hdi_gen" ] 168 if (is_standard_system) { 169 if (defined(invoker.sequenceable)) { 170 public_deps = invoker.sequenceable 171 } 172 173 external_deps = [ 174 "c_utils:utils", 175 "hdf_core:libhdi", 176 "hiviewdfx_hilog_native:libhilog", 177 ] 178 179 if (invoker.language == "c") { 180 external_deps += [ 181 "hdf_core:libhdf_ipc_adapter", 182 "hdf_core:libhdf_utils", 183 ] 184 } else if (invoker.language == "cpp") { 185 external_deps += [ "ipc:ipc_single" ] 186 } 187 } else { 188 external_deps = [ "hilog:libhilog" ] 189 } 190 191 install_images = [ chipset_base_dir ] 192 subsystem_name = invoker.subsystem_name 193 part_name = invoker.part_name 194 } 195 } 196 } 197 198 # generate code and shared library 199 group("$target_name" + "_idl_target") { 200 deps = [ ":$lib_client" ] 201 if (mode == "ipc") { 202 deps += [ ":$lib_server" ] 203 } 204 } 205 206 # only generate code and provide header file path 207 group("$target_name" + "_idl_headers") { 208 public_configs = [ ":$idl_headers_config" ] 209 deps = [ ":hdi_gen" ] 210 } 211} 212