• 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/ohos/build_var.gni")
15import("//build/ohos/sdk/sdk.gni")
16import("//build/ohos_var.gni")
17import("${build_configs_path}/platforms_list.gni")
18
19if (!use_current_sdk) {
20  parse_script = "//build/ohos/sdk/parse_sdk_description.py"
21  ohos_sdk_description_file = "//build/ohos/sdk/ohos_sdk_description_std.json"
22  if (defined(ext_sdk_config_file) && ext_sdk_config_file != "") {
23    ohos_sdk_description_file = ext_sdk_config_file
24  }
25  if (sdk_for_hap_build) {
26    hap_build_sdk_config_parser =
27        "//build/ohos/sdk/generate_hap_build_sdk_config.py"
28    hap_build_sdk_description_file = "//out/sdk/ohos_sdk_description_hap.json"
29    hap_build_sdk_args = [
30      "--sdk-description-file",
31      rebase_path(ohos_sdk_description_file, root_build_dir),
32      "--output-hap-build-sdk-desc-file",
33      rebase_path(hap_build_sdk_description_file, root_build_dir),
34    ]
35    exec_script(hap_build_sdk_config_parser, hap_build_sdk_args)
36    ohos_sdk_description_file = hap_build_sdk_description_file
37  }
38
39  if (sdk_build_public) {
40    public_sdk_config_parser = "//build/ohos/sdk/parse_public_sdk.py"
41    ohos_sdk_pub_description_file =
42        "//out/sdk-public/ohos_sdk_pub_description_std.json"
43    public_sdk_args = [
44      "--sdk-description-file",
45      rebase_path(ohos_sdk_description_file, root_build_dir),
46      "--root-build-dir",
47      rebase_path("//", root_build_dir),
48      "--node-js",
49      rebase_path(nodejs, root_build_dir),
50      "--output-pub-sdk-desc-file",
51      rebase_path(ohos_sdk_pub_description_file, root_build_dir),
52    ]
53    exec_script(public_sdk_config_parser, public_sdk_args)
54    ohos_sdk_description_file = ohos_sdk_pub_description_file
55  }
56
57  generated_sdk_modules_gni = "${generated_files_dir}/ohos_sdk_modules.gni"
58  generated_sdk_types_file = "${generated_files_dir}/generated_sdk_types.txt"
59
60  parse_args = [
61    "--sdk-description-file",
62    rebase_path(ohos_sdk_description_file, root_build_dir),
63    "--sdk-modules-gni",
64    rebase_path(generated_sdk_modules_gni, root_build_dir),
65    "--sdk-install-info-file",
66    rebase_path(generated_sdk_module_install_paths, root_build_dir),
67    "--sdk-types-file",
68    rebase_path(generated_sdk_types_file, root_build_dir),
69    "--base-platform",
70    "phone",
71    "--variant-to-product",
72    rebase_path("./variant_to_product.json", root_build_dir),
73    "--source-root-dir",
74    rebase_path("//", root_build_dir),
75    "--node-js",
76    rebase_path(nodejs, root_build_dir),
77  ]
78  foreach(p, target_platform_list) {
79    parse_args += [
80      "--platforms",
81      p,
82    ]
83  }
84
85  exec_script(parse_script, parse_args)
86
87  sdk_types = read_file(generated_sdk_types_file, "list lines")
88
89  import("${generated_sdk_modules_gni}")
90
91  generate_all_types_sdk_script = "//build/ohos/sdk/generate_all_types_sdk.py"
92  generated_build_gn = "$generated_files_dir/BUILD.gn"
93  generate_args = [
94    "--sdk-modules",
95    "ohos_sdk_modules",
96    "--output",
97    rebase_path(generated_build_gn, root_build_dir),
98    "--current-dir",
99    get_path_info(sdk_base_build_gn, "dir"),
100    "--generated-sdk-modules-gni",
101    generated_sdk_modules_gni,
102    "--type2displayname",
103    rebase_path("./type_to_display_name.json", root_build_dir),
104    "--api-version",
105    api_version,
106    "--release-type",
107    release_type,
108    "--meta-version",
109    meta_version,
110  ]
111
112  foreach(os, sdk_systems) {
113    generate_args += [
114      "--sdk-systems",
115      os,
116    ]
117  }
118
119  foreach(sdk_type, sdk_types) {
120    generate_args += [
121      "--sdk-types",
122      sdk_type,
123    ]
124  }
125
126  exec_script(generate_all_types_sdk_script, generate_args)
127
128  action_with_pydeps("generate_sdk_notice") {
129    deps = [ "${generated_files_dir}:generated_ohos_sdk" ]
130    inputs = []
131
132    script = "//build/ohos/notice/merge_notice_files.py"
133    depfile = "$target_gen_dir/$target_name.d"
134    _install_path = "${target_out_dir}/SDK_NOTICE_FILES/"
135
136    outputs = [
137      sdk_notice_txt,
138      sdk_notice_gz,
139    ]
140    args = [
141      "--image-name",
142      "sdk",
143      "--notice-root-dir",
144      rebase_path(sdk_notice_dir, root_build_dir),
145      "--output-notice-txt",
146      rebase_path(sdk_notice_txt, root_build_dir),
147      "--output-notice-gz",
148      rebase_path(sdk_notice_gz, root_build_dir),
149      "--notice-title",
150      "Notices for files contained in SDK in this directory:",
151      "--static-library-notice-dir",
152      rebase_path(static_libraries_notice_dir, root_build_dir),
153      "--target-cpu",
154      target_cpu,
155      "--depfile",
156      rebase_path(depfile, root_build_dir),
157    ]
158
159    foreach(type, sdk_types) {
160      foreach(os, sdk_systems) {
161        args += [
162          "--collected-notice-zipfile",
163          rebase_path("${sdk_notice_archive_dir}/${os}-${type}.zip",
164                      root_build_dir),
165        ]
166        inputs += [ "${sdk_notice_archive_dir}/${os}-${type}.zip" ]
167      }
168    }
169  }
170
171  action("verify_sdk_notice_file") {
172    deps = [ ":generate_sdk_notice" ]
173
174    script = "//build/core/build_scripts/verify_notice.sh"
175    _verify_result = "${target_out_dir}/sdk_notice_verify_result.out"
176
177    outputs = [ _verify_result ]
178
179    args = [
180      rebase_path(sdk_notice_txt, root_build_dir),
181      rebase_path(_verify_result, root_build_dir),
182      rebase_path("${product_output_dir}/${product_name}", root_build_dir),
183    ]
184  }
185
186  group("ohos_sdk_pre") {
187    deps = []
188    if (enable_process_notice) {
189      deps += [
190        ":generate_sdk_notice",
191        ":verify_sdk_notice_file",
192      ]
193    }
194    deps += [ "${generated_files_dir}:generated_ohos_sdk" ]
195  }
196
197  sdk_delivery_list = "//build/ohos/sdk/sdk_delivery_list.json"
198  action("check_sdk_completeness") {
199    deps = [
200      ":ohos_sdk",
201      "//build/ohos/ndk:ohos_ndk",
202    ]
203    if (host_os == "mac" && enable_sign) {
204      deps += [ ":sign_sdk" ]
205    }
206
207    script = "//build/ohos/sdk/check_sdk_completeness.py"
208    _verify_result = "${target_out_dir}/check_sdk_completeness.txt"
209
210    outputs = [ _verify_result ]
211
212    args = [
213      "--sdk-delivery-list",
214      rebase_path(sdk_delivery_list, root_build_dir),
215      root_build_dir,
216      "--sdk-archive-dir",
217      rebase_path("${product_output_dir}/${product_name}", root_build_dir),
218      product_name,
219      sdk_version,
220      "--sdk-platform",
221      sdk_platform,
222    ]
223  }
224
225  action_with_pydeps("add_notice_file") {
226    deps = [
227      ":generate_sdk_notice",
228      ":ohos_sdk_pre",
229    ]
230    script = "//build/ohos/sdk/add_notice_file.py"
231    _output = target_gen_dir + "/$target_name.stamp"
232    depfile = "$target_gen_dir/$target_name.d"
233    args = [
234      "--sdk-notice-file",
235      rebase_path(sdk_notice_txt, root_build_dir),
236      "--sdk-archive-dir",
237      rebase_path("${product_output_dir}/${product_name}", root_build_dir),
238      "--output",
239      rebase_path(_output, root_build_dir),
240      "--depfile",
241      rebase_path(depfile, root_build_dir),
242      "--skip-pattern",
243      "native",
244    ]
245
246    inputs = [ sdk_notice_txt ]
247    outputs = [ _output ]
248  }
249
250  action("sign_sdk") {
251    deps = [
252      ":ohos_sdk",
253      "//build/ohos/ndk:ohos_ndk",
254    ]
255    script = "//build/scripts/sign_sdk.py"
256    args = [
257      "--sdk-out-dir",
258      rebase_path(ohos_sdk_out_dir, root_build_dir),
259    ]
260    outputs = [ "$target_out_dir/$target_name.stamp" ]
261  }
262
263  group("ohos_sdk") {
264    deps = []
265    if (enable_process_notice) {
266      deps += [ ":add_notice_file" ]
267    }
268    deps += [ ":ohos_sdk_pre" ]
269  }
270
271  group("ohos_sdk_verify") {
272    deps = []
273
274    if (sdk_check_flag) {
275      deps += [ ":check_sdk_completeness" ]
276    }
277  }
278}
279