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