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

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