一、环境准备
1.1 win10主机+虚拟机(Ubuntu20.04,建议硬盘可用空间40G以上)
$ cat /etc/issue Ubuntu 20.04.5 LTS
1.2 网络配置(虚拟机借助主机的VPN来访问外网)
- 主机开启VPN网络
- 虚拟机网络配置为NAT模式
- 在主机上执行ipconfig查看vnet8的IP,查看vpn软件使用的端口
- 在ubuntu系统中配置网络代理,代理的IP和端口为步骤3中的IP和端口
- 主机开启vpn后,在虚拟机中浏览器中输入www.google.com可以打开即表示可以访问外网
- git 配置代理的IP和端口(步骤4中的IP和端口)
rtc@ubuntu:~$ cat ~/.gitconfig [http] proxy = IP:PORT [https] proxy = IP:PORT
或者通过命令行配置
git config --global https.proxy https://IP:PORT git config --global http.proxy http://IP:PORT
二、下载流程
2.1 安装depot_tools工具,WebRTC使用depot工具管理和下载源码
- 下载工具
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
- 添加depot_tools到系统的环境变量PATH
方法1: 在终端直接设置环境变量
export PATH=$PATH:/path/to/depot_tools
方法2:添加到~/.bashrc文件结尾,重新打开终端即可
export PATH=$PATH:/path/to/depot_tools
- 增加权限
chmod 777 depot_tools -R
- 验证测试
终端输入fetch命令,如果提示找不到,则说明depot工具没有配置成功
$ fetch usage: fetch.py [-h] [-n] [--nohooks] [--nohistory] [--force] [-p PROTOCOL_OVERRIDE] config ... fetch.py: error: the following arguments are required: config, props
2.2 新建存储WebRTC源码的目录
mkdir webrtc-checkout cd webrtc-checkout
2.3 使用fetch命令下载源码
fetch --nohooks webrtc
2.4 执行第3步后,如果报网络等异常断开情况时,需要用gclient sync继续下载
gclient sync
2.5 建立编译依赖
cd src ./build/install-build-deps.sh
2.6 使用gn生成编译配置
gn gen out/Default
2.7 使用ninja编译代码
ninja -C out/Default
编译完成会在out/Default目录下生成很多文件(包括各种库等)
三 问题及解决方法:
3.1 下载过程中出现以下问题
0:00:00] Started. ---------------------------------------- Traceback (most recent call last): File "/home/rtc/Project/office/depot_tools/metrics.py", line 302, in print_notice_and_exit yield File "/home/rtc/Project/office/depot_tools/gclient.py", line 4638, in
sys.exit(main(sys.argv[1:])) ^^^^^^^^^^^^^^^^^^ File "/home/rtc/Project/office/depot_tools/gclient.py", line 4624, in main return dispatcher.execute(OptionParser(), argv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/rtc/Project/office/depot_tools/subcommand.py", line 254, in execute return command(parser, args[1:]) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/rtc/Project/office/depot_tools/gclient.py", line 3977, in CMDsync ret = client.RunOnDeps('update', args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/rtc/Project/office/depot_tools/gclient.py", line 2436, in RunOnDeps work_queue.flush(revision_overrides, File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 1026, in flush reraise(e[0], e[1], e[2]) File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 53, in reraise raise value File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 1105, in run self.item.run(*self.args, **self.kwargs) File "/home/rtc/Project/office/depot_tools/gclient.py", line 1251, in run self._got_revision = self._used_scm.RunCommand( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 137, in RunCommand return getattr(self, command)(options, args, file_list) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 664, in wrapper return_val = f(*args) ^^^^^^^^ File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 866, in update strp_current_url = current_url[:-4] if current_url.endswith( ^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'endswith' - 问题原因:git版本过低
- 解决方法:升级git版本
升级前:
git --version git version 2.25.1
升级后:
$ git --version git version 2.46.1
升级流程:
- 方法一: 直接安装更新
sudo apt-get install git
- 方法二: 如果没更新,需要添加源
sudo add-apt-repository ppa:git-core/ppa sudo apt update sudo apt-get install git
四 其它说明
- 国外源码下载需要VPN支持,稳定、速度快的VPN能更快的下载代码
- 源码大小24G左右,下载前需要确认硬盘可用空间大小和VPN流量限制问题
rtc@ubuntu:~/Project/office/webrtc-checkout$ du -sh src 24G src
- 出现下载异常中断时,查明原因并解决后,可以通过gclient sync继续下载
- 声网提供的国内镜像下载源,在没有VPN时,可以尝试下面链接中的方法
https://webrtc.org.cn/mirror/
- 方法二: 如果没更新,需要添加源
- 方法一: 直接安装更新
- 验证测试
- 增加权限
- 添加depot_tools到系统的环境变量PATH