自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

OpenHarmony-3.0 編譯構(gòu)建流程

開發(fā) 前端
早就打算研究下OH3.0的編譯框架了,最近一直在搞移植,總算有點(diǎn)進(jìn)展了,抽個空來分析下3.0的編譯框架。

[[437383]]

想了解更多內(nèi)容,請?jiān)L問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

前言

OpenHarmony-2.0 編譯構(gòu)建流程

早就打算研究下OH3.0的編譯框架了,最近一直在搞移植,總算有點(diǎn)進(jìn)展了,抽個空來分析下3.0的編譯框架。大體看了下和2.0的差別不是特別大,OHOS3.0的打包鏡像腳本由原來2.0的build\adapter\build_image.sh 全部修改替換為 build\ohos\images\build_image.py 將打包image鏡像的部分制作成build_target,以前是通過shell腳本來調(diào)用,現(xiàn)在是通過gn和ninja來調(diào)用。主要文件在build\ohos\images這個文件夾下。沒有修改的部分就不說了,有需要的可以看我之前的帖子 這篇主要說下不一樣的地方,看OH3.0是如何將編譯好的文件打包成鏡像的。

一、增加編譯參數(shù)

3.0之后在build\build_scripts\build_common.sh 增加了 build_cmd+=" build_target=images",這句的意思約等于在執(zhí)行默認(rèn)編譯命令 ./build.sh --product-name Hi3516DV300 會有個默認(rèn)的參數(shù) --build-target images,具體流程是這樣的:

  1. build\build_scripts\build_common.sh => build\core\gn\BUILD.gn => build\ohos\images\BUILD.gn 
  2.  
  3. action_with_pydeps("${_platform}_${_image_name}_image") { 
  4.     script = "//build/ohos/images/build_image.py" 
  5.     depfile = "$target_gen_dir/$target_name.d" 
  6.     deps = [ "//build/ohos/packages:${_platform}_install_modules" ] 
  7.  
  8.     image_config_file = 
  9.     "//build/ohos/images/mkimage/${_image_name}_image_conf.txt" 
  10.     output_image_file = "$current_platform_dir/images/${_image_name}.img" 
  11.  
  12.     image_input_path = "$current_platform_dir/${_image_name}" 
  13.     if (_image_name == "userdata") { 
  14.         image_input_path = "$current_platform_dir/data" 
  15.     } 
  16.  
  17.     sources = [ 
  18.         image_config_file, 
  19.         system_module_info_list, 
  20.         system_modules_list, 
  21.     ] 
  22.     outputs = [ output_image_file ] 
  23.     args = [ 
  24.         "--depfile"
  25.         rebase_path(depfile, root_build_dir), 
  26.         "--image-name"
  27.         _image_name, 
  28.         "--input-path"
  29.         rebase_path(image_input_path, root_build_dir), 
  30.         "--image-config-file"
  31.         rebase_path(image_config_file, root_build_dir), 
  32.         "--output-image"
  33.         rebase_path(output_image_file, root_build_dir), 
  34.         "--build-image-tools-path"
  35.         rebase_path(build_image_tools_path, root_build_dir), 
  36.     ] 
  37.     if (sparse_image) { 
  38.         args += [ "--sparse-image" ] 
  39.     } 

通常情況下,gn會使用 action 運(yùn)行一個腳本來生成一個文件,但是這里使用的是 action_with_pydeps,應(yīng)該也是內(nèi)置的目標(biāo)類型。查看官方手冊是這么說明的

Inputs and Depfiles

List all files read (or executed) by an action as inputs.

  • It is not enough to have inputs listed by dependent targets. They must be listed directly by targets that use them, or added by a depfile.
  • Non-system Python imports are inputs! For scripts that import such modules, use action_with_pydeps to ensure all dependent Python files are captured as inputs.

前面還定義了一個image_list,然后使用 foreach 執(zhí)行 action_with_pydeps,要生成幾個img文件,就執(zhí)行幾次action_with_pydeps。

  1. image_list = [ 
  2.   "system"
  3.   "vendor"
  4.   "userdata"
  5.   "updater"
  6. foreach(_image_name, image_list) {... ...} 

二、調(diào)用python腳本

既然知道了img鏡像是由 build\ohos\images\build_image.py 來創(chuàng)建的,那就來分析下這個python腳本。

  1. if os.path.exists(args.output_image_path): 
  2.         os.remove(args.output_image_path)           # 刪除之前生成的鏡像文件夾 
  3.     if args.image_name == 'userdata'
  4.         _prepare_userdata(args.input_path)          # 準(zhǔn)備好 userdata.img 需要的文件 
  5.     if os.path.isdir(args.input_path): 
  6.         _make_image(args) 
  7.         _dep_files = [] 
  8.         for _root, _, _files in os.walk(args.input_path): 
  9.             for _file in _files: 
  10.                 _dep_files.append(os.path.join(_root, _file)) 
  11.         build_utils.write_depfile(args.depfile, 
  12.                                   args.output_image_path, 
  13.                                   _dep_files, 
  14.                                   add_pydeps=False
  15. =================================================================== 
  16. def _make_image(args): 
  17.     if args.image_name == 'system'
  18.         _prepare_root(args.input_path)              # 準(zhǔn)備好 system.img 需要的文件 
  19.     elif args.image_name == 'updater'
  20.         _prepare_updater(args.input_path)           # 準(zhǔn)備好 updater.img 需要的文件 
  21.     image_type = "raw" 
  22.     if args.sparse_image: 
  23.         image_type = "sparse" 
  24.     mk_image_args = [ 
  25.         args.input_path, args.image_config_file, args.output_image_path, 
  26.         image_type 
  27.     ] 
  28.     env_path = "../../build/ohos/images/mkimage" 
  29.     if args.build_image_tools_path: 
  30.         env_path = '{}:{}'.format(env_path, args.build_image_tools_path) 
  31.     os.environ['PATH'] = '{}:{}'.format(env_path, os.environ.get('PATH')) 
  32.     mkimages.mk_images(mk_image_args)           # 而真正制作鏡像使用的下面的函數(shù) 
  33. =================================================================== 
  34. # build\ohos\images\mkimage\mkimages.py 
  35. def mk_images(args): 
  36.     ... ... 
  37.     if "system.img" in device: 
  38.         src_dir = build_rootdir(src_dir) 
  39.     mkfs_tools, mk_configs = load_config(config_file) 
  40.     mk_configs = src_dir + " " + device + " " + mk_configs 
  41.  
  42.     res = run_cmd(mkfs_tools + " " + mk_configs)    # 制作鏡像命令使用的是mkfs_tools 
  43. =================================================================== 
  44.     if "ext4" in mk_configs: 
  45.         fs_type = "ext4" 
  46.         mkfs_tools = "mkextimage.py"                # 而mkfs_tools根據(jù)文件系統(tǒng)類型,分別調(diào)用對應(yīng)的python腳本 
  47.     elif "f2fs" in mk_configs: 
  48.         mkfs_tools = "mkf2fsimage.py" 
  49.         fs_type = "f2fs" 
  50. =================================================================== 
  51. # build\ohos\images\mkimage\mkextimage.py # 制作ext4文件系統(tǒng) 
  52. def build_run_mke2fs(args): 
  53.     .. ... 
  54.     blocks = int(int(args.fs_size) / BLOCKSIZE) 
  55.     mke2fs_cmd += ("mke2fs " + str(mke2fs_opts) + " -t " + FS_TYPE + " -b " 
  56.                    + str(BLOCKSIZE) + " " + args.device + " " + str(blocks)) 
  57.     res = run_cmd(mke2fs_cmd)       # mke2fs:制作文件系統(tǒng) 
  58. =================================================================== 
  59. def build_run_e2fsdroid(args): 
  60.     ... ... 
  61.     e2fsdroid_cmd += ("e2fsdroid" + e2fsdroid_opts + " -f " + 
  62.                       args.src_dir + " -a " + args.mount_point + 
  63.                       " " + args.device) 
  64.     res = run_cmd(e2fsdroid_cmd)    # e2fsdroid:制作鏡像文件   

無論前面執(zhí)行了什么操作,最終都是為了執(zhí)行mke2fs、e2fsdroid。

關(guān)于這兩個命令:

mke2fs:Linux下的命令,用于建立ext文件系統(tǒng)。

e2fsdroid:來自三方庫,third_party\e2fsprogs。詳情可以參考 http://e2fsprogs.sourceforge.net

想了解更多內(nèi)容,請?jiān)L問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

 

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2021-06-28 09:38:50

鴻蒙HarmonyOS應(yīng)用

2024-07-26 16:39:33

鴻蒙系統(tǒng)開源構(gòu)建系統(tǒng)

2023-06-12 15:43:44

鴻蒙智能家居開發(fā)

2021-09-16 15:04:28

鴻蒙HarmonyOS應(yīng)用

2022-02-21 14:49:26

OpenHarmon操作系統(tǒng)鴻蒙

2023-07-17 16:13:21

組件模塊開發(fā)的鴻蒙

2024-01-03 15:31:16

網(wǎng)格布局ArkTSGrid

2021-10-09 10:12:39

鴻蒙HarmonyOS應(yīng)用

2022-01-11 15:41:18

鴻蒙HarmonyOS應(yīng)用

2023-07-27 14:38:33

開源鴻蒙

2023-08-11 14:06:58

鴻蒙Windows

2021-12-03 09:50:39

鴻蒙HarmonyOS應(yīng)用

2021-10-14 15:48:28

鴻蒙HarmonyOS應(yīng)用

2021-07-27 11:54:51

windows系統(tǒng)OpenHarmony

2021-11-08 07:19:45

鴻蒙HarmonyOS應(yīng)用

2023-02-28 15:49:09

鴻蒙應(yīng)用開發(fā)

2023-02-01 16:28:30

Linux內(nèi)核鴻蒙

2023-07-28 15:32:26

鴻蒙操作系統(tǒng)

2011-01-19 17:13:44

Sylpheed

2023-04-26 15:29:35

NAPI模塊鴻蒙
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號