V8源碼分析之Ubuntu16下獲取源碼(第一篇)

0x00 前言

編譯過程主要參考V8官網提供的指引手冊進行,有坑的話我會盡量說明。官方指引手冊【傳送門

2019/12/02 更新
原標題爲《Ubuntu16下V8源碼編譯之XX》,V8引擎內容比較多,本來不想寫源碼分爲這麼大的標題。奈何想寫的東西比預期多一點,所以開了個大坑,希望能一點點填上。

本文獲取源碼的前提是科學上網,請自行解決。

0x01 使用Git

V8的Git倉庫爲 https://chromium.googlesource.com/v8/v8.git,同時在GitHub上還有個官方鏡像: https://github.com/v8/v8.

不管是爲了遵循主流思想在github上建倉,還是爲了向牆裏勞動人民推廣壓榨相對剩餘價值的生產工具。從github上clone代碼還是比較方便的。

但是官方提示,請不要直接git clone上面的兩個地址。如果想構建V8,請使用depot_tools工具拉取代碼,會比較穩妥。

0x02 拉取代碼

  1. 在Linux或者MacOS上,需要先安裝Git和depot_tools。
    Windows,需要安裝Visual Studio, Debugging tools for Windows和depot_tools(包括Git)

    本文只以linux爲例

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
  1. 添加depot_tools工具路徑到環境變量PATH中
$ export PATH=$PATH:/path/to/depot_tools
  1. 如果你從未用過git,可以使用下面命令配置全局變量。
$ git config --global user.name "John Doe"
$ git config --global user.email "[email protected]"
$ git config --global core.autocrlf false
$ git config --global core.filemode false
$ # and for fun!
$ git config --global color.ui true
  1. 進入工作路徑workspace, 使用depot_tools拉取V8源碼
cd ~/workspace
fetch v8

過程如下

~/workspace$ fetch v8                                           
Running: gclient root                                                           
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be cre
ated.                                                                           
Running: gclient config --spec 'solutions = [                                   
  {                                                                             
    "url": "https://chromium.googlesource.com/v8/v8.git",                       
    "managed": False,                                                           
    "name": "v8",                                                               
    "deps_file": "DEPS",                                                        
    "custom_deps": {},                                                          
  },                                                                            
]                                                                               
'                                                                               
Running: gclient sync --with_branch_heads                                       
1>________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --pro
gress https://chromium.googlesource.com/v8/v8.git /home/test/workspace/_
gclient_v8_O1ff0_' in '/home/test/workspace'                            
1>Cloning into '/home/test/workspace/_gclient_v8_O1ff0_'...             
1>remote: Sending approximately 914.91 MiB ...                                  
1>remote: Counting objects: 7660, done                                          
1>remote: Total 722377 (delta 573877), reused 722377 (delta 573877)             
1>Receiving objects: 100% (722377/722377), 914.54 MiB | 5.66 MiB/s, done.       
1>Resolving deltas: 100% (573877/573877), done.                                 
1>Checking connectivity... done.                                                
1>Syncing projects:   0% ( 0/ 2)                                                
[0:04:14] Still working on:                                                     
[0:04:14]   v8                                                                  
Syncing projects: 100% (27/27), done.  

...

Downloading 1 files took 5.139851 second(s)                                     
Downloading /home/test/workspace/v8/third_party/binutils/Linux_x64/binut
ils.tar.bz2                                                                     
Extracting /home/test/workspace/v8/third_party/binutils/Linux_x64/binuti
ls.tar.bz2                                                                      
Running hooks:  76% (19/25) clang                                               
________ running 'vpython v8/tools/clang/scripts/update.py' in '/home/test/workspace'                                                                   
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Linu
x_x64/clang-n331734-e84b7a5f-1.tgz .......... Done.                             
Hook 'vpython v8/tools/clang/scripts/update.py' took 10.88 secs                 
Running hooks: 100% (25/25), done.                                              
Running: git submodule foreach 'git config -f $toplevel/.git/config submodule.$n
ame.ignore all'                                                                 
Running: git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'        
Running: git config diff.ignoreSubmodules all 

看下代碼磁盤空間

$ du v8 -hs
3.3G v8
$ du deport_tools -hs
690M deport_tools

0x03 使用分支和更新

創建一條新的本地分支(推薦)

git new-branch fix-bug-1234

更新代碼

在當前分支更新可以使用git pull命令,如果不在分支上,git pull會失效,此時需要使用git fetch命令。

git pull

有時需要更新V8的依賴環境,需要使用glient命令

gclient sync

0x04 參考文獻

https://v8.dev/docs/source-code

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