一区二区三区三上|欧美在线视频五区|国产午夜无码在线观看视频|亚洲国产裸体网站|无码成年人影视|亚洲AV亚洲AV|成人开心激情五月|欧美性爱内射视频|超碰人人干人人上|一区二区无码三区亚洲人区久久精品

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

【潤(rùn)和軟件DAYU200開(kāi)發(fā)板體驗(yàn)】移植speexdsp到OpenHarmony標(biāo)準(zhǔn)系統(tǒng)③

開(kāi)發(fā)板試用精選 ? 來(lái)源:開(kāi)發(fā)板試用 ? 作者:電子發(fā)燒友論壇 ? 2022-10-12 10:15 ? 次閱讀

本文來(lái)源電子發(fā)燒友社區(qū),作者:離北況歸, 帖子地址:https://bbs.elecfans.com/jishu_2308797_1_1.html


由于想要分享的內(nèi)容較多,為避免讀者姥爺們失去看下去的耐心,分享將以連載的方式進(jìn)行。
下期預(yù)告:在OpenHarmony的編譯體系下編譯speexdsp的so和測(cè)試用的可執(zhí)行文件,以及編譯報(bào)錯(cuò)的解決辦法。

本期為移植speexdsp到OpenHarmony標(biāo)準(zhǔn)系統(tǒng)的第③期,主要內(nèi)容如下:

image.png


speexdsp移植后已提交至openhamrony sig倉(cāng)庫(kù):https://gitee.com/openharmony-sig/contest/tree/master/2022_OpenHarmony_thirdparty/speexdsp


四、將三方庫(kù)加入到OpenHarmony的編譯體系

根據(jù)上一步分析結(jié)果,編寫gn文件,將三方庫(kù)加入到OpenHarmony的編譯體系。

OpenHarmony編譯構(gòu)建子系統(tǒng)提供了一個(gè)基于Gn和ninja的編譯構(gòu)建框架。根據(jù)產(chǎn)品配置,編譯生成對(duì)應(yīng)的鏡像包。其中編譯構(gòu)建流程為:

  • 使用Gn配置構(gòu)建目標(biāo)。
  • Gn運(yùn)行后會(huì)生成ninja文件。
  • 通過(guò)運(yùn)行ninja來(lái)執(zhí)行編譯任務(wù)。

OpenHarmony三方庫(kù)編譯環(huán)境搭建

本次移植時(shí)在openharmony3.2Beta1版本上運(yùn)行的,所以需要準(zhǔn)備openharmony3.2Beta1的源碼。
先在Widows上安裝虛擬機(jī),在虛擬機(jī)上安裝Ubuntu18.04或者20.04。筆者使用的為Ubuntu20.04。

1.將Ubuntu Shell環(huán)境修改為bash

  • 打開(kāi)終端執(zhí)行
sudo dpkg-reconfigure dash
  • 將Shell由dash改為bash。

image.png

  • 選擇<否>

image.png

  • 更改成功如下:

image.png

2.下載華為集成開(kāi)發(fā)環(huán)境 DevEco Device Tool Linux版本,目前最新版本號(hào)為3.1.0.200

HUAWEI DevEco Device Tool(以下簡(jiǎn)稱DevEco Device Tool)是OpenHarmony面向智能設(shè)備開(kāi)發(fā)者提供的一站式集成開(kāi)發(fā)環(huán)境,支持OpenHarmony的組件按需定制,支持代碼編輯、編譯、燒錄和調(diào)試等功能,支持C/C++語(yǔ)言,以插件的形式部署在Visual Studio Code上。

  • 直接在Ubuntu上打開(kāi)firefox輸入下載地址下載

image.png

  • 解壓DevEco Device Tool安裝包,并對(duì)解壓后的文件賦權(quán)
unzip devicetool-linux-tool-3.1.0.200.zip
chmod u+x devicetool-linux-tool-3.1.0.200.sh

image.png

  • 安裝DevEco Device
  • 執(zhí)行命令安裝DevEco Device
sudo ./devicetool-linux-tool-3.1.0.200.sh

image.png

終端打印出這條信息說(shuō)明安裝成功

image.png

3.獲取標(biāo)準(zhǔn)系統(tǒng)源碼
執(zhí)行命令sudo apt-get install git git-lfs安裝git客戶端和git-lfs

  • 配置git用戶信息
git config --global user.name "yourname"
git config --global user.email "your-email-address"
git config --global credential.helper store

git config --global credential.helper store執(zhí)行這個(gè)命令會(huì)在本地生成一個(gè)文本,上邊記錄配置。然后再拉取代碼就不用再輸入賬號(hào)信息了。

  • 進(jìn)入gitee官網(wǎng)個(gè)人主頁(yè),個(gè)人頭像下方就是user.name
  • 再進(jìn)入設(shè)置點(diǎn)擊郵箱管理就可以得到你的your-email-address
  • 安裝gitee碼云repo工具
sudo apt-get install curl
sudo curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 -o /usr/local/bin/repo
sudo chmod a+x /usr/local/bin/repo
sudo pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests

image.png

image.png

image.png

  • 使用repo+https下載發(fā)布Tag節(jié)點(diǎn)源碼

創(chuàng)建源碼存放目錄
進(jìn)入創(chuàng)建的源碼存放目錄,執(zhí)行以下命令下載源碼

sudo ln -sf /usr/bin/python3 /usr/bin/python
repo init -u https://gitee.com/openharmony/manifest -b refs/tags/OpenHarmony-v3.2-Beta1 --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'

image.png

