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("//build/ohos/ndk/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-x86: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 { 178 copy("copy_linux_ohos_cmake") { 179 deps = [ "//prebuilts/cmake/linux-x86: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 copy("copy_windows_ohos_cmake") { 184 deps = [ "//prebuilts/cmake/windows-x86:windows_cmake_copy" ] 185 sources = [ "./OHOS.cmake" ] 186 outputs = [ "$ndk_windows_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ] 187 } 188 copy("copy_ohos_ohos_cmake") { 189 deps = [ "//prebuilts/cmake/ohos:ohos_cmake_copy" ] 190 sources = [ "./OHOS.cmake" ] 191 outputs = [ "$ndk_ohos_tools_out_dir/cmake/share/cmake-3.28/Modules/Platform/{{source_file_part}}" ] 192 } 193} 194 195if (!use_current_sdk) { 196 action_with_pydeps("merge_ndk_notice") { 197 deps = [ ":all_ndk_targets" ] 198 script = "//build/ohos/notice/merge_notice_files.py" 199 depfile = "$target_gen_dir/$target_name.d" 200 201 outputs = [ 202 ndk_notice_txt, 203 ndk_notice_gz, 204 ] 205 206 args = [ 207 "--image-name", 208 "ndk", 209 "--notice-root-dir", 210 rebase_path(ndk_notice_dir, root_build_dir), 211 "--output-notice-txt", 212 rebase_path(ndk_notice_txt, root_build_dir), 213 "--output-notice-gz", 214 rebase_path(ndk_notice_gz, root_build_dir), 215 "--notice-title", 216 "Notices for files and software contained in sdk-native in this directory:", 217 "--target-cpu", 218 target_cpu, 219 "--depfile", 220 rebase_path(depfile, root_build_dir), 221 ] 222 } 223 224 action("verify_ndk_notice_file") { 225 deps = [ ":merge_ndk_notice" ] 226 227 script = "//build/core/build_scripts/verify_notice.sh" 228 _verify_result = "${target_out_dir}/ndk_notice_verify_result.out" 229 230 outputs = [ _verify_result ] 231 232 args = [ 233 rebase_path(ndk_notice_txt, root_build_dir), 234 rebase_path(_verify_result, root_build_dir), 235 rebase_path(target_out_dir, root_build_dir), 236 ] 237 } 238 239 group("archive_ndk") { 240 deps = [] 241 if (ndk_platform == "default") { 242 if (host_os == "mac") { 243 deps += [ ":archive_darwin_ndk" ] 244 } else { 245 deps += [ 246 ":archive_linux_ndk", 247 ":archive_ohos_ndk", 248 ":archive_windows_ndk", 249 ] 250 } 251 } else if (ndk_platform == "win") { 252 deps += [ ":archive_windows_ndk" ] 253 } else if (ndk_platform == "mac") { 254 deps += [ ":archive_darwin_ndk" ] 255 } else if (ndk_platform == "linux") { 256 deps += [ ":archive_linux_ndk" ] 257 } else if (ndk_platform == "ohos") { 258 deps += [ ":archive_ohos_ndk" ] 259 } 260 } 261 262 action_with_pydeps("archive_windows_ndk") { 263 deps = ndk_targets 264 script = "//build/ohos/ndk/archive_ndk.py" 265 depfile = "$target_gen_dir/$target_name.d" 266 _output = "$ohos_sdk_out_dir/${windows_system}/${ndk_zip_prefix}-${windows_system}-${arch}-${current_ndk_version}" 267 if (release_type != "") { 268 _output += "-${release_type}.zip" 269 } else { 270 _output += ".zip" 271 } 272 273 args = [ 274 "--os-irrelevant-dir", 275 rebase_path(ndk_os_irrelevant_out_dir, root_build_dir), 276 "--output", 277 rebase_path(_output, root_build_dir), 278 "--depfile", 279 rebase_path(depfile, root_build_dir), 280 "--os-specific-dir", 281 rebase_path("$ndk_windows_specific_out_dir", root_build_dir), 282 "--notice-file", 283 rebase_path(ndk_notice_txt, root_build_dir), 284 "--prefix", 285 ndk_zip_prefix, 286 "--record-path", 287 rebase_path( 288 "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp", 289 root_build_dir), 290 "--platform", 291 "windows", 292 ] 293 outputs = [ _output ] 294 } 295 296 action_with_pydeps("archive_linux_ndk") { 297 deps = ndk_targets 298 script = "//build/ohos/ndk/archive_ndk.py" 299 depfile = "$target_gen_dir/$target_name.d" 300 _output = "$ohos_sdk_out_dir/${linux_system}/${ndk_zip_prefix}-${linux_system}-${arch}-${current_ndk_version}" 301 if (release_type != "") { 302 _output += "-${release_type}.zip" 303 } else { 304 _output += ".zip" 305 } 306 307 args = [ 308 "--os-irrelevant-dir", 309 rebase_path(ndk_os_irrelevant_out_dir, root_build_dir), 310 "--output", 311 rebase_path(_output, root_build_dir), 312 "--depfile", 313 rebase_path(depfile, root_build_dir), 314 "--notice-file", 315 rebase_path(ndk_notice_txt, root_build_dir), 316 "--os-specific-dir", 317 rebase_path("$ndk_linux_specific_out_dir", root_build_dir), 318 "--prefix", 319 ndk_zip_prefix, 320 "--record-path", 321 rebase_path( 322 "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp", 323 root_build_dir), 324 ] 325 outputs = [ _output ] 326 } 327 328 action_with_pydeps("archive_darwin_ndk") { 329 deps = ndk_targets 330 script = "//build/ohos/ndk/archive_ndk.py" 331 depfile = "$target_gen_dir/$target_name.d" 332 _output = "$ohos_sdk_out_dir/${darwin_system}/${ndk_zip_prefix}-${darwin_system}-${arch}-${current_ndk_version}" 333 if (release_type != "") { 334 _output += "-${release_type}.zip" 335 } else { 336 _output += ".zip" 337 } 338 339 args = [ 340 "--os-irrelevant-dir", 341 rebase_path(ndk_os_irrelevant_out_dir, root_build_dir), 342 "--output", 343 rebase_path(_output, root_build_dir), 344 "--depfile", 345 rebase_path(depfile, root_build_dir), 346 "--notice-file", 347 rebase_path(ndk_notice_txt, root_build_dir), 348 "--os-specific-dir", 349 rebase_path("$ndk_darwin_specific_out_dir", root_build_dir), 350 "--prefix", 351 ndk_zip_prefix, 352 "--record-path", 353 rebase_path( 354 "$target_gen_dir/" + get_path_info(_output, "file") + ".md5.stamp", 355 root_build_dir), 356 ] 357 outputs = [ _output ] 358 } 359} 360 361action_with_pydeps("archive_ohos_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/${ohos_system}/${ndk_zip_prefix}-${ohos_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_ohos_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