在OpenHarmony编译构建中笔者经常遇到这样的场景——需要执行sh脚本完成某些操作。笔者将OpenHarmony BUILD.gn中执行脚本的方法分享如下:

前置知识点

1.能够把自定义的子系统加入OpenHarmony源码的编译构建,请参考:https://ost.51cto.com/posts/17750%E4%B8%AD%E5%85%B3%E4%BA%8E%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AD%90%E7%B3%BB%E7%BB%9F%E7%9A%84%E9%83%A8%E5%88%86

开发环境

  • OpenHarmony源码5.0.0版本

步骤

1.首先新建一个BUILD.gn

import("//build/ohos.gni")

exec_script("install.sh")

# 脚本如果需要参数则写成
# path= rebase_path("//xxx/xxx/xxxx/libomxil_bellagio")
# exec_script("install.sh", [ "$path" ])

config("public_config") {
....
}

ohos_static_library("omxbase") {
....
}

2.添加脚本执行权限,在5.0.0/build/core/gn/ohos_exec_script_allowlist.gni中加入该BUILD.gn的路径即可

具体实现可以参考
https://gitee.com/openharmony/third_party_libnl

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