# ohos_tool **Repository Path**: karl1864/ohos_tool ## Basic Information - **Project Name**: ohos_tool - **Description**: 给OpenHarmonyOS的linux下开发提供一些方便的工具 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: masterv2 - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 6 - **Forks**: 1 - **Created**: 2021-10-13 - **Last Updated**: 2025-04-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: 正在维护 ## README # ohos_tool 给OpenHarmonyOS的linux下开发提供一些方便的工具 ## 安装 1. 在该项目打目录下根据shell执行一条命令 ```sh git clone https://gitee.com/karl1864/ohos_tool cd ohos_tool git submodule init git submodule update # bash shell echo "export OHOS_TOOL='$(pwd)'" >> ~/.bashrc echo "[ -e $(pwd) ] && source $(pwd)/scripts/ohos-tool-env.sh" >> ~/.bashrc # zsh shell echo "export OHOS_TOOL='$(pwd)'" >> ~/.zshrc echo "[ -e $(pwd) ] && source $(pwd)/scripts/ohos-tool-env.sh" >> ~/.zshrc ``` 2. 重新打开shell ## 特性计划 - [x] 完善使用例子,更新文档 - [x] 使用并行 - [ ] 重写commands的细节 - [ ] 重写libs的细节 - [ ] 优化执行速度 - [ ] 修复zsh补全 - [ ] 依赖树形UI化 - [ ] autopush增强(自动判定是否会被install) - [ ] autohdc(自动连接设备、设置环境变量) - [ ] stack增强 UI化 - [ ] windows push - [ ] 配置docker编译CPU核心限制(当前为75%) - [ ] 配置docker编译内存限制(当前为75%) ## 使用例子 ### 所有命令均可--help ![helpall](./docs/helpall.png) ### 有些命令有别名 ![help](./docs/help.png) ### 0. 配置 `ohos-tool config@config`用于配置ohos-tool的一些行为: - 用docker编译 - 用窗口提醒耗时操作完成 - 自动更新 - 编译代码docker能用的CPU核心限制 (未实现) - 编译代码docker能用的内存限制 (未实现) #### 配置弹出的zenity对话框 ![config@config](./docs/config@config.png) ### 1. 仓库名 为了支持openharmony代码开发时能够并发, 用仓库名来指代不同的repo仓库。 openharmony更新很快,而且有的时候会滚挂, 所以也需要备一些代码仓库。 命令会自行寻找当前路径所在仓库, 所以执行需要仓库命令时需要在仓库下。 如果没有在仓库下执行需要仓库的命令会得到这样的输出`这个命令需要仓库`。 #### 使用样例 - 查看当前仓库情况`ohos-tool config@repo` - 添加仓库并命名为ohos1: `ohos-tool config@repo --add ohos1 $(pwd)` - 删除仓库ohos1: `ohos-tool config@repo --del ohos1` - 配置仓库ohos1的编译产品: `ohos-tool config@repo --product ohos1` - 指定仓库ohos1的编译产品为Hi3516DV300: `ohos-tool config@repo --product Hi3516DV300 ohos1` 简写的指令为 ```sh olr olr --add ohos1 $(pwd) olr --del ohos1 olr --product ohos1 olr --product ohos1 Hi3516DV300 ``` #### 环境变量 经过配置的仓库名在新的shell里将变成仓库路径的环境变量, 因此可以实现这样的效果: ```sh $ cd $ohos1 $ pwd /home/luwh/repo/ohos1 ``` #### olr执行结果 ![olr](./docs/olr.png) #### 执行`olr ohosm1 --product`弹出的选择产品框 ![olr](./docs/olr_product.png) ### 2. 编译 编译分docker编译和真机编译。 真机编译需要开发者自己配置编译环境, docker编译则会用docker容器进行编译。 编译命令均需要仓库。 #### 使用样例 - 编译的错误日志: `ohos-tool cc@err` - 整编,出镜像: `ohos-tool cc@hosp` - 编译BUILD.gn: `ohos-tool cc@buildgn` - 编译所有测试: `ohos-tool cc@alltest` - 编译sdk(有hdc): `ohos-tool cc@sdk` - 重新编译已经失败的文件: `ohos-tool cc@rebuild` - 重新编译第一个已经失败的文件: `ohos-tool cc@rebuild 1` - 重新编译第1、2、4个已经失败的文件: `ohos-tool cc@rebuild 1 2 4` - 查看第2个编译失败的编译参数: `ohos-tool cc@rebuild --args 2` - 预编译第2个编译失败的文件: `ohos-tool cc@rebuild --preprocess 2` - 编译wmtest测试的命令为: `ohos-tool cc@hosp --target wmtest` - 编译的错误个数: `ohos-tool cc@err --count` - 查看编译的第2个错误: `ohos-tool cc@err 2` - 查看所有根编译目标: `ohos-tool cc@list` - 查看所有编译目标的详情: `ohos-tool cc@blame //foundation/graphic/standard/frameowrk/surface:surface` 简写的指令为 ```sh cd $ohos1 oce och ocbg ohos-tool ohos1 cc@alltest ocs ocr ocr 1 ocr 1 2 4 ocra 2 ocrp 2 och --target wmtest ocec ocl ocbl //foundation/graphic/standard/frameowrk/surface:surface ``` ### 3. docker构建 若开发环境中存在docker且不需要sudo时, 可以用docker系列命令来构建最初的docker镜像。 刚装好的docker可以用过下列命令变成不需要sudo的状态 ```sh sudo gpasswd -a $USER docker sudo systemctl start docker.service sudo systemctl enable docker.service ``` #### 使用样例 - 构建docker源镜像: `ohos-tool docker@image` - 重写构建docker源镜像: `ohos-tool docker@reimage` - 进入容器的终端: `ohos-tool docker@enter` 简写的指令为 ```sh odi odr cd $ohos1 ode ``` ### 4. hdc 此功能不稳定,需要连上板子 ### 5. 仓库级操作 #### 使用样例 - 查看仓库状态(检查 修改已跟踪文件 和 新分支): `repo@status` - 同步代码: `repo@sync` - 查看当前仓库最近一笔提交的时间: `repo@date` - 将所有仓库都赶回某个时间之前: `repo@back YYYY-MM-DD [hh:mm]` - 初始化一个master仓库: `repo@init` #### repo@sync执行结果 ![ors](./docs/ors.png) #### repo@status执行结果 ![orss](./docs/orss.png) ### 6. 实用功能 - utils@image: 打包镜像为OHOS_IMAGE_NAME放在OHOS_IMAGE_DIR下 - utils@out: 在out/ohos-arm-release下启动bash,用于反复编译 - utils@asm: 反汇编 - utils@stack: 打印Crash堆栈对应的文件堆栈 - utils@flush: 烧写板子 (目前只支持rk3568) ```sh $ ohos-tool utils@stack Ctrl+V粘贴Crash堆栈 #01 pc 0000000000006951(00000000b64d4951) /system/lib/libivi-shell.z.so(ivi_layout_surface_destroy+31) #02 pc 0000000000019ff1(00000000b5ba6ff1) /system/lib/libwmserver.z.so(wet_module_init+15747) #03 pc 0000000000019c1b(00000000b5ba6c1b) /system/lib/libwmserver.z.so(wet_module_init+14765) #04 pc 0000000000036f93(00000000b6df3f93) /system/lib/libweston.z.so(weston_surface_destroy+33) Ctrl+D结束输入 ```