激光切割機編程軟件

編譯 Flutter Engine
安裝 depot_tools :
$ pwd
/Users/sunhao/developmchromium.googlesource.com/chromium/tools/depot_tools.git
複製代碼配置環境變量:建議在 ~/.bash_profile 文件中添加
export PATH=/Users/sunhao/development/depot_tools/:$PATH
複製代碼然後執行
$ source ~/.bash_profile
複製代碼當然,你也可以配置臨時環境變量
$ export PATH=$PATH:/Users/sunhao/development/depot_tools/
複製代碼2、將 engine 項目 fork 到自己的github
關於 github 的使用,這裏不多說了,fork 過來,添加 github 的 ssh key 信任。
我這裏的地址爲:github.com/loosaSH/eng…
3、創建項目目錄
你可以創建一個目錄,名稱推薦爲 engine,後面的步驟會自動執行 clone 。
$ pwd
/Users/sunhao/development
$ mkdir engine
複製代碼4、創建 .gclient 文件
進入engine 目錄,創建 .gclient 文件
$ cd engine
$ vim .gclient
複製代碼寫入如下內容:
solutions = [
{
“managed”: False,
“name”: “src/flutter”,
“url”: “[email protected]:<your_name_here>/engine.git”,
“custom_deps”: {},
“deps_file”: “DEPS”,
“safesync_url”: “”,
},
]
複製代碼將 <your_name_here> 換成你的 GitHub 名字,例如我的是:
solutions = [
{
“managed”: False,
“name”: “src/flutter”,
“url”: “[email protected]:loosaSH/engine.git”,
“custom_deps”: {},
“deps_file”: “DEPS”,
“safesync_url”: “”,
},
]
複製代碼:wq 保存退出。
5、執行 gclient sync 命令
這裏的執行需要梯子,速度根據你的網絡狀況,同步下來的文件大小大概有 10G 多吧
$ pwd
/Users/sunhao/development/engine
$ gclient sync
複製代碼需要注意的是,這裏需要等待文件自動完成,並且儘量不要打斷該命令,顯示 100% 後仍有很多操作。
6、重新 fetch flutter/engine 倉庫
$ cd src/flutter
$ pwd
/Users/sunhao/development/engine/src/flutter
$ git remote add upstream [email protected]:flutter/engine.git
複製代碼7、安裝輔助工具
安裝 JDK 1.8 以上
ant 安裝
$ brew install ant
複製代碼8、編譯 android 相關
確保本地 flutter/engine 倉庫是最新的
$ pwd
/Users/sunhao/development/engine/src/flutter
$ git pull upstream master
$ cd /Users/sunhao/development/engine
$ gclient sync
複製代碼執行以下命令編譯
// 準備文件,生成 compile_commands.json 文件
$ ./flutter/tools/gn --unoptimized
$ ./flutter/tools/gn --android --unoptimized
// 構建
$ ninja -C out/android_debug_unopt && ninja -C out/host_debug_unopt
複製代碼整個過程比較漫長,耐心等待。
9、編譯 iOS 相關
確保本地 flutter/engine 倉庫是最新的
$ pwd
/Users/sunhao/development/engine/src/flutter
$ git pull upstream master
$ cd /Users/sunhao/development/engine
$ gclient sync
複製代碼執行以下命令編譯
// 準備文件,生成 compile_commands.json 文件
$ ./flutter/tools/gn --ios --unoptimized
$ ./flutter/tools/gn --unoptimized
// 構建
$ ninja -C out/ios_debug_unopt && ninja -C out/host_debug_unopt
複製代碼這樣 flutter engine 的編譯工作就基本完成了。生成的一些編譯文件目錄爲 src/out 。
閱讀 Engine 代碼 ——Clion
個人認爲 Clion 來閱讀 C++ 代碼比較方便,並且打開速度明顯要快於 VSCode
操作比較簡單,將上面生成的 compile_commands.json 文件複製到 src/flutter 目錄中,然後使用 Clion 打開項目,indexing 之後便可以跟蹤跳轉(這一步可能也要一點時間)
閱讀 Engine 代碼 ——VSCode
官方推薦使用 cquery 進行對 engine 的源碼依賴跟蹤,
1、cmake 安裝
安裝 cquery 的過程中需要使用到 cmake
$ brew install cmake
複製代碼2、cquery 安裝
$ brew install --HEAD cquery
複製代碼編譯 cquery 源碼

github.com/cquery-proj…

$ pwd
/Users/sunhao/development
$ git clone --recursive https://github.com/cquery-project/cquery.git
$ cd cquery
$ git submodule update --init
$ mkdir build
$ cd build
$ cmake … -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=release -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
$ cmake --build .
$ cmake --build . --target install
複製代碼3、配置 cquery 環境變量
配置環境變量:建議在 ~/.bash_profile 文件中添加
export PATH=/Users/sunhao/development/cquery/build/release/bin:$PATH
複製代碼然後執行
$ source ~/.bash_profile
複製代碼3、安裝 VSCode、以及cquery插件
4、拷貝 cquery 需要的項目配置文件
將 compile_commands.json 文件從 src/out/compile_commands.json 拷貝到 src/
5、配置 VSCode 設置(還是使用clion吧,舒服多了)

github.com/cquery-proj…

因爲我們配置了全局的環境變量,所以可以根據官方的推薦設置一些 highlighting。
在 VSCode 中打開 settings.json,在 json 中增加:
“cquery.highlighting.enabled.types”: true,
“cquery.highlighting.enabled.freeStandingFunctions”: true,
“cquery.highlighting.enabled.memberFunctions”: true,
“cquery.highlighting.enabled.freeStandingVariables”: true,
“cquery.highlighting.enabled.memberVariables”: true,
“cquery.highlighting.enabled.namespaces”: true,
“cquery.highlighting.enabled.macros”: true,
“cquery.highlighting.enabled.enums”: true,
“cquery.highlighting.enabled.typeAliases”: true,
“cquery.highlighting.enabled.enumConstants”: true,
“cquery.highlighting.enabled.staticMemberFunctions”: true,
“cquery.highlighting.enabled.parameters”: true,
“cquery.highlighting.enabled.templateParameters”: true,
“cquery.highlighting.enabled.staticMemberVariables”: true,
“cquery.highlighting.enabled.globalVariables”: true,
複製代碼這樣你就可以在 VSCode 中跟蹤 flutter/engine 代碼了。
總結
閱讀源碼只是第一步,後面我會分享關於如何使用本地的 Flutter Engine 以及如何進行調試。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章