chromium 浏览器编译 vs2017 win10

01 阅读官方文档

https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md

一个中文翻译文档:https://blog.csdn.net/Vincent95/article/details/78469807

02 安装python2.7.*

depot_tools需要使用python2.7。
https://www.python.org/ftp/python/2.7.15/python-2.7.15.amd64.msi

03 配置 depot_tools

下载depot_tools,加压到d:\git\chromium\depot_tools,并把d:\git\chromium\depot_tools加入环境变量。
https://storage.googleapis.com/chrome-infra/depot_tools.zip
把depot_tools的路径加到 PATH 环境变量的最前面,至少要加到python环境变量的前面

04 配置必要的信息

设置git全局配置信息

# user.name 和 user.email 需要使用自己的。
git config --global user.name "5455945"
git config --global user.email "[email protected]"
git config --global core.autocrlf false
git config --global core.filemode false
git config --global branch.autosetuprebase always

# 这个可以在系统环境变量里面设置,也可以在命令行窗口设置
set GYP_MSVS_VERSION=2017
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GYP_MSVS_OVERRIDE_PATH="D:\install\Microsoft Visual Studio\2017\Community"

5 下载代码
参考:https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md#Using-the-Visual-Studio-IDE

fetch chromium

# 不下载历史版本信息,速度较快,后续切换分支时略慢
fetch chromium --no-history

# 如果下载失败
gclient sync --nohooks --with_branch_heads --with_tags --output-json="log.json"
gclient runhooks # 或者 gclient runhooks --force

# 上面成功后,
cd src
git fetch --all
git fetch --tags

git pull
# 到此为止,是master的最新代码

06 切换到相对稳定分支

参考:
https://omahaproxy.appspot.com/
http://www.chromium.org/developers/how-tos/get-the-code/working-with-release-branches

cd src # 在src目录
# 创建新的分支b3440
git checkout -b b3440 branch-heads/3440
# 也可以考虑直接使用tag。比如:git checkout -b b3440 68.0.3440.54
cd .. # zai src的上一级目录(chromium目录)
gclient sync --with_branch_heads --with_tags

7 build时的设置参数

target_cpu=”x86”:指明生成的针对X86架构的CPU。
is_debug=false:指明生成的是Release版本可执行程序。
is_official_build=true:指明使用Chrome官方的编译优化建议。
proprietary_codecs:指明支持H264编码,编译时,自动H264相关组件,打包PE文件中。
enable_nacl=false:指明关闭支持NACL,这是一种Chrome插件,因为安全性,稳定性存在问题,已经很少使用了。
remove_webcore_debug_symbols=true:指明删除内核层支持调试的符号文件,这样,有助于减少文件体积,提高运行速度。

查看gn args 所有可用参数

# 很重要的参考资料
gn args --list out\Debug
gn gen out/Debug --ide=vs2017 --filters=//chrome --args="target_os=\"win\" target_cpu=\"x86\" is_component_build=true is_debug=true is_official_build=false google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding=\"Chrome\" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"
ninja -C out\Debug chrome setup mini_installer
# 35025文件

gn gen out/Release --ide=vs2017 --filters=//chrome --args="target_os=\"win\" target_cpu=\"x86\" is_component_build=false is_debug=false is_official_build=true google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding=\"Chrome\" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"
ninja -C out\Release chrome
ninja -C out\Release mini_installer

gn gen out/DebugX64 --ide=vs2017 --filters=//chrome --args="target_os=\"win\" target_cpu=\"x64\" is_component_build=true is_debug=true is_official_build=false google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding=\"Chrome\" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"
ninja -C out\DebugX64 chrome
# 35025文件

# is_component_build=false 和 is_official_build=true 不能同时为true
gn gen out/ReleaseX64 --ide=vs2017 --filters=//chrome --args="target_os=\"win\" target_cpu=\"x64\" is_component_build=false is_debug=false is_official_build=true google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding=\"Chrome\" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"
ninja -C out\ReleaseX64 chrome
# 生成安装包
ninja -C out\ReleaseX64 mini_installer
ninja -C out\ReleaseX64 setup
# 34416文件

chromium能够支持的html5选项,可以参考: http://html5test.com/

在gclient sync的时候遇到了错误,根据提示手动修改了 *.py文件。
后来编译的时候又出现错误。卸载了windows wdk,编译正常通过

Chrome浏览器内置功能指令
https://wiki.deepin.io/mediawiki/index.php?title=Chrome%E6%B5%8F%E8%A7%88%E5%99%A8%E5%86%85%E7%BD%AE%E5%8A%9F%E8%83%BD%E6%8C%87%E4%BB%A4

08 设置远程分支与本地分支对应关系

建立对应远程分支的本地分支,比如:建立对应68的正式发布版本的本地分支,68.0.3440.54,分支为b3440。

git checkout -b b3440 remotes/branch-heads/3440

建立本地分支与远程分支的对应关系,远程分支变化,切换到本地分支时,能够直接观察的到,或者使用 git fetch –all时,能够拉到对应分支的变更内容

# git branch --set-upstream-to=远程分支名词  本地分支名称
git branch --set-upstream-to=remotes/branch-heads/3440 b3440

09 查看分支对应关系

git branch -vv

10 取消远程分支对应关系

# git branch --set-unupstream-to=远程分支名词
git branch --set-unupstream-to=remotes/branch-heads/3440

11 编译生成安装包

ninja -C out/Release chrome setup mini_installer
out\Release\setup.exe --chrome --multi-install

12 几个有用的命令

# 查找当前目录下所有.gn文件 是否包含 executable("chrome")
findstr /S "executable(\"chrome\")" *.gn

git clean -df
git reset --hard

git reset --hard 
git clean -xdf

猜你喜欢

转载自blog.csdn.net/longji/article/details/80967225