• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-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/uhdf2/uhdf.gni")
16
17hdf_fwk_path = "//drivers/hdf_core/framework"
18
19template("hdi") {
20  assert(defined(invoker.sources), "sources must be set")
21  assert(defined(invoker.language), "language must be set")
22  assert(defined(invoker.subsystem_name), "subsystem_name must be set")
23  assert(defined(invoker.part_name), "part_name must be set")
24
25  # the module_name is an obsolete option
26  if (defined(invoker.module_name)) {
27    print(invoker.module_name)
28  }
29
30  # system type
31  system = "full"
32
33  # generate mode, the default value is "ipc", the optional values are "ipc" or "passthrough"
34  mode = "ipc"
35  if (defined(invoker.mode)) {
36    assert(invoker.mode == "ipc" || invoker.mode == "passthrough",
37           "hdi mode must be 'ipc' or 'passthrough'")
38    mode = invoker.mode
39  }
40
41  assert(invoker.language == "c" || invoker.language == "cpp",
42         "the language must be set to 'c' or 'cpp'")
43  language = invoker.language
44
45  imports = []
46  if (defined(invoker.imports)) {
47    imports += invoker.imports
48  }
49
50  root_package = "ohos.hdi"
51  root_path = rebase_path("//drivers/interface")
52  if (defined(invoker.root)) {
53    package_path_map = string_split(invoker.root, ":")
54    root_package = package_path_map[0]
55    root_path = rebase_path(package_path_map[1])
56  }
57  root_package_path = "${root_package}:${root_path}"
58
59  sources_gen_dir = get_path_info("${root_path}/", "gen_dir")
60  get_build_info_args = [
61    "-s",
62    system,
63    "-m",
64    mode,
65    "-l",
66    invoker.language,
67    "-o",
68    sources_gen_dir,
69    "-r",
70    root_package_path,
71  ]
72  foreach(idl_file, invoker.sources) {
73    get_build_info_args += [ "-f" ]
74    get_build_info_args += [ rebase_path(idl_file) ]
75  }
76
77  foreach(import_info, imports) {
78    get_build_info_args += [
79      "--import",
80      import_info,
81    ]
82  }
83
84  hdi_build_info =
85      exec_script("$hdf_fwk_path/tools/hdi-gen/build_hdi_files_info.py",
86                  get_build_info_args,
87                  "json")
88  assert(defined(hdi_build_info.include_dirs), "missing include_dirs")
89  assert(defined(hdi_build_info.out_dir), "out_dir")
90  assert(defined(hdi_build_info.version), "missing version")
91  assert(defined(hdi_build_info.sources), "missing sources")
92  assert(defined(hdi_build_info.proxy_sources), "missing proxy_sources")
93  assert(defined(hdi_build_info.stub_sources), "missing stub_sources")
94  assert(defined(hdi_build_info.proxy_deps), "missing proxy_deps")
95  assert(defined(hdi_build_info.stub_deps), "missing stub_deps")
96  assert(defined(hdi_build_info.header_deps), "missing header_deps")
97
98  idl_headers_config = "$target_name" + "_idl_headers_config"
99  config("$idl_headers_config") {
100    include_dirs = [
101      "$hdf_uhdf_path/include/hdi",
102      "$hdf_uhdf_path/osal/include",
103      "$hdf_uhdf_path/ipc/include",
104      "$hdf_framework_path/include/utils",
105      "//drivers/hdf_core/interfaces/inner_api/utils",
106      "//drivers/hdf_core/interfaces/inner_api/osal/uhdf",
107      "//drivers/hdf_core/interfaces/inner_api/hdi",
108    ]
109    include_dirs += hdi_build_info.include_dirs
110  }
111
112  action("hdi_gen") {
113    deps = [ "$hdf_fwk_path/tools/hdi-gen:build_hdi_gen" ]
114    script = "/usr/bin/env"
115    if (defined(ohos_lite)) {
116      script = "//build/lite/run_shell_cmd.py"
117    }
118
119    idl_sources = invoker.sources
120    inputs = invoker.sources
121    outputs = hdi_build_info.sources
122
123    args = [
124      rebase_path(get_path_info("$hdf_fwk_path/tools/hdi-gen/", "out_dir") +
125                  "/hdi-gen"),
126      "--system",
127      system,
128      "--mode",
129      mode,
130      "--language",
131      language,
132      "-d",
133      rebase_path(hdi_build_info.out_dir),
134    ]
135
136    foreach(idl_file, idl_sources) {
137      args += [ "-c" ]
138      args += [ rebase_path(idl_file) ]
139    }
140    args += [
141      "-r",
142      root_package_path,
143    ]
144  }
145
146  lib_client = "lib" + target_name + "_proxy" + "_" + hdi_build_info.version
147  ohos_shared_library(lib_client) {
148    if (defined(invoker.sources)) {
149      sources = hdi_build_info.proxy_sources
150      public_configs = [ ":$idl_headers_config" ]
151      deps = [ ":hdi_gen" ]
152      if (is_standard_system) {
153        public_deps = []
154        if (defined(invoker.sequenceable_pub_deps)) {
155          public_deps += invoker.sequenceable_pub_deps
156        }
157
158        public_deps += hdi_build_info.proxy_deps
159
160        external_deps = [
161          "c_utils:utils",
162          "hdf_core:libhdi",
163          "hdf_core:libpub_utils",
164          "hilog:libhilog",
165        ]
166        if (defined(invoker.sequenceable_ext_deps)) {
167          external_deps += invoker.sequenceable_ext_deps
168        }
169        if (invoker.language == "c") {
170          external_deps += [ "hdf_core:libhdf_ipc_adapter" ]
171        } else if (invoker.language == "cpp") {
172          external_deps += [ "ipc:ipc_single" ]
173        }
174      } else {
175        external_deps = [ "hilog:libhilog" ]
176      }
177
178      if (defined(invoker.innerapi_tags)) {
179        innerapi_tags = invoker.innerapi_tags
180      }
181      shlib_type = "hdi_proxy"
182      install_images = [ system_base_dir ]
183      subsystem_name = invoker.subsystem_name
184      partname_list = string_split(invoker.part_name, "_")
185      if (partname_list[0] == "drivers") {
186        part_name = invoker.part_name
187      } else {
188        part_name = invoker.part_name + "_interface"
189      }
190    }
191  }
192
193  if (mode == "ipc") {
194    lib_server = "lib" + target_name + "_stub" + "_" + hdi_build_info.version
195    ohos_shared_library(lib_server) {
196      if (defined(invoker.sources)) {
197        sources = hdi_build_info.stub_sources
198        public_configs = [ ":$idl_headers_config" ]
199
200        deps = [ ":hdi_gen" ]
201        if (is_standard_system) {
202          public_deps = []
203          if (defined(invoker.sequenceable_pub_deps)) {
204            public_deps += invoker.sequenceable_pub_deps
205          }
206
207          public_deps += hdi_build_info.stub_deps
208
209          external_deps = [
210            "c_utils:utils",
211            "hdf_core:libhdi",
212            "hilog:libhilog",
213          ]
214          if (defined(invoker.sequenceable_ext_deps)) {
215            external_deps += invoker.sequenceable_ext_deps
216          }
217          if (invoker.language == "c") {
218            external_deps += [
219              "hdf_core:libhdf_ipc_adapter",
220              "hdf_core:libhdf_utils",
221            ]
222          } else if (invoker.language == "cpp") {
223            external_deps += [ "ipc:ipc_single" ]
224          }
225        } else {
226          external_deps = [ "hilog:libhilog" ]
227        }
228
229        shlib_type = "hdi_stub"
230        install_images = [ chipset_base_dir ]
231        subsystem_name = invoker.subsystem_name
232        part_name = invoker.part_name
233      }
234    }
235  }
236
237  # generate code and shared library
238  group("$target_name" + "_idl_target") {
239    deps = [ ":$lib_client" ]
240    if (mode == "ipc") {
241      deps += [ ":$lib_server" ]
242    }
243  }
244
245  # only generate code and provide header file path
246  # usage example: external_deps = [ "drivers_interface_xxx:xxx_idl_headers" ]
247  # this target has been replaced by 'idl_headers_target', please use 'idl_headers_target'
248  group("$target_name" + "_idl_headers") {
249    public_configs = [ ":$idl_headers_config" ]
250    deps = [ ":hdi_gen" ]
251  }
252
253  # only generate code and provide header file path
254  # usage example: external_deps = [ "drivers_interface_xxx:xxx_idl_headers_1.0" ]
255  idl_headers_target = target_name + "_idl_headers_" + hdi_build_info.version
256  group(idl_headers_target) {
257    public_configs = [ ":$idl_headers_config" ]
258    deps = [ ":hdi_gen" ]
259    public_deps = hdi_build_info.header_deps
260  }
261}
262