• 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/ndk/ndk.gni")
16import("//build/ohos/ndk/ndk_targets.gni")
17import("//build/ohos/sdk/sdk.gni")
18
19package_info_file = "$ndk_os_irrelevant_out_dir/oh-uni-package.json"
20
21package_info = {
22  path = "native"
23  displayName = "Native"
24  version = current_ndk_version
25  if (release_type != "") {
26    releaseType = release_type
27  }
28  if (meta_version != "") {
29    meta = {
30      metaVersion = meta_version
31    }
32  }
33  apiVersion = api_version
34}
35write_file(package_info_file, package_info, "json")
36
37action_with_pydeps("_collect_ndk_syscap") {
38  deps = all_ndk_targets_list
39  script = "//build/ohos/ndk/collect_ndk_syscap.py"
40  depfile = "$target_gen_dir/$target_name.d"
41  _ndk_syscap_desc_file =
42      "${ndk_os_irrelevant_out_dir}/ndk_system_capability.json"
43  _native_syscap_config_file =
44      "${ndk_os_irrelevant_out_dir}/nativeapi_syscap_config.json"
45  outputs = [ _ndk_syscap_desc_file ]
46  args = [
47    "--depfile",
48    rebase_path(depfile, root_build_dir),
49    "--system-capability-file",
50    rebase_path(_ndk_syscap_desc_file, root_build_dir),
51    "--system-capability-header-config",
52    rebase_path(_native_syscap_config_file, root_build_dir),
53    "--targets-build-config",
54  ]
55  foreach(_ndk_target, all_ndk_targets_list) {
56    _target_bc_file = get_label_info(_ndk_target, "target_gen_dir") + "/" +
57                      get_label_info(_ndk_target, "name") + ".build_config"
58    args += [ rebase_path(_target_bc_file, root_build_dir) ]
59  }
60}
61
62group("all_ndk_targets") {
63  deps = [ ":_collect_ndk_syscap" ]
64}
65
66ndk_targets = [
67  ":ndk_doxygen",
68  ":ndk_cmake_files",
69  ":all_ndk_targets",
70  ":merge_ndk_notice",
71  ":verify_ndk_notice_file",
72]
73
74if (ndk_system == "win") {
75  ndk_targets += [ "//third_party/musl/ndk_script:windows_x86_64" ]
76} else if (ndk_system == "mac") {
77  if (host_cpu == "arm64") {
78    ndk_targets += [ "//third_party/musl/ndk_script:darwin_arm64" ]
79  } else {
80    ndk_targets += [ "//third_party/musl/ndk_script:darwin_x86_64" ]
81  }
82} else if (ndk_system == "linux") {
83  ndk_targets += [ "//third_party/musl/ndk_script:linux_x86_64" ]
84} else if (ndk_system == "default") {
85  if (host_os == "mac") {
86    if (host_cpu == "arm64") {
87      ndk_targets += [ "//third_party/musl/ndk_script:darwin_arm64" ]
88    } else {
89      ndk_targets += [ "//third_party/musl/ndk_script:darwin_x86_64" ]
90    }
91  } else {
92    ndk_targets += [
93      "//third_party/musl/ndk_script:windows_x86_64",
94      "//third_party/musl/ndk_script:linux_x86_64",
95    ]
96  }
97}
98
99group("ohos_ndk") {
100  deps = ndk_targets
101  if (archive_ndk) {
102    deps += [ ":archive_ndk" ]
103  }
104}
105
106group("ndk_doxygen") {
107  deps = [
108    ":create_docs_portal_and_archive",
109    ":generate_ndk_docs",
110  ]
111}
112
113# doxygen always generates index.html
114ndk_doxygen_output = "$ndk_docs_out_dir/html"
115ndk_docs_portal = "$ndk_docs_out_dir/index.html"
116
117action_with_pydeps("generate_ndk_docs") {
118  deps = [ ":all_ndk_targets" ]
119  script = "//build/ohos/ndk/generate_ndk_docs.py"
120  depfile = "$target_gen_dir/$target_name.d"
121
122  doxygen_file = "//build/ohos/ndk/Doxyfile"
123  inputs = [ doxygen_file ]
124
125  version = current_ndk_version
126  working_dir = "$ndk_headers_out_dir"
127
128  outputs = [ ndk_doxygen_output ]
129
130  args = [
131    "--depfile",
132    rebase_path(depfile, root_build_dir),
133    "--working-dir",
134    rebase_path(working_dir, root_build_dir),
135    "--version",
136    version,
137    "--output",
138    rebase_path(ndk_doxygen_output, root_build_dir),
139    "--doxygen-file",
140    rebase_path(doxygen_file, root_build_dir),
141    "--record-path",
142    rebase_path("$target_gen_dir/" + get_path_info(ndk_doxygen_output, "file") +
143                    ".md5.stamp",
144                root_build_dir),
145  ]
146}
147
148action_with_pydeps("create_docs_portal_and_archive") {
149  deps = [ ":generate_ndk_docs" ]
150  script = "//build/ohos/ndk/create_ndk_docs_portal.py"
151  depfile = "$target_gen_dir/$target_name.d"
152  args = [
153    "--depfile",
154    rebase_path(depfile, root_build_dir),
155    "--doxygen-output",
156    rebase_path(ndk_doxygen_output + "/index.html", root_build_dir),
157    "--record-path",
158    rebase_path("$target_gen_dir/" + get_path_info(ndk_docs_portal, "file") +
159                    ".md5.stamp",
160                root_build_dir),
161    "--portal-path",
162    rebase_path(ndk_docs_portal, root_build_dir),
163  ]
164  outputs = [ ndk_docs_portal ]
165}
166
167ohos_ndk_copy("ndk_cmake_files") {
168  dest_dir = "$ndk_os_irrelevant_out_dir/build"
169  sources = [ "./cmake" ]
170}
171
172action_with_pydeps("merge_ndk_notice") {
173  deps = [ ":all_ndk_targets" ]
174  script = "//build/ohos/notice/merge_notice_files.py"
175  depfile = "$target_gen_dir/$target_name.d"
176
177  outputs = [
178    ndk_notice_txt,
179    ndk_notice_gz,
180  ]
181
182  args = [
183    "--image-name",
184    "ndk",
185    "--notice-root-dir",
186    rebase_path(ndk_notice_dir, root_build_dir),
187    "--output-notice-txt",
188    rebase_path(ndk_notice_txt, root_build_dir),
189    "--output-notice-gz",
190    rebase_path(ndk_notice_gz, root_build_dir),
191    "--notice-title",
192    "Notices for files and software contained in sdk-native in this directory:",
193    "--static-library-notice-dir",
194    rebase_path(static_libraries_notice_dir, root_build_dir),
195    "--target-cpu",
196    target_cpu,
197    "--depfile",
198    rebase_path(depfile, root_build_dir),
199  ]
200}
201
202action("verify_ndk_notice_file") {
203  deps = [ ":merge_ndk_notice" ]
204
205  script = "//build/core/build_scripts/verify_notice.sh"
206  _verify_result = "${target_out_dir}/ndk_notice_verify_result.out"
207
208  outputs = [ _verify_result ]
209
210  args = [
211    rebase_path(ndk_notice_txt, root_build_dir),
212    rebase_path(_verify_result, root_build_dir),
213    rebase_path(target_out_dir, root_build_dir),
214  ]
215}
216
217group("archive_ndk") {
218  deps = []
219  if (ndk_system == "default") {
220    if (host_os == "mac") {
221      deps += [ ":archive_darwin_ndk" ]
222    } else {
223      deps += [
224        ":archive_linux_ndk",
225        ":archive_windows_ndk",
226      ]
227    }
228  } else if (ndk_system == "win") {
229    deps += [ ":archive_windows_ndk" ]
230  } else if (ndk_system == "mac") {
231    deps += [ ":archive_darwin_ndk" ]
232  } else if (ndk_system == "linux") {
233    deps += [ ":archive_linux_ndk" ]
234  }
235}
236
237action_with_pydeps("archive_windows_ndk") {
238  deps = ndk_targets
239  script = "//build/ohos/ndk/archive_ndk.py"
240  depfile = "$target_gen_dir/$target_name.d"
241  _output = "$ohos_sdk_out_dir/${windows_system}/${ndk_zip_prefix}-${windows_system}-${arch}-${current_ndk_version}"
242  if (release_type != "") {
243    _output += "-${release_type}.zip"
244  } else {
245    _output += ".zip"
246  }
247
248  args = [
249    "--os-irrelevant-dir",
250    rebase_path(ndk_os_irrelevant_out_dir, root_build_dir),
251    "--output",
252    rebase_path(_output, root_build_dir),
253    "--depfile",
254    rebase_path(depfile, root_build_dir),
255    "--os-specific-dir",
256    rebase_path("$ndk_windows_specific_out_dir", root_build_dir),
257    "--notice-file",
258    rebase_path(ndk_notice_txt, root_build_dir),
259    "--prefix",
260    ndk_zip_prefix,
261    "--record-path",
262    rebase_path(
263        "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp",
264        root_build_dir),
265  ]
266  outputs = [ _output ]
267}
268
269action_with_pydeps("archive_linux_ndk") {
270  deps = ndk_targets
271  script = "//build/ohos/ndk/archive_ndk.py"
272  depfile = "$target_gen_dir/$target_name.d"
273  _output = "$ohos_sdk_out_dir/${linux_system}/${ndk_zip_prefix}-${linux_system}-${arch}-${current_ndk_version}"
274  if (release_type != "") {
275    _output += "-${release_type}.zip"
276  } else {
277    _output += ".zip"
278  }
279
280  args = [
281    "--os-irrelevant-dir",
282    rebase_path(ndk_os_irrelevant_out_dir, root_build_dir),
283    "--output",
284    rebase_path(_output, root_build_dir),
285    "--depfile",
286    rebase_path(depfile, root_build_dir),
287    "--notice-file",
288    rebase_path(ndk_notice_txt, root_build_dir),
289    "--os-specific-dir",
290    rebase_path("$ndk_linux_specific_out_dir", root_build_dir),
291    "--prefix",
292    ndk_zip_prefix,
293    "--record-path",
294    rebase_path(
295        "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp",
296        root_build_dir),
297  ]
298  outputs = [ _output ]
299}
300
301action_with_pydeps("archive_darwin_ndk") {
302  deps = ndk_targets
303  script = "//build/ohos/ndk/archive_ndk.py"
304  depfile = "$target_gen_dir/$target_name.d"
305  _output = "$ohos_sdk_out_dir/${darwin_system}/${ndk_zip_prefix}-${darwin_system}-${arch}-${current_ndk_version}"
306  if (release_type != "") {
307    _output += "-${release_type}.zip"
308  } else {
309    _output += ".zip"
310  }
311
312  args = [
313    "--os-irrelevant-dir",
314    rebase_path(ndk_os_irrelevant_out_dir, root_build_dir),
315    "--output",
316    rebase_path(_output, root_build_dir),
317    "--depfile",
318    rebase_path(depfile, root_build_dir),
319    "--notice-file",
320    rebase_path(ndk_notice_txt, root_build_dir),
321    "--os-specific-dir",
322    rebase_path("$ndk_darwin_specific_out_dir", root_build_dir),
323    "--prefix",
324    ndk_zip_prefix,
325    "--record-path",
326    rebase_path(
327        "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp",
328        root_build_dir),
329  ]
330  outputs = [ _output ]
331}
332