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