Windows下获取Chromium源码

来源:互联网 发布:matlab矩阵乘法运算 编辑:程序博客网 时间:2024/06/05 04:42

先配置好ShadowSocks和depot_tools

配置GIT

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
#用户名
git config --global user.name "Your Name"
#邮箱
git config --global user.email "your-name@your-mail.domain"
#自动CRLF
git config --global core.autocrlf false
#文件模式
git config --global core.filemode false
#自动大写
git config --global branch.autosetuprebase always
#设置代理
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080

设置环境变量,这里包括了VS,NINJA,BOTO和depot_tools的环境变量

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
#设置只使用本地Visual Studio
DEPOT_TOOLS_WIN_TOOLCHAIN = 0
#设置编译选项
GYP_DEFINES = branding=Chromium buildtype=Official target_arch=x64 disable_nacl=1 windows_sdk_path="C:\Program Files (x86)\Windows Kits\8.1"
# 这是编译Release版本的,如果需要Debug版本则
# GYP_DEFINES = component=shared_library target_arch=x64 disable_nacl=1 windows_sdk_path="C:\Program Files (x86)\Windows Kits\8.1"
# 如果需要编译Chrome 则需要登录Google员工账号并设置为
# GYP_DEFINES = branding=Chrome buildtype=Official target_arch=x64 disable_nacl=1 windows_sdk_path="C:\Program Files (x86)\Windows Kits\8.1"
#设置ninja编译器
GYP_GENERATORS = msvs-ninja,ninja
#设置VS版本
GYP_MSVS_VERSION = 2015
#设置代理
NO_AUTH_BOTO_CONFIG = D:\WebKit\boto.cfg
#路径环境变量,必须将depot_tools设置在所有已安装的python和git安装目录之前。
#这样的话调用git和python会优先采用depot_tools里的git.bat和python.bat
#如果需要调用已安装的版本,使用git.exe和python.exe即可
Path = %Path%;D:\WebKit\depot_tools;D:\Python36\;D:\Python36\Scripts\

然后打开CMD窗口并执行

0001
0002
0003
0004
0005
0006
0007
0008
D:
cdWebKit
mkdirChromium
cdChromium
sethttps_proxy=https://127.0.0.1:1080
sethttp_proxy=http://127.0.0.1:1080
setsocks5_proxy=socks5://127.0.0.1:1080
setNO_AUTH_BOTO_CONFIG=D:\WebKit\boto.cfg

D:\WebKit\boto.cfg内容为

0001
0002
0003
[Boto]
proxy = 127.0.0.1
proxy_port = 1080

D:\WebKit\Chromium执行

0001
gclient root

然后,本该在D:\WebKit\Chromium执行

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
gclient config --spec 'solutions = [
  {
    "url":"https://chromium.googlesource.com/chromium/src.git",
    "managed": False,
    "name":"src",
    "deps_file":".DEPS.git",
    "custom_deps": {},
  },
]
target_os = ["win"]
target_os_only = True
'

但这样会出现问题
因为该命令本该由fetch命令自动执行但此处使用了--dry-run指令显示出来并手动一步步执行
所以在D:\WebKit\Chromium手动创建文件D:\WebKit\Chromium\.gclient
内容为

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
solutions = [
  {
    "url":"https://chromium.googlesource.com/chromium/src.git",
    "managed": False,
    "name":"src",
    "deps_file":".DEPS.git",
    "custom_deps": {},
  },
]
target_os = ["win"]
target_os_only = True

开始下载代码,sync可能需要数个小时
可以使用--jobs设置线程数
比如gclient sync --nohooks --no-history --jobs 16
如果下载出错或中断,则继续使用sync即可,可以执行多次来保证下载成功

0001
0002
0003
0004
0005
gclientsync--nohooks --no-history
cdD:\WebKit\Chromium\src
git submodule foreach 'git config -f $toplevel/.git/config submodule.$name.ignore all'
git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
git config diff.ignoreSubmodules all

在经历6小时(200KB/s)左右的主分支下载
接下来就需要获取tags了
加了--no-history--nohooks后源码的下载大概耗时2-16小时
本人的服务器只有2M所以下载了6小时
接下来需要获取tags来切换到稳定版分支
tags的获取也需要2-16小时
当然,也可以下载指定的tags,但这里不做说明了
之前下载主分支sync的时候如果遇到错误和中断可以断点续传
但tags就必须保证一次性下载完毕了,否则就要重新下载了。

0001
0002
git fetch --tags
git checkout -b 新建的本地分支名称 你需要的版本号

删除D:\WebKit\Chromium\src目录下除.git目录以外的所有文件夹文件
这样删除是为了防止出现Reference is not a tree
为了防止出错,建议将这些文件从原处剪切到D:\WebKit\Chromium\backup文件夹
然后执行下面的命令,也需要数个小时

0001
0002
git reset --hard 你刚刚新建的本地分支名字
gclientsync--with_branch_heads --jobs 16

执行完毕后,代码就获取完了
至于runhooks,因为第一次执行的代码要删除所以才加了--nohooks
但这里没有加,所以应该是自己执行了的
如果没有执行,那就再执行一次gclient runhooks
然后编译


原创粉丝点击