需要安装xcode、git
环境配置
配置命令行科学上网方式:
// 设置终端git代理 为CURL设置proxy
git config --global http.proxy 'socks5://127.0.0.1:1086'
git config --global https.proxy 'socks5://127.0.0.1:1086'
// 为wget设置proxy
export http_proxy=127.0.0.1:1087
export https_proxy=127.0.0.1:1087
// 最终记得取消git代理
git config --global --unset http.proxy
git config --global --unset https.proxy
//获取depot_tools代码管理工具
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
//配置path,替换实际地址(可以添加到环境变量)
export PATH=$PATH:/Users/jackey/liulanqi/chromium/depot_tools
拉取源码
fetch chromium
或者网络不好时不下载历史:
fetch chromium --no-history
注意:强烈建议找个稳定的科学上网工具,或者直接买个国外的服务器下载好源码再弄到本地来,git拉取源码不稳定是不行的,不支持断点续传,源码二十多个G。本人刚开始尝试本地拉取,更换了好几个工具,最后还是购买了一台香港服务器搞定的。在服务器上运行(香港服务器拉取源码的速度高达11M/s,满脸都是泪呀):
git clone https://chromium.googlesource.com/chromium/src.git
然后打包下载到本地。
解压到本地后,进入chromium目录,编辑.gclient 文件:
vim .gclient
在尾部添加:
target_os = ['mac']
切记:这样子拉下来的是master分支,强烈建议切换到release分支再编译,否则编译的时候会报各种错误,切换方法:
以下命令需要在科学上网环境下运行。
// 同步所有 tag 信息
git fetch --tags
// 从 tag 创建新的构建 branch(查看所有 tag: git show-ref --tags)
git checkout -b browser 85.0.4183.104
// 切换分支后同步代码
gclient sync
此命令需要下载15G左右的文件。
大概执行一个小时左右。
编译
执行完成之后,运行命令:
注意:这里可能会报错无权限,需要执行:
会打开一个文件,在尾部添加:
保存退出,等其执行完毕,不报错即可。
然后执行编译命令:
需要编译四千多个文件,编译时间视编译机器的配置,快的话七八个小时,慢的话可能会一天一夜哦!
其他
使用Xcode来构建Chromium,我们要使用Xcode来阅读和调试Chromium代码,因此我们需要执行
gn gen out/gn --ide=xcode
在用Ninja和GN构建完成之后,执行这条命令需要的时间就比较少了。然后就可以用Xcode来打开这个工程了。执行
open out/gn/ninja/all.xcworkspace
排错记录
报错:
________ running 'vpython src/build/mac_toolchain.py --xcode-version default' in '/Users/fengyu/chromuim/chromium'
Traceback (most recent call last):
File "src/build/mac_toolchain.py", line 204, in <module>
sys.exit(main())
File "src/build/mac_toolchain.py", line 186, in main
if not _UseHermeticToolchain():
File "src/build/mac_toolchain.py", line 73, in _UseHermeticToolchain
proc = subprocess.Popen([script_path, 'mac'], stdout=subprocess.PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 394, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
Error: Command 'vpython src/build/mac_toolchain.py --xcode-version default' returned non-zero exit status 1 in /Users/fengyu/chromuim/chromium
解决方法:
debug 方法:
vim src/build/mac_toolchain.py
找到第70行
def _UseHermeticToolchain():
current_dir = os.path.dirname(os.path.realpath(__file__))
script_path = os.path.join(current_dir, 'mac/should_use_hermetic_xcode.py')
proc = subprocess.Popen([script_path, 'mac'], stdout=subprocess.PIPE)
return '1' in proc.stdout.readline()
将其修改为:
def _UseHermeticToolchain():
current_dir = os.path.dirname(os.path.realpath(__file__))
script_path = os.path.join(current_dir, 'mac/should_use_hermetic_xcode.py')
print(script_path)
sys.exit(0)
proc = subprocess.Popen([script_path, 'mac'], stdout=subprocess.PIPE)
return '1' in proc.stdout.readline()
然后运行:vpython src/build/mac_toolchain.py --xcode-version default
查看输出文件的路径,给其赋权如下:
chmod a+x /Users/fengyu/chromuim/chromium/src/build/mac/should_use_hermetic_xcode.py
报错:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Traceback (most recent call last):
File "/Users/fengyu/chromuim/chromium/src/build/config/mac/sdk_info.py", line 152, in <module>
FillXcodeVersion(settings, args.developer_dir)
File "/Users/fengyu/chromuim/chromium/src/build/config/mac/sdk_info.py", line 64, in FillXcodeVersion
lines = subprocess.check_output(['xcodebuild', '-version']).splitlines()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 223, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['xcodebuild', '-version']' returned non-zero exit status 1
解决方式:
执行:sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
报错:
FAILED: pyproto/third_party/dom_distiller_js/dom_distiller_pb2.py gen/third_party/dom_distiller_js/dom_distiller.pb.h gen/third_party/dom_distiller_js/dom_distiller.pb.cc gen/third_party/dom_distiller_js/dom_distiller_json_converter.h
python ../../tools/protoc_wrapper/protoc_wrapper.py dom_distiller.proto --protoc ./protoc --proto-in-dir ../../third_party/dom_distiller_js/dist/proto --cc-out-dir gen/third_party/dom_distiller_js --py-out-dir pyproto/third_party/dom_distiller_js --plugin ../../third_party/dom_distiller_js/protoc_plugins/json_values_converter.py --plugin-out-dir gen/third_party/dom_distiller_js --plugin-options output_dir=:
../../third_party/dom_distiller_js/protoc_plugins/json_values_converter.py: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--plugin_out: protoc-gen-plugin: Plugin failed with status code 1.
Protoc has returned non-zero status: 1
解决方式:
chomd a+x third_party/dom_distiller_js/protoc_plugins/json_values_converter.py
Ubuntu 编译
参考:https://chromium.googlesource.com/chromium/src/+/master/docs/android_build_instructions.md
编译的过程会报权限错误,需要将整个chromium文件件赋予776权限。
chromd -R 776 chromium
win10 编译
配置git ssr 代理
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
配置curl ssr代理
配置以下系统环境变量
变量:HTTP_proxy 值:http://127.0.0.1:1080
变量:HTTPS_proxy 值:http://127.0.0.1:1080
需要安装:Debugging Tools for Windows
下载地址:https://developer.microsoft.com/zh-cn/windows/downloads/windows-10-sdk/
3 条评论
你好,博主,想请问你mac电脑配置
两年前的文章了,还是公司的电脑,已经换了,不记得啥配置了哦。
好哒! 谢谢博主