suntongmiandeMacBook-Pro:~ suntongmian$ cd /Users/suntongmian/Documents/develop/webrtc suntongmiandeMacBook-Pro:webrtc suntongmian$ suntongmiandeMacBook-Pro:webrtc suntongmian$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 正克隆到 'depot_tools'... fatal: unable to access 'https://chromium.googlesource.com/chromium/tools/depot_tools.git/': Failed to connect to chromium.googlesource.com port 443: Operation timed out suntongmiandeMacBook-Pro:webrtc suntongmian$
出现 “Failed to connect to chromium.googlesource.com port 443: Operation timed out” 问题后,需要检查 VPN 服务是否开启,网络状况是否良好。如果在 VPN 服务开启和网络状况良好的情况下,仍然不能 clone 代码成功,那就需要检查终端能否成功访问墙外的资源。
我开启了 VPN 服务,网络状况也很好,也能通过 Google 浏览器访问资源,但就是不能 clone depot_tools 源码成功。这个时候,我通过命令 curl 来检查终端是否具备翻墙功能。
suntongmiandeMacBook-Pro:webrtc suntongmian$ curl www.google.com curl: (7) Failed to connect to www.google.com port 80: Operation timed out suntongmiandeMacBook-Pro:webrtc suntongmian$
suntongmiandeMacBook-Pro:webrtc suntongmian$ curl www.google.com <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/logos/doodles/2019/us-teacher-appreciation-week-2019-begins-4994791740801024-l.png" itemprop="image"><meta content="Happy US Teacher Appreciation Week 2019!" property="twitter:title"><meta content="Happy US Teacher Appreciation Week 2019! #GoogleDoodle" \u003E\x22,\x22psrl\x22:\x22Remove\x22,\x22sbit\x22:\x22Search by image\x22,\x22srch\x22:\x22Google Search\x22},\x22ovr\x22:{},\x22pq\x22:\x22\x22,\x22refpd\x22:true,\x22rfs\x22:[],\x22sbpl\x22:24,\x22sbpr\x22:24,\x22scd\x22:10,\x22sce\x22:5,\x22stok\x22:\x22s4ND7ehgr2lcHpcv5T93UySs4ho\x22,\x22uhde\x22:false}}';google.pmc=JSON.parse(pmc);})();</script> </body></html>suntongmiandeMacBook-Pro:webrtc suntongmian$ suntongmiandeMacBook-Pro:webrtc suntongmian$
This script can be used to download the Chromium sources.See http://www.chromium.org/developers/how-tos/get-the-code forfull usage instructions.
Valid options: -h, --help,help Print this message. --nohooksDon't run hooks after checkout. --force (dangerous)Don't look for existing .gclient file. -n, --dry-runDon't run commands,only print them. --no-historyPerform shallow clones,don't fetch the full git history.
________ running '/usr/bin/python src/build/mac_toolchain.py' in '/Users/suntongmian/Documents/develop/webrtc' Skipping Mac toolchain installation formac
________ running '/usr/bin/python src/tools/clang/scripts/update.py' in '/Users/suntongmian/Documents/develop/webrtc' Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac/clang-359912-2.tgz <urlopen error [Errno 54] Connection reset by peer> Retrying in 5 s ... Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac/clang-359912-2.tgz Traceback (most recent call last): File"src/tools/clang/scripts/update.py", line 322, in <module> sys.exit(main()) File"src/tools/clang/scripts/update.py", line 318, in main return UpdateClang() File"src/tools/clang/scripts/update.py", line 252, in UpdateClang DownloadAndUnpackClangPackage(sys.platform, LLVM_BUILD_DIR) File"src/tools/clang/scripts/update.py", line 171, in DownloadAndUnpackClangPackage DownloadAndUnpack(cds_full_url, output_dir, path_prefix) File"src/tools/clang/scripts/update.py", line 141, in DownloadAndUnpack DownloadUrl(url, f) File"src/tools/clang/scripts/update.py", line 100, in DownloadUrl response = urllib.urlopen(url) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, inopen response = self._open(req, data) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open '_open', req) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(*args) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open context=self._context) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1194, in do_open h.request(req.get_method(), req.get_selector(), req.data, headers) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1053, in request self._send_request(method, url, body, headers) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1093, in _send_request self.endheaders(body) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1049, in endheaders self._send_output(message_body) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 893, in _send_output self.send(msg) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 855, in send self.connect() File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1266, in connect HTTPConnection.connect(self) File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 835, in connect self._tunnel() File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 812, in _tunnel (version, code, message) = response._read_status() File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 417, in _read_status raise BadStatusLine(line) httplib.BadStatusLine: '' Error: Command '/usr/bin/python src/tools/clang/scripts/update.py' returned non-zero exit status 1 in /Users/suntongmian/Documents/develop/webrtc suntongmiandeMacBook-Pro:src suntongmian$
在执行编译前,我们需要配置好编译的参数和环境,生产出构建文件。这里就需要用到 GN 这个工具了。GN 是一个为 Ninja 生成构建文件的元构建系统。Ninja 是一个小型构建系统,特点是构建速度快。
step 1
使用 GN 来生产 Ninja 工程文件,在终端执行命令
1
gn gen out/ios --args='target_os="ios" target_cpu="arm64" is_debug=true'
1 2 3 4 5 6 7 8 9 10 11
suntongmiandeMacBook-Pro:src suntongmian$ gn gen out/ios --args='target_os="ios" target_cpu="arm64" is_debug=true' Warning: Multiple codesigning identities match "iPhone Developer" Warning: - D78B0B7AF39CEFA4D0F673B4D3AA517D312C97CC (selected) Warning: - 5634EAED50D1AD95ED76F6AC8298E06590FE476B Warning: - 2843CD233EB6A93C79C2332E4F4FC601BEDA13BC Warning: Please use either ios_code_signing_identity or Warning: ios_code_signing_identity_description variable to Warning: control which identity is selected.
Done. Made 1378 targets from 189 files in 2200ms suntongmiandeMacBook-Pro:src suntongmian$
/bin/sh: ../../third_party/llvm-build/Release+Asserts/bin/clang++: No such fileordirectory
...
isystem../../buildtools/third_party/libc++abi/trunk/include -fvisibility-inlines-hidden -Wnon-virtual-dtor -Woverloaded-virtual -c ../../api/audio_codecs/ilbc/audio_encoder_ilbc.cc -o obj/api/audio_codecs/ilbc/audio_encoder_ilbc/audio_encoder_ilbc.o /bin/sh: ../../third_party/llvm-build/Release+Asserts/bin/clang++: No such fileordirectory ninja: build stopped: subcommand failed. suntongmiandeMacBook-Pro:src suntongmian$
出现错误 “/bin/sh: ../../third_party/llvm-build/Release+Asserts/bin/clang++: No such file or directory”。原因是 /src/third_party/llvm-build 目录下找不到可执行文件 clang++。
先查看 /src/third_party/llvm-build 目录下的文件,在终端执行命令
1
ls third_party/llvm-build
1 2 3
suntongmiandeMacBook-Pro:src suntongmian$ ls third_party/llvm-build cr_build_revision suntongmiandeMacBook-Pro:src suntongmian$
suntongmiandeMacBook-Pro:src suntongmian$ curl https://commondatastorage.googleapis.com/chromium-browser-clang/Mac/clang-359912-2.tgz -o third_party/llvm-build/clang.tgz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 10027.9M 10027.9M 001167k 00:00:240:00:24 --:--:-- 1469k suntongmiandeMacBook-Pro:src suntongmian$
ls third_party/llvm-build mkdir third_party/llvm-build/Release+Asserts tar zxvf third_party/llvm-build/clang.tgz -C third_party/llvm-build/Release+Asserts
suntongmiandeMacBook-Pro:src suntongmian$ ls third_party/llvm-build clang.tgz cr_build_revision suntongmiandeMacBook-Pro:src suntongmian$ suntongmiandeMacBook-Pro:src suntongmian$ mkdir third_party/llvm-build/Release+Asserts suntongmiandeMacBook-Pro:src suntongmian$ suntongmiandeMacBook-Pro:src suntongmian$ tar zxvf third_party/llvm-build/clang.tgz -C third_party/llvm-build/Release+Asserts x bin/ x bin/clang x bin/clang++ x bin/clang-cl ... x include/c++/v1/ios x include/c++/v1/iosfwd x include/c++/v1/iostream
...
x include/c++/v1/support/android/ x include/c++/v1/support/android/locale_bionic.h ... x include/c++/v1/version x include/c++/v1/wchar.h x include/c++/v1/wctype.h suntongmiandeMacBook-Pro:src suntongmian$ suntongmiandeMacBook-Pro:src suntongmian$ ls third_party/llvm-build/Release+Asserts/ bin buildlog.txt include lib suntongmiandeMacBook-Pro:src suntongmian$ suntongmiandeMacBook-Pro:src suntongmian$ ls third_party/llvm-build/Release+Asserts/bin clang clang-cl llvm-symbolizer clang++ llvm-pdbutil llvm-undname suntongmiandeMacBook-Pro:src suntongmian$
suntongmiandeMacBook-Pro:src suntongmian$ cat tools/clang/scripts/update.py #!/usr/bin/env python # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file.
"""This script is used to download prebuilt clang binaries. It runs as a "gclient hook" in Chromium checkouts. It can also be run stand-alone as a convenient way of installing a well-tested near-tip-of-tree clang version: $ curl -s https://raw.githubusercontent.com/chromium/chromium/master/tools/clang/scripts/update.py | python - --clang-dir=. """
# TODO: Running stand-alone won't work on Windows due to the dia dll copying.
from __future__ import print_function
...
try: import urllib2 as urllib except ImportError: # For Py3 compatibility import urllib.request as urllib import urllib.error as urllib
import zipfile
# Do NOT CHANGE this if you don't know what you're doing -- see # https://chromium.googlesource.com/chromium/src/+/master/docs/updating_clang.md # Reverting problematic clang rolls is safe, though. CLANG_REVISION = '359912' CLANG_SUB_REVISION = 2
except urllib.URLError as e: sys.stdout.write('\n') print(e) if num_retries == 0or isinstance(e, urllib.HTTPError) and e.code == 404: raise e num_retries -= 1 print('Retrying in %d s ...' % retry_wait_s)
...
defDownloadAndUnpack(url, output_dir, path_prefix=None): """Download an archive from url and extract into output_dir. If path_prefix def DownloadAndUnpackClangPackage(platform, output_dir, runtimes_only=False): cds_file = "clang-%s.tgz" % PACKAGE_VERSION ... def UpdateClang(): GCLIENT_CONFIG = os.path.join(os.path.dirname(CHROMIUM_DIR), '.gclient') ... DownloadAndUnpackClangPackage(sys.platform, LLVM_BUILD_DIR) ... if args.llvm_force_head_revision: print('--llvm-force-head-revision can only be used for --print-revision') return 1 if args.clang_dir: global LLVM_BUILD_DIR, STAMP_FILE LLVM_BUILD_DIR = os.path.abspath(args.clang_dir) STAMP_FILE = os.path.join(LLVM_BUILD_DIR, 'cr_build_revision') return UpdateClang() if __name__ == '__main__': sys.exit(main()) suntongmiandeMacBook-Pro:src suntongmian$
从该脚本的注释信息 This script is used to download prebuilt clang binaries 可以得知该脚本作用就是下载 clang 可执行文件。其中 clang 的版本信息为 CLANG_REVISION = '359912' CLANG_SUB_REVISION = 2 RELEASE_VERSION = '9.0.0',llvm-build 的目录信息为 LLVM_BUILD_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm-build', 'Release+Asserts')。