3.在源碼目錄下執(zhí)行腳本安裝編譯器及二進(jìn)制工具
下載的prebuilts二進(jìn)制默認(rèn)存放在與OpenHarmony同目錄下的OpenHarmony_2.0_canary_prebuilts下。

image.png

bash build/prebuilts_download.sh

image.png

4.安裝依賴工具

sudo apt-get install binutils git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby

5.最后測(cè)試一下OpenHarmony三方庫(kù)編譯環(huán)境

在源碼根目錄下執(zhí)行編譯命令

./build.sh --product-name rk3568 --ccache --build-target=要編譯的部件名 --target-cpu arm64
#其中:--product-name rk3568 指定產(chǎn)品名為rk3568 
#其中:--ccache              編譯使用ccache
#其中:--target-cpu arm64    編譯構(gòu)建64位系統(tǒng)

在源碼目錄下執(zhí)行編譯zlib命令,生成libzlib.z.so

./build.sh --product-name rk3568 --ccache --build-target=zlib

image.png

image.png

編譯生成了libzlib.z.so,編譯環(huán)境沒(méi)問(wèn)題。

配置speexdsp源碼

下載完openharmony3.2Beta1源碼后,將speexdsp的源碼拷貝到openhamony的third_party目錄下。

image.png

在OpenHarmony/sources/third_party/speexdsp和OpenHarmony/sources/third_party/speexdsp/libspeexdsp下分別編寫一份BUILD.gn文件,完成speexdsp的gn及測(cè)試用例的gn化。測(cè)試用例指的是測(cè)試speexdsp功能的程序。

speexdsp編譯gn化,新增工程構(gòu)建腳本。

OpenHarmony/sources/third_party/speexdsp下添加BUILD.gn腳本文件。

OpenHarmony/sources/third_party/speexdsp/BUILD.gn內(nèi)容如下:

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

config("speexdsp_nowarn_config"){
    cflags = [
         "-Wno-implicit-function-declaration",
         "-Wno-pointer-sign",
         "-Wno-unused-variable",
    ]
}

config("speexdsp_cflag_config"){
    cflags = [
         "-g",
         "-O2",
         "-fvisibility=hidden",
         "-DHAVE_CONFIG_H",

    ]
    ldflags = [
         "-lm"
    ]
}

ohos_shared_library("speexdsp_share") {
    sources = [
         "libspeexdsp/preprocess.c",
         "libspeexdsp/jitter.c",
         "libspeexdsp/mdf.c",
         "libspeexdsp/fftwrap.c",
         "libspeexdsp/filterbank.c",
         "libspeexdsp/resample.c",
         "libspeexdsp/buffer.c",
         "libspeexdsp/scal.c",
         "libspeexdsp/smallft.c",
         ]
         
    defines = [
        "NL_DEBUG",
        "speexdsp_EXPORTS",
    ]
    
    configs = [ 
         ":speexdsp_cflag_config", 
         ":speexdsp_nowarn_config"
    ] 
    include_dirs = [
         ".",
         "libspeexdsp",
         "include"
    ]
    part_name = "speexdsp"
}

代碼解析

第一行:

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

import函數(shù)將ohos.gni文件導(dǎo)入到當(dāng)前作用域。導(dǎo)入的文件是獨(dú)立執(zhí)行的,生成的作用域被復(fù)制到當(dāng)前文件中。一個(gè).gni文件會(huì)定義構(gòu)建參數(shù)和模板。build目錄下ohos.gni文件內(nèi)容如下

import("http://build/config/sanitizers/sanitizers.gni")
import("http://build/ohos/ndk/ndk.gni")
import("http://build/ohos/notice/notice.gni")
import("http://build/ohos/sa_profile/sa_profile.gni")
import("http://build/ohos_var.gni")
import("http://build/toolchain/toolchain.gni")

# import cxx base templates
import("http://build/templates/cxx/cxx.gni")
if (support_jsapi) {
  import("http://build/ohos/ace/ace.gni")
  import("http://build/ohos/app/app.gni")
}

import("http://build/templates/common/ohos_templates.gni")

# import prebuilt templates
import("http://build/templates/cxx/prebuilt.gni")

第三行到第九行:

config("speexdsp_nowarn_config"){
    cflags = [
         "-Wno-implicit-function-declaration",
         "-Wno-pointer-sign",
         "-Wno-unused-variable",
    ]
}
  • configs定義了該模塊編譯配置的環(huán)境變量speexdsp_nowarn_config,第24行ohos_shared_library定義了最終生成的模塊名,這里代表此模塊為最終生成libspeexdsp.z.so。所以在第五行到第七行中config中添加了編譯libspeexdsp.z.so需要添加的編譯器標(biāo)志
    • 但是"-Wno-implicit-function-declaration"、"-Wno-pointer-sign""、-Wno-unused-variable"并非是分析speexdsp原生庫(kù)得來(lái)的cflag編譯器標(biāo)志。
    • 而是后來(lái)在ohos上編譯驗(yàn)證過(guò)程中,根據(jù)編譯報(bào)錯(cuò)信息添加的。如果不添加它們,執(zhí)行./build.sh --product-name rk3568 --ccache --build-target=speexdsp命令后,則無(wú)法編譯生成openharmony上的運(yùn)行的libspeexdsp.z.so庫(kù),會(huì)出現(xiàn)編譯警告信息-W-implicit-function-declaration、-W-pointer-sign、-W-unused-variable。解決辦法就是在gn化時(shí)添加cflag標(biāo)志"-Wno-implicit-function-declaration"、"-Wno-pointer-sign""、-Wno-unused-variable"。
      image.png
      • clang編譯器警告消除:
        1.出現(xiàn)警告的就是直接在-W后面加no,比如-Wimplicit-function-declaration改為 -Wno-implicit-function-declaration
        2.還有另外的一種方法:-Wimplicit-function-declaration=no

