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