• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  _host_toolchain = "$host_toolchain"
238
239  action_with_pydeps("${_platform}_install_modules") {
240    script = "//build/ohos/packages/modules_install.py"
241    public_deps = [ ":${current_platform}_parts_list" ]
242    depfile = "$target_gen_dir/$target_name.d"
243    deps = [
244      ":${current_platform}_hisysevent_install_info",
245      ":${current_platform}_sa_profile_install_info",
246      ":generate_host_symlink",
247      ":merge_system_notice_file_${current_platform}",
248      ":verify_notice_file_${current_platform}",
249    ]
250
251    sources = [
252      _merged_sa_profile_zipfile,
253      _system_install_info_file,
254    ]
255
256    outputs = [
257      system_install_modules,
258      system_module_info_list,
259      system_modules_list,
260      _system_image_zipfile,
261    ]
262
263    args = [
264      "--system-install-info-file",
265      rebase_path(_system_install_info_file, root_build_dir),
266      "--install-modules-info-file",
267      rebase_path(system_install_modules, root_build_dir),
268      "--modules-info-file",
269      rebase_path(system_module_info_list, root_build_dir),
270      "--modules-list-file",
271      rebase_path(system_modules_list, root_build_dir),
272      "--platform-installed-path",
273      rebase_path(current_platform_dir, root_build_dir),
274      "--depfile",
275      rebase_path(depfile, root_build_dir),
276      "--sa-profile-extract-dir",
277      rebase_path(_merged_sa_profile_dir, root_build_dir),
278      "--merged-sa-profile",
279      rebase_path(_merged_sa_profile_zipfile, root_build_dir),
280      "--system-dir",
281      rebase_path("$current_platform_dir/system", root_build_dir),
282      "--system-image-zipfile",
283      rebase_path(_system_image_zipfile, root_build_dir),
284      "--host-toolchain",
285      _host_toolchain,
286    ]
287
288    _additional_system_files = []
289    foreach(tuple, _additional_system_files) {
290      args += [
291        "--additional-system-files",
292        rebase_path(tuple[0], root_build_dir) + ":" + tuple[1],
293      ]
294    }
295
296    if (post_process_modules_list != []) {
297      sources += post_process_modules_list
298      args += [ "--post-process-modules-info-files" ]
299      args += rebase_path(post_process_modules_list, root_build_dir)
300    }
301  }
302
303  action("check_seccomp_filter_name") {
304    script = "//build/ohos/packages/check_seccomp_library_name.py"
305    deps = [ ":${_platform}_install_modules" ]
306
307    # result is not used in script
308    process_validate_result =
309        "${current_platform_dir}/check_seccomp_filter_name.txt"
310    _system_cfg_folder = "${current_platform_dir}/system/etc/init"
311    if (target_cpu == "arm" || target_cpu == "x86") {
312      libdir = "lib"
313    } else if (target_cpu == "arm64" || target_cpu == "x86_64") {
314      libdir = "lib64"
315    } else {
316      libdir = "lib"
317    }
318    _system_seccomp_folder = "${current_platform_dir}/system/${libdir}/seccomp"
319
320    _vendor_cfg_folder = "${current_platform_dir}/vendor/etc/init"
321    _vendor_seccomp_folder = "${current_platform_dir}/vendor/${libdir}/seccomp"
322
323    outputs = [ process_validate_result ]
324
325    args = [
326      "--vendor-cfg-path",
327      rebase_path(_vendor_cfg_folder, root_build_dir),
328      "--vendor-seccomp-lib-path",
329      rebase_path(_vendor_seccomp_folder, root_build_dir),
330      "--system-cfg-path",
331      rebase_path(_system_cfg_folder, root_build_dir),
332      "--system-seccomp-lib-path",
333      rebase_path(_system_seccomp_folder, root_build_dir),
334    ]
335  }
336
337  action("process_field_validate") {
338    script = "//build/ohos/packages/process_field_validate.py"
339
340    deps = [ ":${_platform}_install_modules" ]
341
342    # result is not used in script
343    process_validate_result = "${current_platform_dir}/cfg_validate_result.txt"
344
345    # ext_root_proc_conf_path defined in config.json in vendor warehouse
346    if (ext_root_proc_conf_path != "") {
347      _privilege_whitelist = ext_root_proc_conf_path
348    } else {
349      _privilege_whitelist = "//vendor/${product_company}/${product_name}/security_config/high_privilege_process_list.json"
350    }
351
352    # ext_critical_proc_conf_path defined in config.json in vendor warehouse
353    if (ext_critical_proc_conf_path != "") {
354      _critical_whitelist = ext_critical_proc_conf_path
355    } else {
356      _critical_whitelist = "//vendor/${product_company}/${product_name}/security_config/critical_reboot_process_list.json"
357    }
358    _system_cfg_folder = "${current_platform_dir}/system/etc/init"
359
360    _vendor_cfg_folder = "${current_platform_dir}/vendor/etc/init"
361
362    outputs = [ process_validate_result ]
363
364    args = [
365      "--sys-cfg-folder",
366      rebase_path(_system_cfg_folder, root_build_dir),
367      "--vendor-cfg-folder",
368      rebase_path(_vendor_cfg_folder, root_build_dir),
369      "--high-privilege-process-list-path",
370      rebase_path(_privilege_whitelist, root_build_dir),
371      "--critical-reboot-process-list-path",
372      rebase_path(_critical_whitelist, root_build_dir),
373    ]
374  }
375}
376
377# required_install_module_list.json
378foreach(_platform, target_platform_list) {
379  current_platform_dir = "${product_output_dir}/$_platform"
380  _system_install_info_file =
381      "${current_platform_dir}/system_install_parts.json"
382  required_install_modules_file =
383      "${current_platform_dir}/required_install_module_list.json"
384  action_with_pydeps("gen_required_modules_${_platform}") {
385    deps = [ ":${_platform}_parts_list" ]
386    script = "//build/ohos/packages/gen_required_modules_list.py"
387    inputs = [ _system_install_info_file ]
388    outputs = [ required_install_modules_file ]
389    depfile = "$target_gen_dir/$target_name.d"
390    args = [
391      "--system-installed-info-file",
392      rebase_path(_system_install_info_file, root_out_dir),
393      "--required-install-modules-file",
394      rebase_path(required_install_modules_file, root_out_dir),
395      "--depfile",
396      rebase_path(depfile, root_build_dir),
397    ]
398  }
399}
400
401if (is_asan) {
402  foreach(_platform, target_platform_list) {
403    action("restore_first_stage_artifact_${_platform}") {
404      current_platform = _platform
405      current_platform_dir = "${product_output_dir}/$current_platform"
406      deps = [ ":${_platform}_install_modules" ]
407      print("restore_first_stage_artifact_${_platform}")
408
409      if (current_cpu == "arm64" || current_cpu == "riscv64") {
410        module_type = "lib64"
411      } else if (current_cpu == "arm") {
412        module_type = "lib"
413      }
414
415      sources_dir = [
416        "${root_build_dir}/backup/packages/${_platform}/system/$module_type",
417        "${root_build_dir}/backup/packages/${_platform}/system/bin",
418      ]
419
420      restore_dir = "${current_platform_dir}/${system_base_dir}/restore"
421
422      outputs = [ restore_dir ]
423
424      script = "//build/ohos/packages/backup_restore_artifact.py"
425      args = [ "--source-dir" ]
426      foreach(source_dir, sources_dir) {
427        args += [ rebase_path(source_dir, root_out_dir) ]
428      }
429
430      args += [
431        "--output-dir",
432        rebase_path(restore_dir, root_out_dir),
433      ]
434    }
435
436    action("restore_first_stage_symbols_${_platform}") {
437      current_platform = _platform
438      current_platform_dir = "${product_output_dir}/$current_platform"
439      deps = [ ":package_libs_symbols_${_platform}" ]
440      print("restore_first_stage_symbols_${_platform}")
441
442      sources_dir = [
443        "${root_build_dir}/backup/packages/${_platform}/exe.unstripped",
444        "${root_build_dir}/backup/packages/${_platform}/lib.unstripped",
445      ]
446
447      restore_dir = "${current_platform_dir}/restore_symbols"
448
449      outputs = [ restore_dir ]
450
451      script = "//build/ohos/packages/backup_restore_artifact.py"
452      args = [ "--source-dir" ]
453      foreach(source_dir, sources_dir) {
454        args += [ rebase_path(source_dir, root_out_dir) ]
455      }
456
457      args += [
458        "--output-dir",
459        rebase_path(restore_dir, root_out_dir),
460      ]
461    }
462  }
463}
464
465foreach(_platform, target_platform_list) {
466  current_platform_dir = "$product_output_dir/$_platform"
467  _system_install_info_file =
468      "${current_platform_dir}/system_install_parts.json"
469
470  action_with_pydeps("package_libs_symbols_${_platform}") {
471    deps = [ ":${_platform}_parts_list" ]
472    script = "//build/ohos/packages/resources_collect.py"
473    inputs = [ _system_install_info_file ]
474    output_file = "$target_out_dir/$target_name.out"
475    outputs = [ output_file ]
476
477    args = [
478      "--collect-type",
479      "libs_symbols",
480      "--system-install-info-file",
481      rebase_path(_system_install_info_file, root_build_dir),
482      "--resources-dir-list",
483      "lib.unstripped",
484      "exe.unstripped",
485      "--package-output-base-dir",
486      rebase_path("$current_platform_dir", root_build_dir),
487      "--output-file",
488      rebase_path(output_file, root_build_dir),
489    ]
490  }
491}
492
493group("package_libs_symbols") {
494  deps = []
495  foreach(_platform, target_platform_list) {
496    deps += [ ":package_libs_symbols_${_platform}" ]
497    if (is_asan) {
498      deps += [ ":restore_first_stage_symbols_${_platform}" ]
499    }
500  }
501}
502
503foreach(_platform, target_platform_list) {
504  current_platform_dir = "${product_output_dir}/$_platform"
505  _system_install_info_file =
506      "${current_platform_dir}/system_install_parts.json"
507
508  action_with_pydeps("package_testcase_mlf_${_platform}") {
509    testonly = true
510    deps = [
511      ":${_platform}_parts_list",
512      ":build_all_test_pkg",
513    ]
514    script = "//build/ohos/packages/resources_collect.py"
515    inputs = [ _system_install_info_file ]
516    output_file = "$target_out_dir/$target_name.out"
517    outputs = [ output_file ]
518    args = [
519      "--collect-type",
520      "module_list_files",
521      "--system-install-info-file",
522      rebase_path(_system_install_info_file, root_build_dir),
523      "--resources-dir-list",
524      "module_list_files",
525      "--package-output-base-dir",
526      rebase_path("$current_platform_dir", root_build_dir),
527      "--output-file",
528      rebase_path(output_file, root_build_dir),
529    ]
530  }
531}
532
533group("package_testcase_mlf") {
534  testonly = true
535  deps = []
536  foreach(_platform, target_platform_list) {
537    deps += [ ":package_testcase_mlf_${_platform}" ]
538  }
539}
540
541foreach(_platform, target_platform_list) {
542  current_platform_dir = "${product_output_dir}/$_platform"
543
544  _system_install_info_file =
545      "${current_platform_dir}/system_install_parts.json"
546
547  action_with_pydeps("package_testcase_${_platform}") {
548    testonly = true
549    deps = [
550      ":${_platform}_parts_list",
551      ":build_all_test_pkg",
552    ]
553    script = "//build/ohos/packages/resources_collect.py"
554    inputs = [ _system_install_info_file ]
555    output_file = "$target_out_dir/$target_name.out"
556    outputs = [ output_file ]
557
558    test_type_list = [
559      "unittest",
560      "moduletest",
561      "systemtest",
562      "performance",
563      "security",
564      "reliability",
565      "distributedtest",
566      "fuzztest",
567    ]
568
569    resources_dir_list = []
570    foreach(test_type, test_type_list) {
571      resources_dir_list += [ "tests/" + test_type ]
572    }
573
574    args = [
575      "--collect-type",
576      "testcase",
577      "--system-install-info-file",
578      rebase_path(_system_install_info_file, root_build_dir),
579      "--package-output-base-dir",
580      rebase_path("$current_platform_dir/tests", root_build_dir),
581      "--output-file",
582      rebase_path(output_file, root_build_dir),
583      "--resources-dir-list",
584    ]
585    args += resources_dir_list
586  }
587}
588
589foreach(_platform, target_platform_list) {
590  current_platform_dir = "${product_output_dir}/$_platform"
591  required_files = []
592  required_files += [
593    "${build_configs_path}/target_platforms_parts.json",
594    "${build_configs_path}/parts_info/parts_info.json",
595    "${build_configs_path}/infos_for_testfwk.json",
596  ]
597  action_with_pydeps("copy_testfwk_required_files_${_platform}") {
598    testonly = true
599    deps = [ ":package_testcase_${_platform}" ]
600    script = "//build/ohos/copy_files.py"
601    depfile = "$target_gen_dir/$target_name.d"
602    output_file = "$target_out_dir/$target_name.out"
603    outputs = [ output_file ]
604    args = [
605      "--depfile",
606      rebase_path(depfile, root_build_dir),
607      "--copy-output-dir",
608      rebase_path("$current_platform_dir/tests", root_build_dir),
609      "--outfile",
610      rebase_path(output_file, root_build_dir),
611      "--source-files",
612    ]
613    args += rebase_path(required_files, root_build_dir)
614  }
615}
616
617action_with_pydeps("open_source_package") {
618  script = "//build/scripts/code_release.py"
619  depfile = "$target_gen_dir/$target_name.d"
620  _output = "$root_build_dir/packages/code_opensource/CodeOpensource.tar.gz"
621  outputs = [ _output ]
622  args = [
623    "--depfile",
624    rebase_path(depfile, root_build_dir),
625    "--output",
626    rebase_path(_output, root_build_dir),
627    "--root-dir",
628    rebase_path("//", root_build_dir),
629  ]
630}
631
632group("package_testcase") {
633  testonly = true
634  deps = []
635  foreach(_platform, target_platform_list) {
636    deps += [
637      ":copy_testfwk_required_files_${_platform}",
638      ":package_testcase_${_platform}",
639    ]
640  }
641}
642
643group("build_all_test_pkg") {
644  testonly = true
645  if (!is_llvm_build) {
646    deps = [
647      "$root_build_dir/build_configs:parts_test",
648      "//test/testfwk/developer_test:make_temp_test",
649    ]
650  }
651}
652