• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/config/python.gni")
15import("//build/ohos/kits/kits_check.gni")
16import("//build/ohos_var.gni")
17
18# Defines subsystem_sdk
19#
20# example:
21#
22# subsystem_sdk("examples_sdk") {
23#   sdk_libs = [
24#     {
25#       type = "so"
26#       name = "interfaces/innerkits/{module_name}:{module_name}"
27#       header = {
28#         header_files = [
29#           "calculator.h",
30#           "abc/a.h",
31#           "abc/xyz/b.h"
32#         ]
33#         header_base = "interfaces/innerkits/{module_name}/include/"
34#       }
35#     },
36#     {
37#       type = "jar"
38#       name = "interfaces/innerkits/{module_name}:{module_name}"
39#       header = {
40#         header_files = []
41#       }
42#     },
43#   ]
44#   subsystem_name = "subsystem_examples"
45# }
46
47template("_ohos_subsystem_sdk") {
48  assert(defined(invoker.sdk_libs), "sdk_libs is required.")
49  assert(invoker.variant != "")
50  assert(invoker.origin_name != "")
51
52  part_name = "common"
53  if (defined(invoker.part_name)) {
54    part_name = invoker.part_name
55  }
56  if (defined(invoker.subsystem_name)) {
57    subsystem_name = invoker.subsystem_name
58  } else {
59    subsystem_name = part_name
60  }
61
62  sdk_manifest = []
63  _deps = []
64  _libs_deps = []
65  foreach(sdk_lib, invoker.sdk_libs) {
66    lib_label = get_label_info(sdk_lib.name, "label_with_toolchain")
67    _libs_deps += [ lib_label ]
68
69    lib_type = "so"
70    if (defined(sdk_lib.type)) {
71      lib_type = sdk_lib.type
72    }
73
74    module_out_dir = get_label_info(lib_label, "target_out_dir")
75    module_name = get_label_info(lib_label, "name")
76    module_info_file = "${module_out_dir}/${module_name}_module_info.json"
77
78    lib_header_files = []
79    lib_header_base = "interfaces/innerkits/${module_name}/include/"
80
81    if (defined(sdk_lib.headers)) {
82      if (defined(sdk_lib.header_base)) {
83        lib_header_base = sdk_lib.header_base
84      }
85      foreach(file, sdk_lib.headers) {
86        lib_header_files += [ string_replace(file, lib_header_base, "") ]
87      }
88    } else if (defined(sdk_lib.header)) {
89      header = {
90      }
91      header = sdk_lib.header
92      if (defined(header.header_base)) {
93        lib_header_base = header.header_base
94      }
95      lib_header_files = header.header_files
96    }
97
98    lib_prebuilt_enable = false
99    lib_prebuilt_source = ""
100    if (defined(sdk_lib.prebuilt_source)) {
101      lib_prebuilt_enable = true
102      lib_prebuilt_source = sdk_lib.prebuilt_source
103    }
104
105    sdk_manifest += [
106      {
107        label = lib_label
108        name = module_name
109        type = lib_type
110        header_files = lib_header_files
111        header_base = rebase_path(lib_header_base, "$root_build_dir")
112        source_info = rebase_path(module_info_file, "$root_build_dir")
113        prebuilt_enable = lib_prebuilt_enable
114        prebuilt_source = lib_prebuilt_source
115        subsystem_name = subsystem_name
116        part_name = part_name
117        origin_name = invoker.origin_name
118        current_toolchain = current_toolchain
119        current_toolchain_dir = rebase_path(root_out_dir, root_build_dir)
120      },
121    ]
122  }
123  _deps += _libs_deps
124
125  subsystem_sdk_desc_file = "${target_out_dir}/${subsystem_name}_sdk_desc.json"
126  write_file(subsystem_sdk_desc_file, sdk_manifest, "json")
127
128  if (check_innersdk_interface && !gen_innersdk_interface_signature) {
129    kits_check_remove("${part_name}_innerkit_remove_check_so") {
130      subsystem_name = part_name
131      if (invoker.variant != "phone") {
132        subsystem_name = invoker.origin_name
133      }
134      sign_file_root_dir = "//interface/innersdk/native"
135      sdk_libs_name = []
136      foreach(_sdk_lib, sdk_manifest) {
137        if (_sdk_lib.type == "so") {
138          sdk_libs_name += [ _sdk_lib.name ]
139        }
140      }
141      output_file = "${target_gen_dir}/innerkit_remove_check_so"
142      sdk_type = "so"
143    }
144    _deps += [ ":${part_name}_innerkit_remove_check_so" ]
145  }
146
147  # gen sdk install modules
148  sdk_install_moudles_file =
149      "${target_gen_dir}/${subsystem_name}_sdk_install_modules.json"
150  generated_file("${subsystem_name}_sdk_info") {
151    outputs = [ sdk_install_moudles_file ]
152    data_keys = [ "install_modules" ]
153    output_conversion = "json"
154    deps = _libs_deps
155  }
156
157  sdk_out_dir = "${root_build_dir}/${innersdk_build_out_dir}/"
158  sdk_build_file = "${sdk_out_dir}/${subsystem_name}/BUILD.gn"
159  sdk_info_file = "${sdk_out_dir}/${subsystem_name}/sdk_info.json"
160
161  action_with_pydeps(target_name) {
162    deps = _deps
163    deps += [ ":${subsystem_name}_sdk_info" ]
164    script = "//build/scripts/gen_sdk_build_file.py"
165    sources = [ subsystem_sdk_desc_file ]
166    outputs = [
167      sdk_build_file,
168      sdk_info_file,
169    ]
170    args = [
171      "--input-file",
172      rebase_path(subsystem_sdk_desc_file, root_build_dir),
173      "--sdk-out-dir",
174      rebase_path("${sdk_out_dir}/${subsystem_name}", root_build_dir),
175      "--output-build-file",
176      rebase_path(sdk_build_file, root_build_dir),
177      "--sdk-info-file",
178      rebase_path(sdk_info_file, root_build_dir),
179    ]
180
181    if (check_innersdk_interface && !gen_innersdk_interface_signature) {
182      innersdk_interface_checkfile_dir = "//interface/innersdk/native"
183      args += [
184        "--signature-file-check-dir",
185        rebase_path(innersdk_interface_checkfile_dir, root_build_dir),
186      ]
187    } else if (gen_innersdk_interface_signature) {
188      args += [
189        "--generate-sig",
190        "--signature-file-gen-dir",
191        rebase_path(
192            "${root_build_dir}/innersdk_interface/native/${subsystem_name}",
193            root_build_dir),
194      ]
195    }
196  }
197}
198
199template("ohos_inner_kits") {
200  _ohos_subsystem_sdk(target_name) {
201    part_name = invoker.part_name
202    sdk_libs = invoker.sdk_libs
203    variant = invoker.variant
204    origin_name = invoker.origin_name
205  }
206}
207