• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/khdf/liteos_m/hdf.gni")
16
17template("hdi_mini") {
18  assert(defined(invoker.sources), "sources must be set")
19  assert(defined(invoker.language), "language must be set")
20
21  # system type
22  system = "mini"
23
24  # generate mode, the default value is low
25  mode = "low"
26
27  # generate language, the default value is c
28  language = "c"
29  if (defined(invoker.language)) {
30    assert(invoker.language == "c", "the language must be set to 'c'")
31    language = invoker.language
32  }
33
34  # the path of root package
35  root_package = "ohos.hdi"
36  root_path = rebase_path("//drivers/interface")
37  if (defined(invoker.root)) {
38    package_path_map = string_split(invoker.root, ":")
39    root_package = package_path_map[0]
40    root_path = rebase_path(package_path_map[1])
41  }
42  root_package_path = "${root_package}:${root_path}"
43
44  # the path of generate code file
45  sources_gen_dir = get_path_info("${root_path}/", "gen_dir")
46
47  # analysis idl file
48  get_build_info_args = [
49    "--system",
50    system,
51    "--mode",
52    mode,
53    "--language",
54    language,
55    "-o",
56    sources_gen_dir,
57    "-r",
58    root_package_path,
59  ]
60
61  foreach(idl_file, invoker.sources) {
62    get_build_info_args += [ "-f" ]
63    get_build_info_args += [ rebase_path(idl_file) ]
64  }
65
66  hdi_build_info =
67      exec_script("$HDF_FRAMEWORKS_PATH/tools/hdi-gen/build_hdi_files_info.py",
68                  get_build_info_args,
69                  "json")
70  print("============================================")
71  print(hdi_build_info)
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      "$HDF_FRAMEWORKS_PATH/include/osal",
81      "$HDF_FRAMEWORKS_PATH/include/util",
82    ]
83    include_dirs += hdi_build_info.include_dirs
84  }
85
86  action("hdi_gen") {
87    deps = [ "$HDF_FRAMEWORKS_PATH/tools/hdi-gen:build_hdi_gen" ]
88    script = "/usr/bin/env"
89    if (defined(ohos_lite)) {
90      script = "//build/lite/run_shell_cmd.py"
91    }
92
93    idl_sources = invoker.sources
94    inputs = invoker.sources
95    outputs = hdi_build_info.sources
96
97    args = [
98      rebase_path(get_path_info("$HDF_FRAMEWORKS_PATH/tools/hdi-gen/",
99                                "out_dir") + "/hdi-gen"),
100      "--system",
101      system,
102      "--mode",
103      mode,
104      "--language",
105      language,
106      "-d",
107      rebase_path(hdi_build_info.out_dir),
108    ]
109
110    foreach(idl_file, idl_sources) {
111      args += [ "-c" ]
112      args += [ rebase_path(idl_file) ]
113    }
114
115    args += [
116      "-r",
117      root_package_path,
118    ]
119  }
120
121  # only generate code and provide header file path
122  header_target_name = "${target_name}_idl_headers"
123  group(header_target_name) {
124    public_configs = [ ":$idl_headers_config" ]
125    deps = [ ":hdi_gen" ]
126  }
127
128  # only generate code
129  idl_target_name = "${target_name}_idl_target"
130  group(idl_target_name) {
131    deps = [ ":${header_target_name}" ]
132  }
133}
134