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/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 group("all_ndk_targets") { 75 deps = [ ":_collect_ndk_syscap" ] 76 } 77 78 group("ndk_notice") { 79 deps = [] 80 if (enable_process_notice) { 81 deps += [ 82 ":merge_ndk_notice", 83 ":verify_ndk_notice_file", 84 ] 85 } 86 } 87 88 ndk_targets = [ 89 ":ndk_doxygen", 90 ":all_ndk_targets", 91 ":ndk_notice", 92 ] 93 94 group("ohos_ndk") { 95 deps = ndk_targets 96 if (archive_ndk) { 97 deps += [ ":archive_ndk" ] 98 } 99 } 100 101 group("ndk_doxygen") { 102 deps = [] 103 if (enable_ndk_doxygen) { 104 deps += [ 105 ":create_docs_portal_and_archive", 106 ":generate_ndk_docs", 107 ] 108 } 109 } 110 111 # doxygen always generates index.html 112 ndk_doxygen_output = "$ndk_docs_out_dir/html" 113 ndk_docs_portal = "$ndk_docs_out_dir/index.html" 114 115 action_with_pydeps("generate_ndk_docs") { 116 deps = [ ":all_ndk_targets" ] 117 script = "//build/ohos/ndk/generate_ndk_docs.py" 118 depfile = "$target_gen_dir/$target_name.d" 119 120 doxygen_file = "//build/ohos/ndk/Doxyfile" 121 inputs = [ doxygen_file ] 122 123 version = current_ndk_version 124 working_dir = "$ndk_headers_out_dir" 125 126 outputs = [ ndk_doxygen_output ] 127 128 args = [ 129 "--depfile", 130 rebase_path(depfile, root_build_dir), 131 "--working-dir", 132 rebase_path(working_dir, root_build_dir), 133 "--version", 134 version, 135 "--output", 136 rebase_path(ndk_doxygen_output, root_build_dir), 137 "--doxygen-file", 138 rebase_path(doxygen_file, root_build_dir), 139 "--record-path", 140 rebase_path("$target_gen_dir/" + 141 get_path_info(ndk_doxygen_output, "file") + ".md5.stamp", 142 root_build_dir), 143 ] 144 } 145 146 action_with_pydeps("create_docs_portal_and_archive") { 147 deps = [ ":generate_ndk_docs" ] 148 script = "//build/ohos/ndk/create_ndk_docs_portal.py" 149 depfile = "$target_gen_dir/$target_name.d" 150 args = [ 151 "--depfile", 152 rebase_path(depfile, root_build_dir), 153 "--doxygen-output", 154 rebase_path(ndk_doxygen_output + "/index.html", root_build_dir), 155 "--record-path", 156 rebase_path("$target_gen_dir/" + get_path_info(ndk_docs_portal, "file") + 157 ".md5.stamp", 158 root_build_dir), 159 "--portal-path", 160 rebase_path(ndk_docs_portal, root_build_dir), 161 ] 162 outputs = [ ndk_docs_portal ] 163 } 164} 165 166ohos_ndk_copy("ndk_cmake_files") { 167 dest_dir = "$ndk_os_irrelevant_out_dir/build" 168 sources = [ "./cmake" ] 169} 170 171if (host_os == "mac") { 172 copy("copy_darwin_ohos_cmake") { 173 deps = [ "//prebuilts/cmake/darwin-universal:darwin_cmake_copy" ] 174 sources = [ "./OHOS.cmake" ] 175 outputs = [ "$ndk_darwin_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ] 176 } 177} else if (host_os == "linux" && host_cpu == "arm64") { 178 copy("copy_linux_ohos_cmake") { 179 deps = [ "//prebuilts/cmake/linux-aarch64:linux_cmake_copy" ] 180 sources = [ "./OHOS.cmake" ] 181 outputs = [ "$ndk_linux_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ] 182 } 183} else { 184 copy("copy_linux_ohos_cmake") { 185 deps = [ "//prebuilts/cmake/linux-x86:linux_cmake_copy" ] 186 sources = [ "./OHOS.cmake" ] 187 outputs = [ "$ndk_linux_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ] 188 } 189 copy("copy_windows_ohos_cmake") { 190 deps = [ "//prebuilts/cmake/windows-x86:windows_cmake_copy" ] 191 sources = [ "./OHOS.cmake" ] 192 outputs = [ "$ndk_windows_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ] 193 } 194 copy("copy_ohos_ohos_cmake") { 195 deps = [ "//prebuilts/cmake/ohos:ohos_cmake_copy" ] 196 sources = [ "./OHOS.cmake" ] 197 outputs = [ "$ndk_ohos_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ] 198 } 199} 200 201if (!use_current_sdk) { 202 action_with_pydeps("merge_ndk_notice") { 203 deps = [ ":all_ndk_targets" ] 204 script = "//build/ohos/notice/merge_notice_files.py" 205 depfile = "$target_gen_dir/$target_name.d" 206 207 outputs = [ 208 ndk_notice_txt, 209 ndk_notice_gz, 210 ] 211 212 args = [ 213 "--image-name", 214 "ndk", 215 "--notice-root-dir", 216 rebase_path(ndk_notice_dir, root_build_dir), 217 "--output-notice-txt", 218 rebase_path(ndk_notice_txt, root_build_dir), 219 "--output-notice-gz", 220 rebase_path(ndk_notice_gz, root_build_dir), 221 "--notice-title", 222 "Notices for files and software contained in sdk-native in this directory:", 223 "--target-cpu", 224 target_cpu, 225 "--depfile", 226 rebase_path(depfile, root_build_dir), 227 ] 228 } 229 230 action("verify_ndk_notice_file") { 231 deps = [ ":merge_ndk_notice" ] 232 233 script = "//build/core/build_scripts/verify_notice.sh" 234 _verify_result = "${target_out_dir}/ndk_notice_verify_result.out" 235 236 outputs = [ _verify_result ] 237 238 args = [ 239 rebase_path(ndk_notice_txt, root_build_dir), 240 rebase_path(_verify_result, root_build_dir), 241 rebase_path(target_out_dir, root_build_dir), 242 ] 243 } 244 245 group("archive_ndk") { 246 deps = [] 247 if (ndk_platform == "default") { 248 if (host_os == "mac") { 249 deps += [ ":archive_darwin_ndk" ] 250 } else if (host_os == "linux" && host_cpu == "arm64") { 251 deps += [ ":archive_linux_ndk" ] 252 } else { 253 deps += [ 254 ":archive_linux_ndk", 255 ":archive_ohos_ndk", 256 ":archive_windows_ndk", 257 ] 258 } 259 } 260 if (build_windows_ndk_target) { 261 deps += [ ":archive_windows_ndk" ] 262 } 263 if (build_mac_ndk_target) { 264 deps += [ ":archive_darwin_ndk" ] 265 } 266 if (build_linux_ndk_target) { 267 deps += [ ":archive_linux_ndk" ] 268 } 269 if (build_ohos_ndk_target) { 270 deps += [ ":archive_ohos_ndk" ] 271 } 272 } 273 274 action_with_pydeps("archive_windows_ndk") { 275 deps = ndk_targets 276 script = "//build/ohos/ndk/archive_ndk.py" 277 depfile = "$target_gen_dir/$target_name.d" 278 _output = "$ohos_sdk_out_dir/${windows_system}/${ndk_zip_prefix}-${windows_system}-${arch}-${current_ndk_version}" 279 if (release_type != "") { 280 _output += "-${release_type}.zip" 281 } else { 282 _output += ".zip" 283 } 284 285 args = [ 286 "--os-irrelevant-dir", 287 rebase_path(ndk_os_irrelevant_out_dir, root_build_dir), 288 "--output", 289 rebase_path(_output, root_build_dir), 290 "--depfile", 291 rebase_path(depfile, root_build_dir), 292 "--os-specific-dir", 293 rebase_path("$ndk_windows_specific_out_dir", root_build_dir), 294 "--notice-file", 295 rebase_path(ndk_notice_txt, root_build_dir), 296 "--prefix", 297 ndk_zip_prefix, 298 "--record-path", 299 rebase_path( 300 "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp", 301 root_build_dir), 302 "--platform", 303 "windows", 304 ] 305 outputs = [ _output ] 306 } 307 308 action_with_pydeps("archive_linux_ndk") { 309 deps = ndk_targets 310 script = "//build/ohos/ndk/archive_ndk.py" 311 depfile = "$target_gen_dir/$target_name.d" 312 _output = "$ohos_sdk_out_dir/${linux_system}/${ndk_zip_prefix}-${linux_system}-${arch}-${current_ndk_version}" 313 if (release_type != "") { 314 _output += "-${release_type}.zip" 315 } else { 316 _output += ".zip" 317 } 318 319 args = [ 320 "--os-irrelevant-dir", 321 rebase_path(ndk_os_irrelevant_out_dir, root_build_dir), 322 "--output", 323 rebase_path(_output, root_build_dir), 324 "--depfile", 325 rebase_path(depfile, root_build_dir), 326 "--notice-file", 327 rebase_path(ndk_notice_txt, root_build_dir), 328 "--os-specific-dir", 329 rebase_path("$ndk_linux_specific_out_dir", root_build_dir), 330 "--prefix", 331 ndk_zip_prefix, 332 "--record-path", 333 rebase_path( 334 "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp", 335 root_build_dir), 336 ] 337 outputs = [ _output ] 338 } 339 340 action_with_pydeps("archive_darwin_ndk") { 341 deps = ndk_targets 342 script = "//build/ohos/ndk/archive_ndk.py" 343 depfile = "$target_gen_dir/$target_name.d" 344 _output = "$ohos_sdk_out_dir/${darwin_system}/${ndk_zip_prefix}-${darwin_system}-${arch}-${current_ndk_version}" 345 if (release_type != "") { 346 _output += "-${release_type}.zip" 347 } else { 348 _output += ".zip" 349 } 350 351 args = [ 352 "--os-irrelevant-dir", 353 rebase_path(ndk_os_irrelevant_out_dir, root_build_dir), 354 "--output", 355 rebase_path(_output, root_build_dir), 356 "--depfile", 357 rebase_path(depfile, root_build_dir), 358 "--notice-file", 359 rebase_path(ndk_notice_txt, root_build_dir), 360 "--os-specific-dir", 361 rebase_path("$ndk_darwin_specific_out_dir", root_build_dir), 362 "--prefix", 363 ndk_zip_prefix, 364 "--record-path", 365 rebase_path( 366 "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp", 367 root_build_dir), 368 ] 369 outputs = [ _output ] 370 } 371 372 action_with_pydeps("archive_ohos_ndk") { 373 deps = ndk_targets 374 script = "//build/ohos/ndk/archive_ndk.py" 375 depfile = "$target_gen_dir/$target_name.d" 376 _output = "$ohos_sdk_out_dir/${ohos_system}/${ndk_zip_prefix}-${ohos_system}-${arch}-${current_ndk_version}" 377 if (release_type != "") { 378 _output += "-${release_type}.zip" 379 } else { 380 _output += ".zip" 381 } 382 383 args = [ 384 "--os-irrelevant-dir", 385 rebase_path(ndk_os_irrelevant_out_dir, root_build_dir), 386 "--output", 387 rebase_path(_output, root_build_dir), 388 "--depfile", 389 rebase_path(depfile, root_build_dir), 390 "--notice-file", 391 rebase_path(ndk_notice_txt, root_build_dir), 392 "--os-specific-dir", 393 rebase_path("$ndk_ohos_specific_out_dir", root_build_dir), 394 "--prefix", 395 ndk_zip_prefix, 396 "--record-path", 397 rebase_path( 398 "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp", 399 root_build_dir), 400 ] 401 outputs = [ _output ] 402 } 403} 404