第十一到第二十二行:

config("speexdsp_cflag_config"){
    cflags = [
         "-g",
         "-O2",
         "-fvisibility=hidden",
         "-DHAVE_CONFIG_H",

    ]
    ldflags = [
         "-lm"
    ]
}
  • configs定義了該模塊編譯配置的環(huán)境變量speexdsp_cflag_config,在第十三行到第十六行添加了編譯需要添加的編譯器標(biāo)志 "-g","-O2","-fvisibility=hidden", "-DHAVE_CONFIG_H"。
    • "-g","-O2","-fvisibility=hidden"通過(guò)分析原生庫(kù)config.log和makefile文件,具體請(qǐng)查看第二期內(nèi)容。
    • "-DHAVE_CONFIG_H"通過(guò)分析執(zhí)行build命令后編譯ohos上speexdsp的so庫(kù)報(bào)錯(cuò)信息得來(lái)
      image.png
      • 添加"-DHAVE_CONFIG_H"后仍然有報(bào)錯(cuò)信息,解決辦法是把linux下編譯speexdsp原生庫(kù)./configure后生成的config.h放置在thrid_party/speexdsp下。
        image.png

第二十四行到第五十二行:

ohos_shared_library("speexdsp_share") {
    sources = [
         "libspeexdsp/preprocess.c",
         "libspeexdsp/jitter.c",
         "libspeexdsp/mdf.c",
         "libspeexdsp/fftwrap.c",
         "libspeexdsp/filterbank.c",
         "libspeexdsp/resample.c",
         "libspeexdsp/buffer.c",
         "libspeexdsp/scal.c",
         "libspeexdsp/smallft.c",
         ]
         
    defines = [
        "NL_DEBUG",
        "speexdsp_EXPORTS",
    ]
    
    configs = [ 
         ":speexdsp_cflag_config", 
         ":speexdsp_nowarn_config"
    ] 
    include_dirs = [
         ".",
         "libspeexdsp",
         "include"
    ]
    part_name = "speexdsp"
}
  • 第24行ohos_shared_library定義了最終生成的模塊名,這里代表此模塊為最終生成libspeexdsp.z.so/動(dòng)態(tài)庫(kù)

如果是生成靜態(tài)庫(kù)ohos_static_library(" ") { }

  • 第二十五行到第三十五行sources模塊包含了需要編譯的源碼文件
  • 第四十六行到五十行include_dirs模塊包含了編譯依賴的頭文件路徑
  • 第五十一行part_name 該模塊編譯依賴的編譯子系統(tǒng)組件名。該配置項(xiàng)是為了模塊最終生成的so文件能在系統(tǒng)編譯完后自動(dòng)拷貝到系統(tǒng)目錄中。如果沒(méi)有配置該項(xiàng),系統(tǒng)編譯完后是不會(huì)自動(dòng)將生成的so文件拷貝到系統(tǒng)目錄。

測(cè)試用例gn化,新增工程構(gòu)建腳本

OpenHarmony/sources/third_party/speexdsp/libspeexdsp下添加BUILD.gn腳本文件。

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

config("test_nowarn_config"){
    cflags = [
         "-Wno-sign-compare",
         "-Wno-pointer-sign"
    ]
}


config("speexdsp_cflag_config") {
    ldflags = [ "-lm" ]
    cflags_cc = [
         "-g",
         "-O2",
         "-fvisibility=hidden",
    ]
}


config("speexdsp_config") {
    include_dirs = [
         "http://third_party/speexdsp/include"
     ]
}


ohos_executable("testdenoise"){
    public_configs = [ 
          ":speexdsp_config",
          ":test_nowarn_config"
    ]
    sources = [
         "testdenoise.c"
    ]
    configs = [
         ":speexdsp_cflag_config",

    ]
    
    deps = [
         "http://third_party/speexdsp:speexdsp_share"
    ]
    
    part_name = "speexdsp"
}

ohos_executable("testecho"){
    public_configs = [ 
          ":speexdsp_config",
          ":test_nowarn_config"
    ]
    sources = [
         "testecho.c"
    ]
    
    configs = [
         ":speexdsp_cflag_config"
    ]
    
    deps = [
         "http://third_party/speexdsp:speexdsp_share"
    ]
    
    part_name = "speexdsp"
}

ohos_executable("testjitter"){
    public_configs = [ 
          ":speexdsp_config",
          ":test_nowarn_config"
    ]
    sources = [
         "testjitter.c"
    ]
    
    configs = [
         ":speexdsp_cflag_config"
    ]
    
    deps = [
         "http://third_party/speexdsp:speexdsp_share"
    ]
    
    part_name = "speexdsp"
}

ohos_executable("testresample"){
    public_configs = [ 
          ":speexdsp_config",
          ":test_nowarn_config"
    ]
    sources = [
         "testresample.c"
    ]
    
    configs = [
         ":speexdsp_cflag_config"
    ]
    
    deps = [
         "http://third_party/speexdsp:speexdsp_share"
    ]
    
    part_name = "speexdsp"
}

ohos_executable("testresample2"){
     public_configs = [ 
          ":speexdsp_config",
          ":test_nowarn_config"
    ]
    sources = [
         "testresample2.c"
    ]
    
    configs = [
         ":speexdsp_cflag_config"
    ]
    
    deps = [
         "http://third_party/speexdsp:speexdsp_share"
    ]
    part_name = "speexdsp"
    
}

代碼解析

