[转帖]Chromium的源码获取与编译(2018-06-06)

Chromium的源码获取与编译(2018-06-06)

https://www.jianshu.com/p/08aa03e8ce18

0.操作环境

操作系统:win8.1 64位
chromium版本:65.0.3325.181
shas:代理地址127.0.0.1:1080,确保已翻
visual studio版本:vs2017 社区版
内存要求:该版本至少需要8G内存,更高版本要高于8G内存不然会崩

1.chromium版本选择

最新的vs配最新的chrome版本对应的chromium!

2.流程

2.1下载depot_tools

下载地址:https://chromium.googlesource.com/chromium/tools/depot_tools/
注意:类似的,depot_tools的下载到本地的地址也要全英文,不能包含中文!
下好后,请在环境变量Path中添加depot_tools目录地址。

2.2配置depot_tools代理

由于众所周知的原因,本文需要在shas全局代理下配置depot_tools。一共有以下几个步骤。

  • 第一个步骤:
    为了解决depot_tools自身更新的问题,为depot_tools增加代理支持,修改depot_tools目录下,bootstrap\win\get_file.js文件:
    (1)改xml_http = newActiveXObject("MSXML2.ServerXMLHTTP");
    为xml_http = newActiveXObject("MSXML2.ServerXMLHTTP.5.0");
    (2)xml_http.open("GET",url,false);前增加
    xml_http.setProxy(2,"127.0.0.1:1080"); 这里的要填shas的代理地址
  • 第二个步骤:
    设置下载工具代理环境变量
    在cmd中,输入:
    set http_proxy=http://127.0.0.1:1080
    set https_proxy=https//127.0.0.1:1080

2.3设置环境变量

set DEPOT_TOOLS_WIN_TOOLCHAIN = 0
set GYP_MSVS_VERSION = 2017
set GYP_MSVS_OVERRIDE_PATH = D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise
set GYP_DEFINES=component=shared_library
set GYP_GENERATORS=msvs

2.4下载源码

  • 第一种方法:
    下载地址:https://chromium.googlesource.com/chromium/src/+archive/版本号.tar.gz
    其中,版本号即对应的chromium版本号。
    网上很多blog的chromium的源码地址都过时了,从39.0.2313.2版本过后,chromium的源码就迁移到git了,除了上面的下载源码的方法,也可以通过git clone下载。
    注意:源码的下载到本地的地址要全英文,不能包含中文!

  • 第二种方法:
    在源码目录下 运行fetch chromium
    中间断了的话,可以通过gclient sync来同步代码。

坑:谷歌云存储google-storage: gs://xxxxxx文件 下载的坑
造成原因:在下载第三方库和build工具时,有部分文件是在谷歌云存储服务器下载的,链接地址是gs://开头的,在depot工具里有访问gs的模块,但根本下载不了。
解决方法:只能将depot_tools的代码修改为https下载。该版本只有两处需要修改:1.depot_tools\download_from_google_storage.py 2.chromium\src\build\get_syzygy_binaries.py
修改内容如下:
1.定义函数download_url:

1. 按照cef说明,执行到update.bat,报错,gs://xxxxx无法访问 2. 修改\depot_tools\download_from_google_storage.py,将其中 A) base_url = 'gs://%s' % options.bucket 改为 base_url = 'https://storage.googleapis.com/%s' % options.bucket B) 搜索 # Check if file exists.段,注释原来的代码(多行),去掉gs判断检查 C) 搜索 # Fetch the file.段,改为http下载,同时增加download_url函数 如下: import urllib def download_url(src, target): """ the contents of src, which may be a URL or local file, to the target directory. """ if src[:4] == 'http': # Attempt to download a URL. opener = urllib.FancyURLopener({}) response = opener.open(src) CHUNK = 16 * 1024 with open(target, 'wb') as f: while True: chunk = response.read(CHUNK) if not chunk: break f.write(chunk) else: raise Exception('Path type is unsupported or does not exist: ' + src) 

2.修改:depot_tools\download_from_google_storage.py

# Fetch the file.
    out_q.put('%d> Downloading %s...' % (thread_num, output_filename)) try: if delete: os.remove(output_filename) # Delete the file if it exists already. except OSError: if os.path.exists(output_filename): out_q.put('%d> Warning: deleting %s failed.' % ( thread_num, output_filename)) download_url(file_url,output_filename) #code, _, err = gsutil.check_call('cp', file_url, output_filename) code =0 if code != 0: out_q.put('%d> %s' % (thread_num, err)) ret_codes.put((code, err)) continue 

3.修改chromium\src\build\get_syzygy_binaries.py

def _Download(resource): """Downloads the given GS resource to a temporary file, returning its path.""" tmp = tempfile.mkstemp(suffix='syzygy_archive') os.close(tmp[0]) tmp_file = tmp[1] url = 'gs://syzygy-archive' + resource if sys.platform == 'cygwin': # Change temporary path to Windows path for gsutil def winpath(path): return subprocess.check_output(['cygpath', '-w', path]).strip() tmp_file = winpath(tmp_file) #_GsUtil('cp', url, tmp_file) url=url.replace("gs://","https://storage.googleapis.com/") download_url(url,tmp_file) return tmp[1] 

2.5生成vs解决方案

cd到下好的源码目录下,gn gen out/Default,生成all.sln解决方案

2.6使用ninja编译

使用ninja -C out/Defalult chrome
编译完后,src\out\Default下就有chrome.exe了,那么编译成功。

猜你喜欢

转载自www.cnblogs.com/jinanxiaolaohu/p/12453550.html