1# Copyright (c) 2023 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/uhdf/uhdf.gni") 16 17template("hdi_small") { 18 assert(defined(invoker.sources), "sources must be set") 19 assert(defined(invoker.language), "language must be set") 20 21 #system type, the default value is lite 22 system = "lite" 23 24 # generate mode, the default value is low 25 mode = "passthrough" 26 27 # generate language, the default value is c 28 language = "c" 29 if (defined(invoker.language)) { 30 assert(invoker.language == "c" || invoker.language == "cpp", 31 "the language must be set to 'c' or 'cpp'") 32 language = invoker.language 33 } 34 35 # the path of root package 36 root_package = "ohos.hdi" 37 root_path = rebase_path("//drivers/interface") 38 if (defined(invoker.root)) { 39 package_path_map = string_split(invoker.root, ":") 40 root_package = package_path_map[0] 41 root_path = rebase_path(package_path_map[1]) 42 } 43 root_package_path = "${root_package}:${root_path}" 44 45 # the path of generate code file 46 sources_gen_dir = get_path_info("${root_path}/", "gen_dir") 47 48 # analysis idl file 49 get_build_info_args = [ 50 "--system", 51 system, 52 "--mode", 53 mode, 54 "--language", 55 language, 56 "-o", 57 sources_gen_dir, 58 "-r", 59 root_package_path, 60 ] 61 62 foreach(idl_file, invoker.sources) { 63 get_build_info_args += [ "-f" ] 64 get_build_info_args += [ rebase_path(idl_file) ] 65 } 66 67 hdi_build_info = 68 exec_script("$hdf_framework_path/tools/hdi-gen/build_hdi_files_info.py", 69 get_build_info_args, 70 "json") 71 72 assert(defined(hdi_build_info.include_dirs), "missing include_dirs") 73 assert(defined(hdi_build_info.out_dir), "out_dir") 74 assert(defined(hdi_build_info.version), "missing version") 75 assert(defined(hdi_build_info.sources), "missing sources") 76 77 idl_headers_config = "$target_name" + "_idl_headers_config" 78 config("$idl_headers_config") { 79 include_dirs = [ 80 "//drivers/hdf_core/interfaces/inner_api/osal/shared", 81 "//drivers/hdf_core/interfaces/inner_api/osal/uhdf", 82 "//drivers/hdf_core/interfaces/inner_api/utils", 83 ] 84 include_dirs += hdi_build_info.include_dirs 85 } 86 87 action("hdi_gen") { 88 deps = [ "$hdf_framework_path/tools/hdi-gen:build_hdi_gen" ] 89 script = "/usr/bin/env" 90 if (defined(ohos_lite)) { 91 script = "//build/lite/run_shell_cmd.py" 92 } 93 94 idl_sources = invoker.sources 95 inputs = invoker.sources 96 outputs = hdi_build_info.sources 97 98 args = [ 99 rebase_path(get_path_info("$hdf_framework_path/tools/hdi-gen/", 100 "out_dir") + "/hdi-gen"), 101 "--system", 102 system, 103 "--mode", 104 mode, 105 "--language", 106 language, 107 "-d", 108 rebase_path(hdi_build_info.out_dir), 109 ] 110 111 foreach(idl_file, idl_sources) { 112 args += [ "-c" ] 113 args += [ rebase_path(idl_file) ] 114 } 115 116 args += [ 117 "-r", 118 root_package_path, 119 ] 120 } 121 122 lib_client = "lib" + target_name + "_proxy" + "_" + hdi_build_info.version 123 ohos_shared_library(lib_client) { 124 output_extension = "z.so" 125 126 if (defined(invoker.sources)) { 127 sources = hdi_build_info.proxy_sources 128 public_configs = [ ":$idl_headers_config" ] 129 deps = [ 130 ":hdi_gen", 131 "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", 132 "//third_party/bounds_checking_function:libsec_shared", 133 ] 134 135 public_deps = hdi_build_info.proxy_deps 136 137 external_deps = [ "hdf_core:libhdi" ] 138 if (invoker.language == "c") { 139 external_deps += [ "hdf_core:libhdf_utils" ] 140 } 141 142 shlib_type = "hdi_proxy" 143 subsystem_name = invoker.subsystem_name 144 partname_list = string_split(invoker.part_name, "_") 145 if (partname_list[0] == "drivers") { 146 part_name = invoker.part_name 147 } else { 148 part_name = invoker.part_name + "_interface" 149 } 150 } 151 } 152 153 # generate code and shared library 154 group("$target_name" + "_idl_target") { 155 deps = [ ":$lib_client" ] 156 } 157 158 # only generate code and provide header file path 159 group("$target_name" + "_idl_headers") { 160 public_configs = [ ":$idl_headers_config" ] 161 deps = [ ":hdi_gen" ] 162 } 163} 164