測(cè)試用例gn化代碼解析的內(nèi)容與speexdsp編譯gn化內(nèi)容相似,這里不做重復(fù)解釋,只補(bǔ)充以下幾點(diǎn)。

  • 測(cè)試用例是在ohos上測(cè)試libspeexdsp.z.so功能用的。
  • 第28、48、68、88、108行:gn中的目標(biāo)類型executable表示生成可執(zhí)行文件testdenoise、testecho、testjitter、testresample、testresample2。
  • 第41、61、81、101、121行:deps表示測(cè)試用例模塊編譯依賴其他模塊,這里指的是測(cè)試用例的編譯依賴。libspeexdsp.z.so庫(kù)。
  • 第45、65、85、105、125行:part_name表示測(cè)試用例模塊編譯依賴的編譯子系統(tǒng)組件名。該配置項(xiàng)是為了模塊最終生成的so文件能在系統(tǒng)編譯完后自動(dòng)拷貝到系統(tǒng)目錄中。如果沒(méi)有配置該項(xiàng),系統(tǒng)編譯完后是不會(huì)自動(dòng)將生成的so文件拷貝到系統(tǒng)目錄。

OpenHarmony/sources/third_party/speexdsp目錄下添加ohos.build。

  • 定義子系統(tǒng)并加入到編譯框架
    在系統(tǒng)源碼根目錄下創(chuàng)建一個(gè)目錄作為子系統(tǒng)目錄,子系統(tǒng)目錄可創(chuàng)建在OpenHarmony源碼目錄任意位置。
    • 本項(xiàng)目以third_party/speexdsp作為為子系統(tǒng)目錄,子系統(tǒng)名字即為speexdsp。

子系統(tǒng)speexdsp目錄下創(chuàng)建ohos.build文件,build構(gòu)建時(shí)會(huì)先讀取該文件。

"subsystem": "speexdsp",
  "parts": {
    "speexdsp": {
      "module_list": [
        "http://third_party/speexdsp/libspeexdsp:testdenoise",
        "http://third_party/speexdsp/libspeexdsp:testecho",
        "http://third_party/speexdsp/libspeexdsp:testjitter",
        "http://third_party/speexdsp/libspeexdsp:testresample",
        "http://third_party/speexdsp/libspeexdsp:testresample2"
      ],
      "inner_kits": [
              ],
      "system_kits": [
      ],
      "test_list": [
      ]
    }
  }
}
  • build文件夾下的subsystem_config.json文件,主要包含子系統(tǒng)名稱與路徑信息,在preloader階段被加載,根據(jù)子系統(tǒng)名稱和路徑信息查找該路徑下的ohos.build文件。
  • 其中需要包含module_list、inner_kits、system_kits、test_list四個(gè)部分的聲明:
    • module_list:部件包含的模塊列表
    • inner_kits:部件提供其它部件的接口
    • system_kits:部件提供給生成應(yīng)用的接口
    • test_list:部件對(duì)應(yīng)模塊的測(cè)試用例

修改build/subsystem_config.json,新增子系統(tǒng)定義。

在源碼/build/subsystem_config.json中增加子系統(tǒng)選項(xiàng),把子系統(tǒng)speexdsp配置到build/subsystem_config.json。

"speexdsp": {
    "path": "third_party/speexdsp",
    "name": "speexdsp"
  },

注意:要求符合json語(yǔ)法規(guī)范,要在}前加,(如下圖所示)
image.png

修改vendor/hihope/rk3568/config.json文件將speexdsp添加至rk3568開(kāi)發(fā)板,在vendor目錄下新增產(chǎn)品的定義。

將子系統(tǒng)及其組件加入產(chǎn)品定義中,以rk3568為例,產(chǎn)品定義文件在vendor/hihope/rk3568/config.json,需要將以下內(nèi)容添加到config.json中:

{
      "subsystem": "speexdsp",
      "components": [
        {
          "component": "speexdsp",
          "features": []
        }
      ]
    },

下期分享內(nèi)容:在OpenHarmony的編譯體系下編譯speexdsp的so和測(cè)試用的可執(zhí)行文件,以及編譯報(bào)錯(cuò)的解決辦法

知識(shí)點(diǎn)附送

本文中知識(shí)點(diǎn)附送的內(nèi)容并不和移植speexdsp到openharmony標(biāo)準(zhǔn)系統(tǒng)直接相關(guān),僅作為拓展閱讀的知識(shí)點(diǎn),因此讀者可以不作過(guò)細(xì)的了解。

gn

generate ninja工具,在out目錄下生成ninja編譯文件*.ninja,gn的可執(zhí)行文件位置在prebuilts/build-tools/linux-x86目錄里

jiajiahao@ubuntu:~/Desktop/OpenHarmony/sources/prebuilts/build-tools/linux-x86/bin$ ./gn --help

Commands (type "gn help " for more help):
  analyze: Analyze which targets are affected by a list of files.
  args: Display or configure arguments declared by the build.
  check: Check header dependencies.
  clean: Cleans the output directory.
  desc: Show lots of insightful information about a target or config.
  format: Format .gn files.
  gen: Generate ninja files.
  help: Does what you think.
  ls: List matching targets.
  meta: List target metadata collection results.
  path: Find paths between two targets.
  refs: Find stuff referencing a target or file.

