• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2025 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/ndk/ndk.gni")
16import("//build/ohos/sdk/sdk.gni")
17
18if (!use_current_sdk) {
19  package_info_name = "oh-uni-package"
20  if (defined(ext_ndk_config_file) && ext_ndk_config_file != "") {
21    ext_ndk_target = rebase_path(ext_ndk_config_file)
22    import(ext_ndk_target)
23    package_info_name = "uni-package"
24  } else {
25    import("//interface/sdk_c/ndk_targets.gni")
26  }
27
28  package_info_file = "$ndk_os_irrelevant_out_dir/$package_info_name.json"
29
30  package_info = {
31    path = "native"
32    displayName = "Native"
33    version = current_ndk_version
34    if (release_type != "") {
35      releaseType = release_type
36    }
37    if (meta_version != "") {
38      meta = {
39        metaVersion = meta_version
40      }
41    }
42    if (defined(ext_ndk_config_file) && ext_ndk_config_file != "") {
43      platformVersion = platform_version
44    }
45    apiVersion = api_version
46  }
47  write_file(package_info_file, package_info, "json")
48
49  action_with_pydeps("_collect_ndk_syscap") {
50    deps = all_ndk_targets_list
51    script = "//build/ohos/ndk/collect_ndk_syscap.py"
52    depfile = "$target_gen_dir/$target_name.d"
53    _ndk_syscap_desc_file =
54        "${ndk_os_irrelevant_out_dir}/ndk_system_capability.json"
55    _native_syscap_config_file =
56        "${ndk_os_irrelevant_out_dir}/nativeapi_syscap_config.json"
57    outputs = [ _ndk_syscap_desc_file ]
58    args = [
59      "--depfile",
60      rebase_path(depfile, root_build_dir),
61      "--system-capability-file",
62      rebase_path(_ndk_syscap_desc_file, root_build_dir),
63      "--system-capability-header-config",
64      rebase_path(_native_syscap_config_file, root_build_dir),
65      "--targets-build-config",
66    ]
67    foreach(_ndk_target, all_ndk_targets_list) {
68      _target_bc_file = get_label_info(_ndk_target, "target_gen_dir") + "/" +
69                        get_label_info(_ndk_target, "name") + ".build_config"
70      args += [ rebase_path(_target_bc_file, root_build_dir) ]
71    }
72  }
73
74  if (!defined(ext_ndk_config_file) || ext_ndk_config_file == "") {
75    action_with_pydeps("_clean_ndk_ani") {
76      deps = [ ":_collect_ndk_syscap" ]
77      script = "//interface/sdk_c/build-tools/clean_ndk_ani.py"
78      outputs = [ "${ndk_os_irrelevant_out_dir}/clean_ndk_ani.json" ]
79      _native_syscap_config_file =
80          "${ndk_os_irrelevant_out_dir}/nativeapi_syscap_config.json"
81      args = [
82        "--ndk-header-path",
83        rebase_path("$ndk_headers_out_dir", root_build_dir),
84        "--system-capability-header-config",
85        rebase_path(_native_syscap_config_file, root_build_dir),
86      ]
87    }
88  }
89
90  group("all_ndk_targets") {
91    deps = [ ":_collect_ndk_syscap" ]
92    if (!defined(ext_ndk_config_file) || ext_ndk_config_file == "") {
93      if (!sdk_build_arkts) {
94        deps += [ ":_clean_ndk_ani" ]
95      }
96    }
97  }
98
99  group("ndk_notice") {
100    deps = []
101    if (enable_process_notice) {
102      deps += [
103        ":merge_ndk_notice",
104        ":verify_ndk_notice_file",
105      ]
106    }
107  }
108
109  ndk_targets = [
110    ":ndk_doxygen",
111    ":all_ndk_targets",
112    ":ndk_notice",
113  ]
114
115  group("ohos_ndk") {
116    deps = ndk_targets
117    if (archive_ndk) {
118      deps += [ ":archive_ndk" ]
119    }
120  }
121
122  group("ndk_doxygen") {
123    deps = []
124    if (enable_ndk_doxygen) {
125      deps += [
126        ":create_docs_portal_and_archive",
127        ":generate_ndk_docs",
128      ]
129    }
130  }
131
132  # doxygen always generates index.html
133  ndk_doxygen_output = "$ndk_docs_out_dir/html"
134  ndk_docs_portal = "$ndk_docs_out_dir/index.html"
135
136  action_with_pydeps("generate_ndk_docs") {
137    deps = [ ":all_ndk_targets" ]
138    script = "//build/ohos/ndk/generate_ndk_docs.py"
139    depfile = "$target_gen_dir/$target_name.d"
140
141    doxygen_file = "//build/ohos/ndk/Doxyfile"
142    inputs = [ doxygen_file ]
143
144    version = current_ndk_version
145    working_dir = "$ndk_headers_out_dir"
146
147    outputs = [ ndk_doxygen_output ]
148
149    args = [
150      "--depfile",
151      rebase_path(depfile, root_build_dir),
152      "--working-dir",
153      rebase_path(working_dir, root_build_dir),
154      "--version",
155      version,
156      "--output",
157      rebase_path(ndk_doxygen_output, root_build_dir),
158      "--doxygen-file",
159      rebase_path(doxygen_file, root_build_dir),
160      "--record-path",
161      rebase_path("$target_gen_dir/" +
162                      get_path_info(ndk_doxygen_output, "file") + ".md5.stamp",
163                  root_build_dir),
164    ]
165  }
166
167  action_with_pydeps("create_docs_portal_and_archive") {
168    deps = [ ":generate_ndk_docs" ]
169    script = "//build/ohos/ndk/create_ndk_docs_portal.py"
170    depfile = "$target_gen_dir/$target_name.d"
171    args = [
172      "--depfile",
173      rebase_path(depfile, root_build_dir),
174      "--doxygen-output",
175      rebase_path(ndk_doxygen_output + "/index.html", root_build_dir),
176      "--record-path",
177      rebase_path("$target_gen_dir/" + get_path_info(ndk_docs_portal, "file") +
178                      ".md5.stamp",
179                  root_build_dir),
180      "--portal-path",
181      rebase_path(ndk_docs_portal, root_build_dir),
182    ]
183    outputs = [ ndk_docs_portal ]
184  }
185}
186
187ohos_ndk_copy("ndk_cmake_files") {
188  dest_dir = "$ndk_os_irrelevant_out_dir/build"
189  sources = [ "./cmake" ]
190}
191
192if (host_os == "mac") {
193  copy("copy_darwin_ohos_cmake") {
194    deps = [ "//prebuilts/cmake/darwin-universal:darwin_cmake_copy" ]
195    sources = [ "./OHOS.cmake" ]
196    outputs = [ "$ndk_darwin_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ]
197  }
198} else if (host_os == "linux" && host_cpu == "arm64") {
199  copy("copy_linux_ohos_cmake") {
200    deps = [ "//prebuilts/cmake/linux-aarch64:linux_cmake_copy" ]
201    sources = [ "./OHOS.cmake" ]
202    outputs = [ "$ndk_linux_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ]
203  }
204} else {
205  copy("copy_linux_ohos_cmake") {
206    deps = [ "//prebuilts/cmake/linux-x86:linux_cmake_copy" ]
207    sources = [ "./OHOS.cmake" ]
208    outputs = [ "$ndk_linux_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ]
209  }
210  copy("copy_windows_ohos_cmake") {
211    deps = [ "//prebuilts/cmake/windows-x86:windows_cmake_copy" ]
212    sources = [ "./OHOS.cmake" ]
213    outputs = [ "$ndk_windows_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ]
214  }
215  copy("copy_ohos_ohos_cmake") {
216    deps = [ "//prebuilts/cmake/ohos:ohos_cmake_copy" ]
217    sources = [ "./OHOS.cmake" ]
218    outputs = [ "$ndk_ohos_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ]
219  }
220}
221
222if (!use_current_sdk) {
223  action_with_pydeps("merge_ndk_notice") {
224    deps = [ ":all_ndk_targets" ]
225    script = "//build/ohos/notice/merge_notice_files.py"
226    depfile = "$target_gen_dir/$target_name.d"
227
228    outputs = [
229      ndk_notice_txt,
230      ndk_notice_gz,
231    ]
232
233    args = [
234      "--image-name",
235      "ndk",
236      "--notice-root-dir",
237      rebase_path(ndk_notice_dir, root_build_dir),
238      "--output-notice-txt",
239      rebase_path(ndk_notice_txt, root_build_dir),
240      "--output-notice-gz",
241      rebase_path(ndk_notice_gz, root_build_dir),
242      "--notice-title",
243      "Notices for files and software contained in sdk-native in this directory:",
244      "--target-cpu",
245      target_cpu,
246      "--depfile",
247      rebase_path(depfile, root_build_dir),
248    ]
249  }
250
251  action("verify_ndk_notice_file") {
252    deps = [ ":merge_ndk_notice" ]
253
254    script = "//build/core/build_scripts/verify_notice.sh"
255    _verify_result = "${target_out_dir}/ndk_notice_verify_result.out"
256
257    outputs = [ _verify_result ]
258
259    args = [
260      rebase_path(ndk_notice_txt, root_build_dir),
261      rebase_path(_verify_result, root_build_dir),
262      rebase_path(target_out_dir, root_build_dir),
263    ]
264  }
265
266  group("archive_ndk") {
267    deps = []
268    if (ndk_platform == "default") {
269      if (host_os == "mac") {
270        deps += [ ":archive_darwin_ndk" ]
271      } else if (host_os == "linux" && host_cpu == "arm64") {
272        deps += [ ":archive_linux_ndk" ]
273      } else {
274        deps += [
275          ":archive_linux_ndk",
276          ":archive_ohos_ndk",
277          ":archive_windows_ndk",
278        ]
279      }
280    }
281    if (build_windows_ndk_target) {
282      deps += [ ":archive_windows_ndk" ]
283    }
284    if (build_mac_ndk_target) {
285      deps += [ ":archive_darwin_ndk" ]
286    }
287    if (build_linux_ndk_target) {
288      deps += [ ":archive_linux_ndk" ]
289    }
290    if (build_ohos_ndk_target) {
291      deps += [ ":archive_ohos_ndk" ]
292    }
293  }
294
295  action_with_pydeps("archive_windows_ndk") {
296    deps = ndk_targets
297    script = "//build/ohos/ndk/archive_ndk.py"
298    depfile = "$target_gen_dir/$target_name.d"
299    _output = "$ohos_sdk_out_dir/${windows_system}/${ndk_zip_prefix}-${windows_system}-${arch}-${current_ndk_version}"
300    if (release_type != "") {
301      _output += "-${release_type}.zip"
302    } else {
303      _output += ".zip"
304    }
305
306    args = [
307      "--os-irrelevant-dir",
308      rebase_path(ndk_os_irrelevant_out_dir, root_build_dir),
309      "--output",
310      rebase_path(_output, root_build_dir),
311      "--depfile",
312      rebase_path(depfile, root_build_dir),
313      "--os-specific-dir",
314      rebase_path("$ndk_windows_specific_out_dir", root_build_dir),
315      "--notice-file",
316      rebase_path(ndk_notice_txt, root_build_dir),
317      "--prefix",
318      ndk_zip_prefix,
319      "--record-path",
320      rebase_path(
321          "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp",
322          root_build_dir),
323      "--platform",
324      "windows",
325    ]
326    outputs = [ _output ]
327  }
328
329  action_with_pydeps("archive_linux_ndk") {
330    deps = ndk_targets
331    script = "//build/ohos/ndk/archive_ndk.py"
332    depfile = "$target_gen_dir/$target_name.d"
333    _output = "$ohos_sdk_out_dir/${linux_system}/${ndk_zip_prefix}-${linux_system}-${arch}-${current_ndk_version}"
334    if (release_type != "") {
335      _output += "-${release_type}.zip"
336    } else {
337      _output += ".zip"
338    }
339
340    args = [
341      "--os-irrelevant-dir",
342      rebase_path(ndk_os_irrelevant_out_dir, root_build_dir),
343      "--output",
344      rebase_path(_output, root_build_dir),
345      "--depfile",
346      rebase_path(depfile, root_build_dir),
347      "--notice-file",
348      rebase_path(ndk_notice_txt, root_build_dir),
349      "--os-specific-dir",
350      rebase_path("$ndk_linux_specific_out_dir", root_build_dir),
351      "--prefix",
352      ndk_zip_prefix,
353      "--record-path",
354      rebase_path(
355          "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp",
356          root_build_dir),
357    ]
358    outputs = [ _output ]
359  }
360
361  action_with_pydeps("archive_darwin_ndk") {
362    deps = ndk_targets
363    script = "//build/ohos/ndk/archive_ndk.py"
364    depfile = "$target_gen_dir/$target_name.d"
365    _output = "$ohos_sdk_out_dir/${darwin_system}/${ndk_zip_prefix}-${darwin_system}-${arch}-${current_ndk_version}"
366    if (release_type != "") {
367      _output += "-${release_type}.zip"
368    } else {
369      _output += ".zip"
370    }
371
372    args = [
373      "--os-irrelevant-dir",
374      rebase_path(ndk_os_irrelevant_out_dir, root_build_dir),
375      "--output",
376      rebase_path(_output, root_build_dir),
377      "--depfile",
378      rebase_path(depfile, root_build_dir),
379      "--notice-file",
380      rebase_path(ndk_notice_txt, root_build_dir),
381      "--os-specific-dir",
382      rebase_path("$ndk_darwin_specific_out_dir", root_build_dir),
383      "--prefix",
384      ndk_zip_prefix,
385      "--record-path",
386      rebase_path(
387          "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp",
388          root_build_dir),
389    ]
390    outputs = [ _output ]
391  }
392
393  action_with_pydeps("archive_ohos_ndk") {
394    deps = ndk_targets
395    script = "//build/ohos/ndk/archive_ndk.py"
396    depfile = "$target_gen_dir/$target_name.d"
397    _output = "$ohos_sdk_out_dir/${ohos_system}/${ndk_zip_prefix}-${ohos_system}-${arch}-${current_ndk_version}"
398    if (release_type != "") {
399      _output += "-${release_type}.zip"
400    } else {
401      _output += ".zip"
402    }
403
404    args = [
405      "--os-irrelevant-dir",
406      rebase_path(ndk_os_irrelevant_out_dir, root_build_dir),
407      "--output",
408      rebase_path(_output, root_build_dir),
409      "--depfile",
410      rebase_path(depfile, root_build_dir),
411      "--notice-file",
412      rebase_path(ndk_notice_txt, root_build_dir),
413      "--os-specific-dir",
414      rebase_path("$ndk_ohos_specific_out_dir", root_build_dir),
415      "--prefix",
416      ndk_zip_prefix,
417      "--record-path",
418      rebase_path(
419          "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp",
420          root_build_dir),
421    ]
422    outputs = [ _output ]
423  }
424}
425