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/sa_profile/sa_profile.gni") 16 17import("//build/ohos.gni") 18import("//build/ohos/build_var.gni") 19import("//build/ohos_var.gni") 20 21import("//build/ohos/hisysevent/hisysevent.gni") 22 23# import target_platform_list 24import("${build_configs_path}/platforms_list.gni") 25yml_file = rebase_path(product_path) + "/fs.yml" 26is_exist_yml_file = exec_script(rebase_path("//build/ohos/file_exists.py"), 27 [ 28 "--filename", 29 yml_file, 30 "--type", 31 "file", 32 ], 33 "string") 34 35group("make_packages") { 36 deps = [] 37 foreach(_platform, target_platform_list) { 38 if (is_standard_system && !skip_gen_module_info) { 39 # Lite system uses different packaging scheme, which is called in hb. 40 # So skip install_modules for lite system since it's the packaging 41 # action of standard system. 42 43 deps += [ ":${_platform}_install_modules" ] 44 } 45 if (!skip_gen_module_info) { 46 deps += [ ":gen_required_modules_${_platform}" ] 47 } 48 deps += [ ":${_platform}_parts_list" ] 49 if (!is_standard_system) { 50 deps += [ ":merge_system_notice_file_${_platform}" ] 51 } 52 } 53 if (make_osp) { 54 deps += [ ":open_source_package" ] 55 } 56} 57 58action("packer") { 59 script = rebase_path("//build/ohos/packages/fs_process.py") 60 if (is_exist_yml_file == "True") { 61 inputs = [ yml_file ] 62 } 63 outputs = [ "${root_build_dir}/result.txt" ] 64 deps = [ ":make_packages" ] 65 args = [ 66 "--product", 67 product_name, 68 "--root-path", 69 rebase_path("//"), 70 "--out-path", 71 rebase_path(root_build_dir), 72 "--log-path", 73 rebase_path("${root_build_dir}/build.log"), 74 "--product-path", 75 rebase_path(product_path), 76 ] 77} 78 79all_parts_host_info_file = "${root_build_dir}/all_parts_host.json" 80all_host_symlink_file = "${root_build_dir}/all_host_symlink.json" 81 82action("generate_host_symlink") { 83 script = "//build/ohos/packages/generate_host_symlink.py" 84 inputs = [ all_parts_host_info_file ] 85 outputs = [ all_host_symlink_file ] 86 deps = [ "//build/ohos/common:generate_host_info" ] 87 args = [ 88 "--all-parts-host-info-file", 89 rebase_path(all_parts_host_info_file), 90 "--output-file", 91 rebase_path(all_host_symlink_file), 92 "--root-build-dir", 93 rebase_path(root_build_dir), 94 ] 95} 96 97all_parts_info_file = "${root_build_dir}/all_parts_info.json" 98all_platforms_parts = 99 "${root_build_dir}/build_configs/target_platforms_parts.json" 100 101foreach(_platform, target_platform_list) { 102 current_platform = _platform 103 current_platform_dir = "${product_output_dir}/$current_platform" 104 105 _system_install_info_file = 106 "${current_platform_dir}/system_install_parts.json" 107 108 action_with_pydeps("${current_platform}_parts_list") { 109 script = "//build/ohos/packages/parts_install_info.py" 110 deps = [ "//build/ohos/common:merge_all_parts" ] 111 inputs = [ all_parts_info_file ] 112 outputs = [ _system_install_info_file ] 113 depfile = "$target_gen_dir/$target_name.d" 114 args = [ 115 "--depfile", 116 rebase_path(depfile, root_build_dir), 117 "--all-parts-info-file", 118 rebase_path(all_parts_info_file, root_build_dir), 119 "--platforms-parts-file", 120 rebase_path(all_platforms_parts, root_build_dir), 121 "--system-install-info-file", 122 rebase_path(_system_install_info_file, root_build_dir), 123 "--current-platform", 124 current_platform, 125 "--root-code-dir", 126 rebase_path("//"), 127 "--root-build-dir", 128 root_build_dir, 129 ] 130 } 131 132 post_process_modules_list = [] 133 134 # sa profile install 135 sa_install_modules_info_file = 136 "${current_platform_dir}/sa_profile/sa_install_info.json" 137 _merged_sa_profile_zipfile = 138 "${current_platform_dir}/sa_profile/merged_sa_profile.zip" 139 _merged_sa_profile_dir = "${current_platform_dir}/sa_profile/merged_sa" 140 ohos_sa_install_info("${current_platform}_sa_profile_install_info") { 141 deps = [ ":${current_platform}_parts_list" ] 142 _outputs = get_target_outputs(":${current_platform}_parts_list") 143 system_install_info_file = _outputs[0] 144 sa_install_info_file = sa_install_modules_info_file 145 merged_sa_profile_zipfile = _merged_sa_profile_zipfile 146 merged_sa_profile_dir = _merged_sa_profile_dir 147 } 148 149 # all post process moudles info 150 post_process_modules_list += [ sa_install_modules_info_file ] 151 152 hisysevent_install_info_file = 153 "${current_platform_dir}/hisysevent/hisysevent_install_info.json" 154 ohos_hisysevent_install_info("${current_platform}_hisysevent_install_info") { 155 deps = [ ":${current_platform}_parts_list" ] 156 _outputs = get_target_outputs(":${current_platform}_parts_list") 157 system_install_info_file = _outputs[0] 158 } 159 post_process_modules_list += [ hisysevent_install_info_file ] 160 161 _notice_root_dir = "${current_platform_dir}/NOTICE_FILES" 162 _collected_notice_zipfile = "${current_platform_dir}/system_notice_files.zip" 163 164 action_with_pydeps("collect_notice_files__${_platform}") { 165 deps = [ ":${_platform}_parts_list" ] 166 script = "//build/ohos/notice/collect_system_notice_files.py" 167 depfile = "$target_gen_dir/$target_name.d" 168 sources = [ _system_install_info_file ] 169 outputs = [ _collected_notice_zipfile ] 170 args = [ 171 "--install-info-file", 172 rebase_path(_system_install_info_file, root_build_dir), 173 "--output-file", 174 rebase_path(_collected_notice_zipfile, root_build_dir), 175 "--depfile", 176 rebase_path(depfile, root_build_dir), 177 "--notice-root-dir", 178 rebase_path(_notice_root_dir, root_build_dir), 179 ] 180 } 181 182 _merged_notice_txt = "${current_platform_dir}/NOTICE.txt" 183 _notice_module_info_file = "${current_platform_dir}/NOTICE_module_info.json" 184 action_with_pydeps("merge_system_notice_file_${current_platform}") { 185 deps = [ ":collect_notice_files__${current_platform}" ] 186 script = "//build/ohos/notice/merge_notice_files.py" 187 depfile = "$target_gen_dir/$target_name.d" 188 189 _merged_notice_gz = "${current_platform_dir}/NOTICE.xml.gz" 190 inputs = [ _collected_notice_zipfile ] 191 outputs = [ 192 _merged_notice_txt, 193 _merged_notice_gz, 194 _notice_module_info_file, 195 ] 196 args = [ 197 "--image-name", 198 "system", 199 "--notice-root-dir", 200 rebase_path(_notice_root_dir, root_build_dir), 201 "--output-notice-txt", 202 rebase_path(_merged_notice_txt, root_out_dir), 203 "--output-notice-gz", 204 rebase_path(_merged_notice_gz, root_out_dir), 205 "--notice-title", 206 "Notices for files contained in the system filesystem image in this directory:", 207 "--static-library-notice-dir", 208 rebase_path(static_libraries_notice_dir, root_build_dir), 209 "--target-cpu", 210 target_cpu, 211 "--depfile", 212 rebase_path(depfile, root_build_dir), 213 "--collected-notice-zipfile", 214 rebase_path(_collected_notice_zipfile, root_build_dir), 215 "--notice-module-info", 216 rebase_path(_notice_module_info_file, root_build_dir), 217 "--notice-install-dir", 218 ] 219 if (is_system_component) { 220 args += [ "system/etc" ] 221 } else { 222 args += [ "vendor/etc" ] 223 } 224 if (!is_standard_system) { 225 args += [ 226 "--lite-product", 227 "true", 228 ] 229 } 230 } 231 post_process_modules_list += [ _notice_module_info_file ] 232 233 action("verify_notice_file_${current_platform}") { 234 deps = [ ":merge_system_notice_file_${current_platform}" ] 235 script = "//build/lite/run_shell_cmd.py" 236 _verify_result = "${current_platform_dir}/notice_verify_result.out" 237 238 inputs = [ _merged_notice_txt ] 239 outputs = [ _verify_result ] 240 241 args = [ 242 "/bin/bash", 243 rebase_path("//build/core/build_scripts/verify_notice.sh", 244 root_build_dir), 245 rebase_path(_merged_notice_txt, root_build_dir), 246 rebase_path(_verify_result, root_build_dir), 247 rebase_path(current_platform_dir, root_build_dir), 248 ] 249 } 250 251 system_install_modules = "${current_platform_dir}/system_install_modules.json" 252 system_module_info_list = "${current_platform_dir}/system_module_info.json" 253 system_modules_list = "${current_platform_dir}/system_modules_list.txt" 254 _system_image_zipfile = "${current_platform_dir}/system.zip" 255 _host_toolchain = "$host_toolchain" 256 257 action_with_pydeps("${_platform}_install_modules") { 258 script = "//build/ohos/packages/modules_install.py" 259 public_deps = [ ":${current_platform}_parts_list" ] 260 depfile = "$target_gen_dir/$target_name.d" 261 deps = [ 262 ":${current_platform}_hisysevent_install_info", 263 ":${current_platform}_sa_profile_install_info", 264 ":generate_host_symlink", 265 ":merge_system_notice_file_${current_platform}", 266 ":verify_notice_file_${current_platform}", 267 ] 268 269 sources = [ 270 _merged_sa_profile_zipfile, 271 _system_install_info_file, 272 ] 273 274 outputs = [ 275 system_install_modules, 276 system_module_info_list, 277 system_modules_list, 278 _system_image_zipfile, 279 ] 280 281 args = [ 282 "--system-install-info-file", 283 rebase_path(_system_install_info_file, root_build_dir), 284 "--install-modules-info-file", 285 rebase_path(system_install_modules, root_build_dir), 286 "--modules-info-file", 287 rebase_path(system_module_info_list, root_build_dir), 288 "--modules-list-file", 289 rebase_path(system_modules_list, root_build_dir), 290 "--platform-installed-path", 291 rebase_path(current_platform_dir, root_build_dir), 292 "--depfile", 293 rebase_path(depfile, root_build_dir), 294 "--sa-profile-extract-dir", 295 rebase_path(_merged_sa_profile_dir, root_build_dir), 296 "--merged-sa-profile", 297 rebase_path(_merged_sa_profile_zipfile, root_build_dir), 298 "--system-dir", 299 rebase_path("$current_platform_dir/system", root_build_dir), 300 "--system-image-zipfile", 301 rebase_path(_system_image_zipfile, root_build_dir), 302 "--host-toolchain", 303 _host_toolchain, 304 ] 305 306 _additional_system_files = [] 307 foreach(tuple, _additional_system_files) { 308 args += [ 309 "--additional-system-files", 310 rebase_path(tuple[0], root_build_dir) + ":" + tuple[1], 311 ] 312 } 313 314 if (post_process_modules_list != []) { 315 sources += post_process_modules_list 316 args += [ "--post-process-modules-info-files" ] 317 args += rebase_path(post_process_modules_list, root_build_dir) 318 } 319 320 args += [ "--categorized-libraries" ] 321 args += 322 [ rebase_path("//build/ohos/packages/rules/categorized-libraries.json", 323 root_build_dir) ] 324 } 325 326 action("check_seccomp_filter_name") { 327 script = "//build/ohos/packages/check_seccomp_library_name.py" 328 deps = [ ":${_platform}_install_modules" ] 329 330 # result is not used in script 331 process_validate_result = 332 "${current_platform_dir}/check_seccomp_filter_name.txt" 333 _system_cfg_folder = "${current_platform_dir}/system/etc/init" 334 if (target_cpu == "arm" || target_cpu == "x86") { 335 libdir = "lib" 336 } else if (target_cpu == "arm64" || target_cpu == "x86_64") { 337 libdir = "lib64" 338 } else { 339 libdir = "lib" 340 } 341 _system_seccomp_folder = "${current_platform_dir}/system/${libdir}/seccomp" 342 343 _vendor_cfg_folder = "${current_platform_dir}/vendor/etc/init" 344 _vendor_seccomp_folder = "${current_platform_dir}/vendor/${libdir}/seccomp" 345 346 outputs = [ process_validate_result ] 347 348 args = [ 349 "--vendor-cfg-path", 350 rebase_path(_vendor_cfg_folder, root_build_dir), 351 "--vendor-seccomp-lib-path", 352 rebase_path(_vendor_seccomp_folder, root_build_dir), 353 "--system-cfg-path", 354 rebase_path(_system_cfg_folder, root_build_dir), 355 "--system-seccomp-lib-path", 356 rebase_path(_system_seccomp_folder, root_build_dir), 357 ] 358 } 359 360 action("process_field_validate") { 361 script = "//build/ohos/packages/process_field_validate.py" 362 363 deps = [ ":${_platform}_install_modules" ] 364 365 # result is not used in script 366 process_validate_result = "${current_platform_dir}/cfg_validate_result.txt" 367 368 # ext_root_proc_conf_path defined in config.json in vendor warehouse 369 if (ext_root_proc_conf_path != "") { 370 _privilege_whitelist = ext_root_proc_conf_path 371 } else { 372 _privilege_whitelist = "//vendor/${product_company}/${product_name}/security_config/high_privilege_process_list.json" 373 } 374 375 # ext_critical_proc_conf_path defined in config.json in vendor warehouse 376 if (ext_critical_proc_conf_path != "") { 377 _critical_whitelist = ext_critical_proc_conf_path 378 } else { 379 _critical_whitelist = "//vendor/${product_company}/${product_name}/security_config/critical_reboot_process_list.json" 380 } 381 _system_cfg_folder = "${current_platform_dir}/system/etc/init" 382 383 _vendor_cfg_folder = "${current_platform_dir}/vendor/etc/init" 384 385 outputs = [ process_validate_result ] 386 387 args = [ 388 "--sys-cfg-folder", 389 rebase_path(_system_cfg_folder, root_build_dir), 390 "--vendor-cfg-folder", 391 rebase_path(_vendor_cfg_folder, root_build_dir), 392 "--high-privilege-process-list-path", 393 rebase_path(_privilege_whitelist, root_build_dir), 394 "--critical-reboot-process-list-path", 395 rebase_path(_critical_whitelist, root_build_dir), 396 ] 397 } 398} 399 400# required_install_module_list.json 401foreach(_platform, target_platform_list) { 402 current_platform_dir = "${product_output_dir}/$_platform" 403 _system_install_info_file = 404 "${current_platform_dir}/system_install_parts.json" 405 required_install_modules_file = 406 "${current_platform_dir}/required_install_module_list.json" 407 action_with_pydeps("gen_required_modules_${_platform}") { 408 deps = [ ":${_platform}_parts_list" ] 409 script = "//build/ohos/packages/gen_required_modules_list.py" 410 inputs = [ _system_install_info_file ] 411 outputs = [ required_install_modules_file ] 412 depfile = "$target_gen_dir/$target_name.d" 413 args = [ 414 "--system-installed-info-file", 415 rebase_path(_system_install_info_file, root_out_dir), 416 "--required-install-modules-file", 417 rebase_path(required_install_modules_file, root_out_dir), 418 "--depfile", 419 rebase_path(depfile, root_build_dir), 420 ] 421 } 422} 423 424if (is_asan || is_tsan) { 425 foreach(_platform, target_platform_list) { 426 action("restore_first_stage_artifact_${_platform}") { 427 current_platform = _platform 428 current_platform_dir = "${product_output_dir}/$current_platform" 429 deps = [ ":${_platform}_install_modules" ] 430 print("restore_first_stage_artifact_${_platform}") 431 432 if (current_cpu == "arm64" || current_cpu == "riscv64") { 433 module_type = "lib64" 434 } else if (current_cpu == "arm") { 435 module_type = "lib" 436 } 437 438 sources_dir = [ 439 "${root_build_dir}/backup/packages/${_platform}/system/$module_type", 440 "${root_build_dir}/backup/packages/${_platform}/system/bin", 441 ] 442 443 restore_dir = "${current_platform_dir}/${system_base_dir}/restore" 444 445 outputs = [ restore_dir ] 446 447 script = "//build/ohos/packages/backup_restore_artifact.py" 448 args = [ "--source-dir" ] 449 foreach(source_dir, sources_dir) { 450 args += [ rebase_path(source_dir, root_out_dir) ] 451 } 452 453 args += [ 454 "--output-dir", 455 rebase_path(restore_dir, root_out_dir), 456 ] 457 } 458 459 action("restore_first_stage_symbols_${_platform}") { 460 current_platform = _platform 461 current_platform_dir = "${product_output_dir}/$current_platform" 462 deps = [ ":package_libs_symbols_${_platform}" ] 463 print("restore_first_stage_symbols_${_platform}") 464 465 sources_dir = [ 466 "${root_build_dir}/backup/packages/${_platform}/exe.unstripped", 467 "${root_build_dir}/backup/packages/${_platform}/lib.unstripped", 468 ] 469 470 restore_dir = "${current_platform_dir}/restore_symbols" 471 472 outputs = [ restore_dir ] 473 474 script = "//build/ohos/packages/backup_restore_artifact.py" 475 args = [ "--source-dir" ] 476 foreach(source_dir, sources_dir) { 477 args += [ rebase_path(source_dir, root_out_dir) ] 478 } 479 480 args += [ 481 "--output-dir", 482 rebase_path(restore_dir, root_out_dir), 483 ] 484 } 485 } 486} 487 488foreach(_platform, target_platform_list) { 489 current_platform_dir = "$product_output_dir/$_platform" 490 _system_install_info_file = 491 "${current_platform_dir}/system_install_parts.json" 492 493 action_with_pydeps("package_libs_symbols_${_platform}") { 494 deps = [ ":${_platform}_parts_list" ] 495 script = "//build/ohos/packages/resources_collect.py" 496 inputs = [ _system_install_info_file ] 497 output_file = "$target_out_dir/$target_name.out" 498 outputs = [ output_file ] 499 500 args = [ 501 "--collect-type", 502 "libs_symbols", 503 "--system-install-info-file", 504 rebase_path(_system_install_info_file, root_build_dir), 505 "--resources-dir-list", 506 "lib.unstripped", 507 "exe.unstripped", 508 "--package-output-base-dir", 509 rebase_path("$current_platform_dir", root_build_dir), 510 "--output-file", 511 rebase_path(output_file, root_build_dir), 512 ] 513 } 514} 515 516group("package_libs_symbols") { 517 deps = [] 518 foreach(_platform, target_platform_list) { 519 deps += [ ":package_libs_symbols_${_platform}" ] 520 if (is_asan || is_tsan) { 521 deps += [ ":restore_first_stage_symbols_${_platform}" ] 522 } 523 } 524} 525 526foreach(_platform, target_platform_list) { 527 current_platform_dir = "${product_output_dir}/$_platform" 528 _system_install_info_file = 529 "${current_platform_dir}/system_install_parts.json" 530 531 action_with_pydeps("package_testcase_mlf_${_platform}") { 532 testonly = true 533 deps = [ 534 ":${_platform}_parts_list", 535 ":build_all_test_pkg", 536 ] 537 script = "//build/ohos/packages/resources_collect.py" 538 inputs = [ _system_install_info_file ] 539 output_file = "$target_out_dir/$target_name.out" 540 outputs = [ output_file ] 541 args = [ 542 "--collect-type", 543 "module_list_files", 544 "--system-install-info-file", 545 rebase_path(_system_install_info_file, root_build_dir), 546 "--resources-dir-list", 547 "module_list_files", 548 "--package-output-base-dir", 549 rebase_path("$current_platform_dir", root_build_dir), 550 "--output-file", 551 rebase_path(output_file, root_build_dir), 552 ] 553 } 554} 555 556group("package_testcase_mlf") { 557 testonly = true 558 deps = [] 559 foreach(_platform, target_platform_list) { 560 deps += [ ":package_testcase_mlf_${_platform}" ] 561 } 562} 563 564foreach(_platform, target_platform_list) { 565 current_platform_dir = "${product_output_dir}/$_platform" 566 567 _system_install_info_file = 568 "${current_platform_dir}/system_install_parts.json" 569 570 action_with_pydeps("package_testcase_${_platform}") { 571 testonly = true 572 deps = [ 573 ":${_platform}_parts_list", 574 ":build_all_test_pkg", 575 ] 576 script = "//build/ohos/packages/resources_collect.py" 577 inputs = [ _system_install_info_file ] 578 output_file = "$target_out_dir/$target_name.out" 579 outputs = [ output_file ] 580 581 test_type_list = [ 582 "unittest", 583 "moduletest", 584 "systemtest", 585 "performance", 586 "security", 587 "reliability", 588 "distributedtest", 589 "fuzztest", 590 ] 591 592 resources_dir_list = [] 593 foreach(test_type, test_type_list) { 594 resources_dir_list += [ "tests/" + test_type ] 595 } 596 597 args = [ 598 "--collect-type", 599 "testcase", 600 "--system-install-info-file", 601 rebase_path(_system_install_info_file, root_build_dir), 602 "--package-output-base-dir", 603 rebase_path("$current_platform_dir/tests", root_build_dir), 604 "--output-file", 605 rebase_path(output_file, root_build_dir), 606 "--resources-dir-list", 607 ] 608 args += resources_dir_list 609 } 610} 611 612foreach(_platform, target_platform_list) { 613 current_platform_dir = "${product_output_dir}/$_platform" 614 required_files = [] 615 required_files += [ 616 "${build_configs_path}/target_platforms_parts.json", 617 "${build_configs_path}/parts_info/parts_info.json", 618 "${build_configs_path}/infos_for_testfwk.json", 619 ] 620 action_with_pydeps("copy_testfwk_required_files_${_platform}") { 621 testonly = true 622 deps = [ ":package_testcase_${_platform}" ] 623 script = "//build/ohos/copy_files.py" 624 depfile = "$target_gen_dir/$target_name.d" 625 output_file = "$target_out_dir/$target_name.out" 626 outputs = [ output_file ] 627 args = [ 628 "--depfile", 629 rebase_path(depfile, root_build_dir), 630 "--copy-output-dir", 631 rebase_path("$current_platform_dir/tests", root_build_dir), 632 "--outfile", 633 rebase_path(output_file, root_build_dir), 634 "--source-files", 635 ] 636 args += rebase_path(required_files, root_build_dir) 637 } 638} 639 640action_with_pydeps("open_source_package") { 641 script = "//build/scripts/code_release.py" 642 depfile = "$target_gen_dir/$target_name.d" 643 if (osp_only_collect_file) { 644 _output = "${root_build_dir}/packages/code_opensource/release_opensource/CodeOpensource.stamp" 645 } else { 646 _output = "${root_build_dir}/packages/code_opensource/CodeOpensource.tar.gz" 647 } 648 outputs = [ _output ] 649 args = [ 650 "--depfile", 651 rebase_path(depfile, root_build_dir), 652 "--output", 653 rebase_path(_output, root_build_dir), 654 "--root-dir", 655 rebase_path("//", root_build_dir), 656 "--scan-dirs", 657 osp_scan_dirs, 658 "--scan-licenses", 659 osp_scan_licenses, 660 ] 661 662 # extend args 663 if (osp_only_collect_file) { 664 args += [ "--only-collect-file" ] 665 } 666} 667 668group("package_testcase") { 669 testonly = true 670 deps = [] 671 foreach(_platform, target_platform_list) { 672 deps += [ 673 ":copy_testfwk_required_files_${_platform}", 674 ":package_testcase_${_platform}", 675 ] 676 } 677} 678 679group("build_all_test_pkg") { 680 testonly = true 681 if (!is_llvm_build) { 682 deps = [ 683 "$root_build_dir/build_configs:parts_test", 684 "//test/testfwk/developer_test:make_temp_test", 685 ] 686 } 687} 688