Target declarations (type "gn help " for more help):
  action: Declare a target that runs a script a single time.
  action_foreach: Declare a target that runs a script over a set of files.
  bundle_data: [iOS/macOS] Declare a target without output.
  copy: Declare a target that copies files.
  create_bundle: [iOS/macOS] Build an iOS or macOS bundle.
  executable: Declare an executable target.
  generated_file: Declare a generated_file target.
  group: Declare a named group of targets.
  loadable_module: Declare a loadable module target.
  rust_library: Declare a Rust library target.
  rust_proc_macro: Declare a Rust procedural macro target.
  shared_library: Declare a shared library target.
  source_set: Declare a source set target.
  static_library: Declare a static library target.
  target: Declare an target with the given programmatic type.

Buildfile functions (type "gn help " for more help):
  assert: Assert an expression is true at generation time.
  config: Defines a configuration object.
  declare_args: Declare build arguments.
  defined: Returns whether an identifier is defined.
  exec_script: Synchronously run a script and return the output.
  foreach: Iterate over a list.
  forward_variables_from: Copies variables from a different scope.
  get_label_info: Get an attribute from a target's label.
  get_path_info: Extract parts of a file or directory name.
  get_target_outputs: [file list] Get the list of outputs from a target.
  getenv: Get an environment variable.
  import: Import a file into the current scope.
  not_needed: Mark variables from scope as not needed.
  pool: Defines a pool object.
  print: Prints to the console.
  process_file_template: Do template expansion over a list of files.
  read_file: Read a file into a variable.
  rebase_path: Rebase a file or directory to another location.
  set_default_toolchain: Sets the default toolchain name.
  set_defaults: Set default values for a target type.
  set_sources_assignment_filter: Set a pattern to filter source files.
  split_list: Splits a list into N different sub-lists.
  string_join: Concatenates a list of strings with a separator.
  string_replace: Replaces substring in the given string.
  string_split: Split string into a list of strings.
  template: Define a template rule.
  tool: Specify arguments to a toolchain tool.
  toolchain: Defines a toolchain.
  write_file: Write a file to disk.

Built-in predefined variables (type "gn help " for more help):
  current_cpu: [string] The processor architecture of the current toolchain.
  current_os: [string] The operating system of the current toolchain.
  current_toolchain: [string] Label of the current toolchain.
  default_toolchain: [string] Label of the default toolchain.
  gn_version: [number] The version of gn.
  host_cpu: [string] The processor architecture that GN is running on.
  host_os: [string] The operating system that GN is running on.
  invoker: [string] The invoking scope inside a template.
  python_path: [string] Absolute path of Python.
  root_build_dir: [string] Directory where build commands are run.
  root_gen_dir: [string] Directory for the toolchain's generated files.
  root_out_dir: [string] Root directory for toolchain output files.
  target_cpu: [string] The desired cpu architecture for the build.
  target_gen_dir: [string] Directory for a target's generated files.
  target_name: [string] The name of the current target.
  target_os: [string] The desired operating system for the build.
  target_out_dir: [string] Directory for target output files.

Variables you set in targets (type "gn help " for more help):
  aliased_deps: [scope] Set of crate-dependency pairs.
  all_dependent_configs: [label list] Configs to be forced on dependents.
  allow_circular_includes_from: [label list] Permit includes from deps.
  arflags: [string list] Arguments passed to static_library archiver.
  args: [string list] Arguments passed to an action.
  asmflags: [string list] Flags passed to the assembler.
  assert_no_deps: [label pattern list] Ensure no deps on these targets.
  bundle_contents_dir: Expansion of {{bundle_contents_dir}} in create_bundle.
  bundle_deps_filter: [label list] A list of labels that are filtered out.
  bundle_executable_dir: Expansion of {{bundle_executable_dir}} in create_bundle
  bundle_resources_dir: Expansion of {{bundle_resources_dir}} in create_bundle.
  bundle_root_dir: Expansion of {{bundle_root_dir}} in create_bundle.
  cflags: [string list] Flags passed to all C compiler variants.
  cflags_c: [string list] Flags passed to the C compiler.
  cflags_cc: [string list] Flags passed to the C++ compiler.
  cflags_objc: [string list] Flags passed to the Objective C compiler.
  cflags_objcc: [string list] Flags passed to the Objective C++ compiler.
  check_includes: [boolean] Controls whether a target's files are checked.
  code_signing_args: [string list] Arguments passed to code signing script.
  code_signing_outputs: [file list] Output files for code signing step.
  code_signing_script: [file name] Script for code signing.
  code_signing_sources: [file list] Sources for code signing step.
  complete_static_lib: [boolean] Links all deps into a static library.
  configs: [label list] Configs applying to this target or config.
  contents: Contents to write to file.
  crate_name: [string] The name for the compiled crate.
  crate_root: [string] The root source file for a binary or library.
  crate_type: [string] The type of linkage to use on a shared_library.
  data: [file list] Runtime data file dependencies.
  data_deps: [label list] Non-linked dependencies.
  data_keys: [string list] Keys from which to collect metadata.
  defines: [string list] C preprocessor defines.
  depfile: [string] File name for input dependencies for actions.
  deps: [label list] Private linked dependencies.
  externs: [scope] Set of Rust crate-dependency pairs.
  framework_dirs: [directory list] Additional framework search directories.
  frameworks: [name list] Name of frameworks that must be linked.
  friend: [label pattern list] Allow targets to include private headers.
  include_dirs: [directory list] Additional include directories.
  inputs: [file list] Additional compile-time dependencies.
  ldflags: [string list] Flags passed to the linker.
  lib_dirs: [directory list] Additional library directories.
  libs: [string list] Additional libraries to link.
  metadata: [scope] Metadata of this target.
  output_conversion: Data format for generated_file targets.
  output_dir: [directory] Directory to put output file in.
  output_extension: [string] Value to use for the output's file extension.
  output_name: [string] Name for the output file other than the default.
  output_prefix_override: [boolean] Don't use prefix for output name.
  outputs: [file list] Output files for actions and copy targets.
  partial_info_plist: [filename] Path plist from asset catalog compiler.
  pool: [string] Label of the pool used by the action.
  precompiled_header: [string] Header file to precompile.
  precompiled_header_type: [string] "gcc" or "msvc".
  precompiled_source: [file name] Source file to precompile.
  product_type: [string] Product type for Xcode projects.
  public: [file list] Declare public header files for a target.
  public_configs: [label list] Configs applied to dependents.
  public_deps: [label list] Declare public dependencies.
  rebase: [boolean] Rebase collected metadata as files.
  response_file_contents: [string list] Contents of .rsp file for actions.
  script: [file name] Script file for actions.
  sources: [file list] Source files for a target.
  testonly: [boolean] Declares a target must only be used for testing.
  visibility: [label list] A list of labels that can depend on a target.
  walk_keys: [string list] Key(s) for managing the metadata collection walk.
  write_runtime_deps: Writes the target's runtime_deps to the given path.
  xcode_extra_attributes: [scope] Extra attributes for Xcode projects.
  xcode_test_application_name: [string] Name for Xcode test target.

