啃論文俱樂部—移植Speexdsp到OpenHarmony標準系統(六)
- 大家好!我來自南京,在OpenHarmony成長計劃啃論文俱樂部,與華為、軟通動力、潤和軟件、拓維信息、深開鴻?等公司一起,學習和研究?操作系統技術從今年1月11日加入OpenHarmony俱樂部已經有接近8個月時間了。筆者一直在思考啃論文給我帶來了些什么,通過啃論文能為OpenHarmony做些什么。筆者利用大二升大三暑假兩個月時間移植了Speexdsp這個三方庫到OpenHarmony標準系統,而關于前面的問題我似乎找到了答案,現將啃論文和三方庫移植分享經驗如下:
九、準備好上傳speexdsp至OpenHarmony倉庫。
移植完成后,先將代碼上傳至??sig倉中的contest倉??。
sig倉庫是TPC倉庫的孵化倉。代碼先上sig倉,到時會直接平移到tpc倉。
上傳的內容包括:
- 原生庫代碼。
- (除了涉及需要修改原生庫代碼的部分,其他都不能上傳,例如編譯途中生成的中間文件)。
- BUILD.gn。
- README.Opensource。
- 庫對外導出的所有api接口export_api.txt。
- 測試過的api接口tested_api.txt。
- 功能測試文檔: 三方庫_test_function.md。
- 內容至少包含羅列出庫所有的功能,已測試過的功能,原生庫測試邏輯的分析。
- 原生庫分析文檔: 三方庫_analyse.md。
文檔命名不要用中文,如果涉及到編碼問題的話,到時候會出現亂碼,一般建議不用中文命名!
提供OAT.xml文件:
OAT開源掃描
- OAT(OSS Audit Tool)是OpenHarmony社區的自動化開源審視工具,用于幫助開發人員基于自定義的規則自動掃描開源倉代碼,識別不符合預定規則的代碼并輸出掃描報告。
- OAT下載地址:https://gitee.com/openharmony-sig/tools_oat。
工具使用
編譯構建:
- 在linux上安裝好java和Maven后,下載OAT工具源碼,執行mvn package完成構建。
- 編譯構建成功
在父目錄下添加OAT.xml,內容如下:
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
-->
<configuration>
<oatconfig>
<licensefile>COPYING</licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<!--policyitem type="compatibility" name="GPL-2.0+" path="abc/.*" desc="Process that runs independently, invoked by the X process."/-->
<policyitem type="license" name="*" path=".*" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter" desc=""/>
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filepath" name=".*" desc="原生庫文件"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
<filteritem type="filepath" name=".*" desc="原生庫代碼"/>
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
<filteritem type="filepath" name=".*" desc="原生庫代碼"/>
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
</filefilterlist>
<licensematcherlist>
<!--licensematcher name="uvwxyz License" desc="If the scanning result is InvalidLicense, you can define matching rules here. Note that quotation marks must be escaped.">
<licensetext name="
uvwxyz license textA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
" desc=""/>
<licensetext name="
uvwxyz license textB xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
" desc=""/>
</licensematcher-->
</licensematcherlist>
</oatconfig>
</configuration>
在speexdsp根目錄下新建空白的OAT_report.text文件,執行命令:
Java –jar ohos_ossaudittool-1.0.jar –s src_dir –r report_file –n selfcheck
- ohos_ossaudittool-1.0.jar 工具包名,需要帶實際路徑。
- -s 指定需要檢查的代碼目錄,src_dir 改成要檢查的項目路徑。
- -r 指定報告輸出文件的路徑,檢查完成后可查看此文件中列出的問題,按指導文檔修復。
- report_file。
- -n 檢查任務的名稱,任意指定,本地檢查使用不上。
例如筆者執行的語句為:
sudo java -Dfile.encoding=UTF-8 -jar /home/jiajiahao/Desktop/tools_oat-master/target/ohos_ossaudittool-1.0.jar -s /home/jiajiahao/Desktop/gitee_speexdsp -r /home/jiajiahao/Desktop/gitee_speexdsp/OAT_report.text -n nameOfRepo
掃描結果
執行完上述命令后,OAT_report.text生成內容如下:
同時在speexdsp父目錄下生成log文件夾。
- LicenseFile.txt位于OAT工具運行目錄的log目錄下,此文件記錄掃描目錄下所有疑似許可證的文件。
原生庫通過make或者cmake時生成的一些配置文件。如比較通用的config.h配置文件,config.h文件為原生庫生成文件,原則上也不做修改,為了避免文件上倉進行代碼掃碼,可以將文件文件修改后綴名(config.h.in)。相關文檔中需要將配置文件使用方法說明。
提供README.OpenSource文件
README.Opensource的格式如下:
[
{
"Name": "", ## 庫名
"License": "", ## 開源協議
"License File": ", ## 開源文件,一般開源項目都會自帶該文件
"Version Number": "", ## 庫的版本
"Owner": "", ## 作者
"Upstream URL": "", ## 開源庫的地址
"Description": "" ## 庫的描述
}
]
speexdsp的README.OpenSource文件如下:
[
{
"Name": "speexdsp",
"License": "BSD-3-Clause",
"License File": "COPYING",
"Version Number": "1.2.1",
"Owner": "2692032597@qq.com",
"Upstream URL": "https://speex.org/",
"Description": "Speexdsp is a speech processing library that goes along with the Speex codec"
}
]
提供庫的分析文檔
三方庫分析文檔如下:
一、確定庫實現方式
例如:C/C++/JS/JAVA
二.依賴分析
例如:當前庫依賴其他三方庫,如下
1)庫名1,庫倉庫地址
2)庫名2,庫倉庫地址
三、license以及版權
例如:一般在license文件或者COPYING中,Apache License V2.0
四、最新一次版本
xx年xx月xx日,版本號xxx
五、功能點分析
(羅列出該庫所支持的功能)
六、代碼規模
(統計庫代碼總行數,包括.h/.hpp/.c/.cpp/.cc 等代碼相關文件)
提供功能測試文檔
文檔中需羅列出:
- 庫所有的功能
- 已測試過的功能
- 原生庫測試邏輯的分析
提供導出的api接口列表
- 導出庫對外暴露的所有api接口的列表。
- 導出庫對外暴露的已測試api接口的列表。
十、上傳speexdsp至OpenHarmony倉庫
配置個人信息
打開git bash,依次輸入以下命令:
git config --global user.name "xxxx" (配置用戶名,xxxx為賬號用戶名,即個人空間地址)
git config --global user.email "xxxxxx@xxx" (gitee 賬號郵箱與簽署DCO 的郵箱保持一致即可)
git config --list (查看配置情況)
git config --global credential.helper store (解決每次git pull都要輸入賬號信息的問題)
克隆倉庫內容到本地
到個人賬號點擊并進入??contest倉庫??, fork該倉庫:
進入到clone界面,復制clone的鏈接地址。
執行如下語句:
git clone https://gitee.com/xxxxx/contest.git --depth=1
- –depth=1意思是只clone當前倉庫最新版本,省去一些歷史log,避免倉庫歷史記錄過于龐大花費太多clone時間。
- clone完畢之后,即可在本地目錄下看到這個clone的倉庫。本地目錄所在位置是根據git bash的位置決定的,比如在桌面啟動git bash,則clone的倉庫會出現在桌面。
利用git lfs機制添加特殊文件
提交三方庫時候,文檔中有PDF文件時就需要使用利用git lfs機制。
git lfs track xxx/xxx.pdf // 聲明該特殊文件到git lfs機制
git add .gitattributes // 添加配置文件
git add xxx/xxx.pdf // 添加具體特殊文件到暫存區中
git lfs ls-files // 確認相關test_lfs.a 文件是否已經添加到lfs 機制中。
git add * //將變更文件加入到暫存區
git commit -s -m "add:知識體系7_10 日心得" //將暫存區內容簽名并提交到本地
- -s是簽名表明這次提交者簽名(signoff)。
- -m是對此次提交行為進行備注。
推送本地修改到賬號倉庫
現在需要將本地倉庫的修改內容推送到gitee上fork后的個人倉庫,使用git push命令來完成這個動作。
git push origin master
- origin指的是自己的倉庫對應的原始遠程服務器地址。
- master標識的是想要提交的分支。
- 可以使用 git remote -v查看配置的遠程服務器。
- git branch -a查看所有的分支。
進入自己的賬號下面,查看這個倉庫,發現已經發生了變化。從個人賬號倉庫下向官方倉庫下提交PR。
進入個人賬號的該倉庫下,點擊增加PR即可開始提交PR。
提交pr時,push的文件超過100個文件,在pr頁面只顯示100個。