Other help topics:
  all: Print all the help at once
  buildargs: How build arguments work.
  dotfile: Info about the toplevel .gn file.
  execution: Build graph and execution overview.
  grammar: Language and grammar for GN build files.
  input_conversion: Processing input from exec_script and read_file.
  label_pattern: Matching more than one label.
  labels: About labels.
  metadata_collection: About metadata and its collection.
  ninja_rules: How Ninja build rules are named.
  nogncheck: Annotating includes for checking.
  output_conversion: Specifies how to transform a value to output.
  runtime_deps: How runtime dependency computation works.
  source_expansion: Map sources to outputs for scripts.
  switches: Show available command-line switches.

ninja

ninja構(gòu)建工具,編譯時(shí)根據(jù)gn生成的*.ninja文件進(jìn)行編譯構(gòu)建,ninjiad的可執(zhí)行文件位置在prebuilts/build-tools/linux-x86目錄里

jiajiahao@ubuntu:~/Desktop/OpenHarmony/sources/prebuilts/build-tools/linux-x86/bin$ ./ninja --help
usage: ninja [options] [targets...]

if targets are unspecified, builds the 'default' target (see manual).

options:
  --version      print ninja version ("1.10.1")
  -v, --verbose  show all command lines while building

  -C DIR   change to DIR before doing anything else
  -f FILE  specify input build file [default=build.ninja]

  -j N     run N jobs in parallel (0 means infinity) [default=18 on this system]
  -k N     keep going until N jobs fail (0 means infinity) [default=1]
  -l N     do not start new jobs if the load average is greater than N
  -n       dry run (don't run commands but act like they succeeded)

  -d MODE  enable debugging (use '-d list' to list modes)
  -t TOOL  run a subtool (use '-t list' to list subtools)
    terminates toplevel options; further flags are passed to the tool
  -w FLAG  adjust warnings (use '-w list' to list warnings)

關(guān)于deps、external_deps的使用

在添加一個(gè)模塊的時(shí)候,需要在BUILD.gn中聲明它的依賴,為了便于后續(xù)處理部件間依賴關(guān)系,我們將依賴分為兩種——部件內(nèi)依賴deps和部件間依賴external_deps。

依賴分類:

image.png

如上圖所示,主要分為部件內(nèi)依賴(圖左)和部件間依賴(圖右)。

部件內(nèi)依賴: 現(xiàn)有模塊module1屬于部件part1,要添加一個(gè)屬于部件part1的模塊module2,module2依賴于module1,這種情況就屬于部件內(nèi)依賴。

部件間依賴: 現(xiàn)有模塊module1屬于部件part1,要添加一個(gè)模塊module2,module2依賴于module1,module2屬于部件part2。模塊module2與模塊module1分屬于兩個(gè)不同的部件,這種情況就屬于部件間依賴。

部件內(nèi)依賴示例:

import("http://build/ohos.gni")
ohos_shared_library("module1") {
  ……
  part_name = "part1"   # 必選,所屬部件名稱
  ……
}
import("http://build/ohos.gni")
ohos_shared_library("module2") {
  ……
  deps = [
    "module1的gn target",
  ……
 ]                        # 部件內(nèi)模塊依賴
part_name = "part1"       # 必選,所屬部件名稱
}

部件間依賴示例:

import("http://build/ohos.gni")
ohos_shared_library("module1") {
  ……
  part_name = "part1"   # 必選,所屬部件名稱
  ……
}
import("http://build/ohos.gni")
ohos_shared_library("module2") {
  ……
  external_deps = [
    "part1:module1",
  ……
  ]                      # 部件間模塊依賴,這里依賴的模塊必須是依賴的部件聲明在inner_kits中的模塊
  part_name = "part2"    # 必選,所屬部件名稱
}

注意:部件間依賴要寫在external_deps里面,格式為”部件名:模塊名"的形式,并且依賴的模塊必須是依賴的部件聲明在inner_kits中的模塊。

查看.ninja_log文件可以知道每個(gè)模塊編譯的開(kāi)始和結(jié)束時(shí)間

out/rk3568/.ninja_log文件記錄了每個(gè)模塊編譯的開(kāi)始和結(jié)束時(shí)間(ms),結(jié)束時(shí)間和開(kāi)始時(shí)間間隔越短表示模塊的編譯時(shí)間越短,編譯性能越高。

從左到右分別表示:start time|end time|mtime|command hash。
mtime(modify time)顯示的是文件內(nèi)容被修改的最后時(shí)間

image.png

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • dayu200
    +關(guān)注

    關(guān)注

    1

    文章

    26

    瀏覽量

    1403
  • 潤(rùn)和軟件
    +關(guān)注

    關(guān)注

    1

    文章

    307

    瀏覽量

    1105
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    北京迅為RK3568開(kāi)發(fā)板OpenHarmony系統(tǒng)南向驅(qū)動(dòng)開(kāi)發(fā)內(nèi)核HDF驅(qū)動(dòng)框架架構(gòu)

    北京迅為RK3568開(kāi)發(fā)板OpenHarmony系統(tǒng)南向驅(qū)動(dòng)開(kāi)發(fā)內(nèi)核HDF驅(qū)動(dòng)框架架構(gòu)
    的頭像 發(fā)表于 03-11 14:13 ?886次閱讀
    北京迅為RK3568<b class='flag-5'>開(kāi)發(fā)板</b><b class='flag-5'>OpenHarmony</b><b class='flag-5'>系統(tǒng)</b>南向驅(qū)動(dòng)<b class='flag-5'>開(kāi)發(fā)</b>內(nèi)核HDF驅(qū)動(dòng)框架架構(gòu)

    基于OpenHarmony標(biāo)準(zhǔn)系統(tǒng)的C++公共基礎(chǔ)類庫(kù)案例:ThreadPoll

    1、程序簡(jiǎn)介該程序是基于OpenHarmony標(biāo)準(zhǔn)系統(tǒng)的C++公共基礎(chǔ)類庫(kù)的線程池處理:ThreadPoll。本案例完成如下工作:創(chuàng)建1個(gè)線程池,設(shè)置該線程池內(nèi)部有1024個(gè)線程空間。啟動(dòng)5個(gè)線程
    的頭像 發(fā)表于 02-10 18:09 ?212次閱讀
    基于<b class='flag-5'>OpenHarmony</b><b class='flag-5'>標(biāo)準(zhǔn)系統(tǒng)</b>的C++公共基礎(chǔ)類庫(kù)案例:ThreadPoll

    OpenHarmony源碼編譯后燒錄鏡像教程,RK3566鴻蒙開(kāi)發(fā)板演示

    本文介紹瑞芯微主板/開(kāi)發(fā)板編譯OpenHarmony源碼后燒錄鏡像的教程,觸覺(jué)智能Purple Pi OH鴻蒙開(kāi)發(fā)板演示。搭載了瑞芯微RK3566四核處理器,樹(shù)莓派卡片電腦設(shè)計(jì),支持開(kāi)源鴻蒙O
    的頭像 發(fā)表于 12-30 10:08 ?496次閱讀
    <b class='flag-5'>OpenHarmony</b>源碼編譯后燒錄鏡像教程,RK3566鴻蒙<b class='flag-5'>開(kāi)發(fā)板</b>演示

    dayu200 rk3568 openharmony5.0 sim卡 通話服務(wù)

    想請(qǐng)問(wèn)一下有人在dayu200 rk3568上插過(guò)sim卡并且成功完成過(guò)通話服務(wù)嗎? 我現(xiàn)在在dayu200上燒錄了openHarmony release 5.0.0版本的鏡像,在上面插上了sim卡,但是仍然顯示未檢測(cè)到sim卡
    發(fā)表于 12-26 16:52

    OpenHarmony怎么修改DPI密度值?觸覺(jué)智能RK3566鴻蒙開(kāi)發(fā)板演示

    開(kāi)源鴻蒙OpenHarmony系統(tǒng)下,修改DPI密度值的方法,觸覺(jué)智能Purple Pi OH鴻蒙開(kāi)發(fā)板演示,搭載了瑞芯微RK3566四核處理器,Laval鴻蒙社區(qū)推薦開(kāi)發(fā)板,已適配全
    的頭像 發(fā)表于 12-24 11:46 ?504次閱讀
    <b class='flag-5'>OpenHarmony</b>怎么修改DPI密度值?觸覺(jué)智能RK3566鴻蒙<b class='flag-5'>開(kāi)發(fā)板</b>演示

    戈帥《OpenHarmony輕量系統(tǒng)從入門精通50例》開(kāi)發(fā)板與傳感器配置說(shuō)明

    戈帥《OpenHarmony輕量系統(tǒng)從入門精通50例》開(kāi)發(fā)板與傳感器配置說(shuō)明,請(qǐng)查看附件*附件:《OpenHarmony輕量
    發(fā)表于 12-03 15:46

    基于ArkTS語(yǔ)言的OpenHarmony APP應(yīng)用開(kāi)發(fā):HelloOpenharmony

    1、程序簡(jiǎn)介該程序是基于OpenHarmony標(biāo)準(zhǔn)系統(tǒng)編寫的UI應(yīng)用類:HelloOpenHarmony。本案例是基于API9接口開(kāi)發(fā)。本案例已在O
    的頭像 發(fā)表于 09-15 08:09 ?697次閱讀
    基于ArkTS語(yǔ)言的<b class='flag-5'>OpenHarmony</b> APP應(yīng)用<b class='flag-5'>開(kāi)發(fā)</b>:Hello<b class='flag-5'>Openharmony</b>

    瑞芯微RK3566鴻蒙開(kāi)發(fā)板OpenHarmony標(biāo)準(zhǔn)系統(tǒng)應(yīng)用兼容性測(cè)試指導(dǎo)

    本文OpenHarmony標(biāo)準(zhǔn)系統(tǒng)應(yīng)用兼容性測(cè)試指導(dǎo),適用鴻蒙系統(tǒng)軟件開(kāi)發(fā)測(cè)試的新手入門學(xué)習(xí)課程,設(shè)備為觸覺(jué)智能的瑞芯微RK3566開(kāi)發(fā)板,型號(hào)Purple Pi OH。是Laval官
    的頭像 發(fā)表于 09-10 11:56 ?872次閱讀
    瑞芯微RK3566鴻蒙<b class='flag-5'>開(kāi)發(fā)板</b><b class='flag-5'>OpenHarmony</b><b class='flag-5'>標(biāo)準(zhǔn)系統(tǒng)</b>應(yīng)用兼容性測(cè)試指導(dǎo)

    Openharmony軟件評(píng)估指南-米爾瑞芯微RK3568開(kāi)發(fā)板

    Openharmony軟件評(píng)估指南用于介紹在米爾的開(kāi)發(fā)板上運(yùn)行Openharmony系統(tǒng)下的核心資源與外設(shè)資源的測(cè)試步驟與評(píng)估方法。本文可作
    發(fā)表于 09-06 20:06

    請(qǐng)求推薦無(wú)需NPU的OpenHarmony標(biāo)準(zhǔn)系統(tǒng)ARM開(kāi)發(fā)板

    請(qǐng)教一下大佬們,目前的需求是在國(guó)產(chǎn)ARM開(kāi)發(fā)板上跑OpenHarmony標(biāo)準(zhǔn)系統(tǒng),無(wú)需NPU/GPU,其它配置(CPU、RAM等)可以盡量高點(diǎn),價(jià)位在2k以內(nèi),球球推薦!感謝大佬們!
    發(fā)表于 08-16 16:25

    潤(rùn)開(kāi)鴻“龍芯+OpenHarmony開(kāi)發(fā)平臺(tái)DAYU431先鋒派新品發(fā)布

    潤(rùn)開(kāi)鴻基于全新龍芯2K0300芯片平臺(tái)的重磅新品潤(rùn)開(kāi)鴻HH-SCDAYU431先鋒派開(kāi)發(fā)平臺(tái)正式上市,成為潤(rùn)開(kāi)鴻DAYU系列產(chǎn)品中符合
    的頭像 發(fā)表于 08-07 14:50 ?828次閱讀
    <b class='flag-5'>潤(rùn)</b>開(kāi)鴻“龍芯+<b class='flag-5'>OpenHarmony</b>”<b class='flag-5'>開(kāi)發(fā)</b>平臺(tái)<b class='flag-5'>DAYU</b>431先鋒派新品發(fā)布

    鴻蒙OpenHarmony南向/北向快速開(kāi)發(fā)教程-迅為RK3568開(kāi)發(fā)板

    大家期待已久的迅為RK3568開(kāi)發(fā)板終于迎來(lái)了鴻蒙4.1系統(tǒng)的強(qiáng)勢(shì)支持!想知道如何實(shí)現(xiàn)快速開(kāi)發(fā)學(xué)習(xí)嗎?跟著我們一起來(lái)探索吧! 迅為RK3568開(kāi)發(fā)板: 想象一下,你手中的RK3568
    發(fā)表于 07-23 10:44

    鴻蒙OpenHarmony【基于Hi3516DV300開(kāi)發(fā)板(時(shí)鐘應(yīng)用開(kāi)發(fā))】

    如何快速搭建基于OpenHarmony標(biāo)準(zhǔn)系統(tǒng)(Hi3516DV300開(kāi)發(fā)板)的應(yīng)用開(kāi)發(fā)環(huán)境,并基于一個(gè)時(shí)鐘APP示例逐步展示應(yīng)用的創(chuàng)建、開(kāi)發(fā)
    的頭像 發(fā)表于 05-08 15:27 ?1473次閱讀
    鴻蒙<b class='flag-5'>OpenHarmony</b>【基于Hi3516DV300<b class='flag-5'>開(kāi)發(fā)板</b>(時(shí)鐘應(yīng)用<b class='flag-5'>開(kāi)發(fā)</b>)】

    鴻蒙OpenHarmony南向:【Hi3516標(biāo)準(zhǔn)系統(tǒng)入門(命令行方式)】

    除小型系統(tǒng)外,Hi3516DV300開(kāi)發(fā)板還支持標(biāo)準(zhǔn)系統(tǒng)。此章節(jié)簡(jiǎn)要介紹如何使用命令行在Hi3516DV300開(kāi)發(fā)板上進(jìn)行標(biāo)準(zhǔn)系統(tǒng)
    的頭像 發(fā)表于 05-08 09:26 ?1109次閱讀
    鴻蒙<b class='flag-5'>OpenHarmony</b>南向:【Hi3516<b class='flag-5'>標(biāo)準(zhǔn)系統(tǒng)</b>入門(命令行方式)】

    鴻蒙OpenHarmony標(biāo)準(zhǔn)系統(tǒng) 運(yùn)行】(基于RK3568開(kāi)發(fā)板

    燒錄完成重啟開(kāi)發(fā)板后,系統(tǒng)將會(huì)自動(dòng)啟動(dòng)。開(kāi)發(fā)板附帶的屏幕呈現(xiàn)以下界面,表明系統(tǒng)已運(yùn)行成功。
    的頭像 發(fā)表于 05-06 15:38 ?616次閱讀
    鴻蒙<b class='flag-5'>OpenHarmony</b>【<b class='flag-5'>標(biāo)準(zhǔn)系統(tǒng)</b> 運(yùn)行】(基于RK3568<b class='flag-5'>開(kāi)發(fā)板</b>)