chromium下载与编译

来源:互联网 发布:手机淘宝有秒杀专区吗 编辑:程序博客网 时间:2024/05/19 23:00

chromium下载与编译

准备工作

chromium源码的下载需要准备梯子,如果你还不知道怎么做,可以参考这里shadowsocks和proxifier的安装配置,你可能也想要参考这里depot_tools更新失败。

For windows

直接上官方文档:

Setting up Windows

You must set your Windows system locale to English, or else you may get build errors about “The file contains a character that cannot be represented in the current code page.”

Setting up the environment for Visual Studio

You must build with Visual Studio 2015 Update 2; no other version is supported.

You must have Windows 7 x64 or later. x86 OSs are unsupported.

Getting the compiler toolchain

As of March 11, 2016 Chromium requires Visual Studio 2015 to build.

Install Visual Studio 2015 Update 2 or later - Community Edition should work if its license is appropriate for you. Use the Custom Install option and select:

Visual C++, which will select three sub-categories including MFC
Universal Windows Apps Development Tools > Tools
Universal Windows Apps Development Tools > Windows 10 SDK (10.0.10586)
You must have the 10586 SDK installed or else you will hit compile errors such as redefined macros.

Install Windows Driver Kit (WDK) 10, or use some other method to get the Debugging Tools for Windows.

Run set DEPOT_TOOLS_WIN_TOOLCHAIN=0, or set that variable in your global environment.

Compilation is done through ninja, not Visual Studio.

For macos

也是上官方文档:

Prerequisites

A Mac running 10.9+.
Xcode 7.3+.
depot_tools.
The OSX 10.10 SDK. Run
ls xcode-select -p/Platforms/MacOSX.platform/Developer/SDKs
to check whether you have it. Building with the 10.11 SDK works too, but the releases currently use the 10.10 SDK.
Getting the code

Check out the source code using Git.

Before checking out, go to the waterfall and check that the source tree is open (to avoid pulling a broken tree).

The path to the build directory should not contain spaces (e.g. not ~/Mac OS X/chromium), as this will cause the build to fail. This includes your drive name, the default “Macintosh HD2” for a second drive has a space.

下载代码

这里是官方文档的说明:

GETTING THE CODE

Pick an empty directory and run one of the following:

$ fetch chromium # Basic checkout for desktop Chromium
$ fetch android # Chromium checkout for Android platform
$ fetch ios # Chromium checkout for iOS platform

When the fetch tool completes you should have the following in your working directory:

.gclient # A configuration file for you source checkout
src/ # Top-level Chromium source checkout.

If you are on linux and fetching the code for the first time, then you’ll need to run:

$ cd src && ./build/install-build-deps.sh

And finally:

$ gclient sync

This will pull all dependencies of the Chromium src checkout. You will need to run this any time you update the main src checkout, including when you switch branches.

以下进入代码的下载过程:

开始下载代码

选择你想要放置chromium代码的位置,命令行cd到工作目录,执行fetch chromium即可下载代码,这句命令会执行gclient rootgclient config ...gclient sync

温馨提示:带--nohooks参数的命令(fetch --nohooks chromiumgclient sync --nohooks)不会创建和当前目录相关的文件链接,方便拷贝/压缩代码到其他目录。此种情况下,开始编译前需要执行一次gclient runhooks生成相关文件。也可以使用--no-history参数不拉取历史版本。

如果你想要了解更多的fetch参数,只要直接执行fetch即可,命令行会得到类似如下的输出:

> fetch
Error: Must specify a config.
usage: fetch.py [options] <config> [–property=value [–property2=value2 …]]

This script can be used to download the Chromium sources. See
http://www.chromium.org/developers/how-tos/get-the-code
for full usage instructions.

Valid options:
-h, –help, help Print this message.
–nohooks Don’t run hooks after checkout.
–force (dangerous) Don’t look for existing .gclient file.
-n, –dry-run Don’t run commands, only print them.
–no-history Perform shallow clones, don’t fetch the full git history.

Valid fetch configs:
android
breakpad
chromium
config_util
crashpad
dart
dartino
dartium
depot_tools
gyp
infra
infra_internal
ios
ios_internal
mojo
nacl
naclports
pdfium
skia
skia_buildbot
syzygy
v8
webrtc
webrtc_android
webrtc_ios

选择自己想要的参数,比如这里我们选择的是chromium,如果你需要android或者ios版本的话,可以选择androidios,查看官方文档可以获得更详细的说明。

温馨提示:chromium是桌面版,在windows和macos平台运行会gclient sync出不同的代码,但是二者都是使用这个参数。

如果你的网络没有问题,执行fetch chromium命令以后,会得到如下的输出,此时chromium开始下载:

>fetch chromium
Running: ‘…\depot_tools\python276_bin\python.exe’ ‘…\depot_tools\gclient.py’ root
Running: ‘…\depot_tools\python276_bin\python.exe’ ‘…\depot_tools\gclient.py’ config –spec ‘solutions = [
{
“managed”: False,
“name”: “src”,
“url”: “https://chromium.googlesource.com/chromium/src.git“,
“custom_deps”: {},
“deps_file”: “.DEPS.git”,
“safesync_url”: “”,
},
]

Running: ‘…\depot_tools\python276_bin\python.exe’ ‘…\depot_tools\gclient.py’ sync

如果你已经执行过fetch chromium命令,则(下次)只要执行gclient sync即可,否则会得到类似如下输出:

>fetch chromium
Running: ‘…\depot_tools\python276_bin\python.exe’ ‘…\depot_tools\gclient.py’ root
Your current directory appears to already contain, or be part of,
a checkout. “fetch” is used only to get new checkouts. Use
“gclient sync” to update existing checkouts.

Fetch also does not yet deal with partial checkouts, so if fetch
failed, delete the checkout and start over (crbug.com/230691).

执行完上述命令后,可以看到工作目录下下生成了一个_gclient_src_cyziaq之类的临时文件夹,文件夹名字的后6个字符是随机的。然后,命令行看起来会像是卡住了。

此时分两种情况:

直接fetch chromium

如果你是直接fetch chromium的,中途没有退出,那么命令行就这样一直卡着,不用管,没告诉你出错了就是正常的。

在此期间,你需要保持网络畅通,否则全部都要重来。

以下是完整的命令行输出:

>fetch chromium
Running: ‘…\depot_tools\python276_bin\python.exe’ ‘…\depot_tools\gclient.py’ root
Running: ‘…\depot_tools\python276_bin\python.exe’ ‘…\depot_tools\gclient.py’ config –spec ‘solutions = [
{
“managed”: False,
“name”: “src”,
“url”: “https://chromium.googlesource.com/chromium/src.git“,
“custom_deps”: {},
“deps_file”: “.DEPS.git”,
“safesync_url”: “”,
},
]

Running: ‘…\depot_tools\python276_bin\python.exe’ ‘…\depot_tools\gclient.py’ sync
Running: git submodule foreach ‘git config -f toplevel/.git/configsubmodule.name.ignore all’
Running: git config –add remote.origin.fetch ‘+refs/tags/:refs/tags/
Running: git config diff.ignoreSubmodules all

fetch chromium.gclient文件后退出,再重新用gclient sync同步生成

如果你fetch chromium之后退出命令行,再重新用gclient sync同步,那么depot_tools会生成一个新的临时文件夹,过1分钟以后,以及之后的每10秒都会得到类似如下输出,提示你depot_tools依然在正常工作:

[0:01:00] Still working on:
[0:01:00] src

[0:01:10] Still working on:
[0:01:10] src

[0:01:20] Still working on:
[0:01:20] src

然后,你就可以去喝杯茶/咖啡了,或者和妹纸/汉子聊聊天,过一段时间再回来。

温馨提示:此种情况下,在执行gclient sync之前可以修改.gclient文件的urlhttps://chromium.googlesource.com/chromium/src.git@SHA-1,以取特定版本的代码。可以在这里chromium/src.git - Git at Google查看对应版本的SHA-1值,比如56.0.2905.4版本对应的值为174a48c3cfacaf86a7ad59a79e1db598a5f317ab。注意,最好取Tags最新的大版本,不然同步第三方库的时候可能会失败!

当前(2016年11月)主干版本传输的代码(不含third_party)有6GB多,大约一个小时(取决于你的网速)后,可以看到proxifier的日志如下:

git-remote-https.exe *64 - chromium.googlesource.com:443 close, 261140 bytes (255 KB) sent, 6660233995 bytes (6.20 GB) received, lifetime 01:06:58

然后,从proxifier看似乎没有在下载了,你还需要继续等待,不要手贱关闭命令行,只要你看到Still working on:就是正常的。

耐心的等待,然后你会看到如下输出,开始下载第三方库:

Syncing projects: 0% ( 0/ 2)
[1:17:30] Still working on:
[1:17:30] src
Syncing projects: 38% (30/77) src/third_party/libsrtp
[1:21:56] Still working on:
[1:21:56] src/native_client
[1:21:56] src/third_party/catapult
[1:21:56] src/third_party/cld_2/src
[1:21:56] src/third_party/ffmpeg
….

继续等待,然后你会看到如下输出,表示代码已经下载完成:

[1:37:25] Still working on:
[1:37:25] src/native_client
[1:37:25] src/v8
Syncing projects: 100% (77/77), done.
….
Success!
….

同步工程可能出现的问题:

Traceback (most recent call last):
File “src/build/landmines.py”, line 138, in <module>
sys.exit(main())
File “src/build/landmines.py”, line 125, in main
gyp_environment.SetEnvironment()
File “…\chromium\src\build\gyp_environment.py”, line 30, in SetEnvironment
vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs()
File “…\chromium\src\build\vs_toolchain.py”, line 46, in SetEnvironmentAndGetRuntimeDllDirs
Update()
File “…\chromium\src\build\vs_toolchain.py”, line 356, in Update
subprocess.check_call(get_toolchain_args)
File “…\depot_tools\python276_bin\lib\subprocess.py”, line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘[‘…\depot_tools\python276_bin\python.exe’, ‘…\depot_tools\win_toolchain\get_toolchain_if_necessary.py’, ‘–output-json’, ‘…\chromium\src\build\win_toolchain.json’, ‘d5dc33b15d1b2c086f2f6632e2fd15882f80dbd3’]’ returned non-zero exit status 1
Error: Command ‘…\depot_tools\python276_bin\python.exe src/build/landmines.py’ returned non-zero exit status 1 in …\chromium

这是因为你没有设置环境变量:DEPOT_TOOLS_WIN_TOOLCHAIN=0,参照上文的windows准备工作。

代码下载完成

至此,chromium的代码已下载完成,后续可以使用git rebase-update(在src目录下执行),gclient sync更新和同步代码。全部的代码大约有9GB,包含git仓库占用磁盘空间有15GB多,过程大约2小时(取决于你的网速)。

取得代码分支(可选)

首先,cd到src目录,执行git fetch --tags取得所有tag,然后执行git show-ref --tags可以查看代码的tags,部分输出如下:

174a48c3cfacaf86a7ad59a79e1db598a5f317ab refs/tags/56.0.2905.4
6cbde00078342d76a24c66380e151967398e0fc9 refs/tags/6.0.397.0

假定我们要检出56.0.2905.4的代码,branch名字为branches/56.0.2905.4(可以自定)可以执行如下语句(最后的参数也可以是tags/56.0.2905.4):git checkout -b branches/56.0.2905.4 56.0.2905.4。如果要切换到一个只读的tag可以省略branch的参数,比如:git checkout tags/56.0.2905.4。检出branch/tag后,执行gclient sync --with_branch_heads --jobs 16同步代码。

返回主干可以执行:git checkout -f master,然后执行gclient sync --jobs 16同步代码。

输入git branch可以查看本地的分支,git branch -a可以查看所有的分支。如果要删除一个分支,可以执行如下命令git branch –d branches/56.0.2905.4(需要先切换到别的分支),git branch –D branches/56.0.2905.4则可以强制删除分支。

输入git show-ref --heads可以查看仓库中所有的HEAD。

来自官方文档的说明:

Note: it is usually NOT possible to sync and build a release branch (i.e. with consistent third_party DEPS)

上文说到最好是取最新的大版本号的代码就是这个原因。

编译代码

编译细节详见官方文档,这里是笔者预先下载到本地的一些文档chromium官方文档。

ninja的使用可以参考这里The Ninja build system。

相关文档:

  1. 谷歌开源项目Chromium的源码获取与项目构建(Win7+vs10/vs13) - Kuerjinjin的专栏 - 博客频道 - CSDN.NET
  2. Chromium周边了解:content_shell和cef - Kuerjinjin的专栏 - 博客频道 - CSDN.NET
  3. Chromium for windows (2015) - Kuerjinjin的专栏 - 博客频道 - CSDN.NET
  4. Chromium for mac (2015) - Kuerjinjin的专栏 - 博客频道 - CSDN.NET
  5. Chromium for Android (2015) - Kuerjinjin的专栏 - 博客频道 - CSDN.NET
  6. Chromium源码获取与编译–附加一个简单例子的编译 - glunoy的专栏 - 博客频道 - CSDN.NET
  7. chrome源码编译常见的错误解决 - share study - 博客园
  8. VS2010 Chromium编译 - 鉴于 - 博客园
  9. chromium获取代码和编译 - kanego - 博客园
  10. chromium编译 - 网事蒙尘 - 博客频道 - CSDN.NET
  11. 使用gyp构建项目,使用ninja更快的编译,以及使用出现和解决的问题记录 - 木木老蔫

参考文档:

  1. The Chromium Projects
  2. Chromium - The Chromium Projects
  3. How-Tos - The Chromium Projects
  4. Infrastructure FAQ - The Chromium Projects
  5. Get the Code: Checkout, Build, & Run Chromium - The Chromium Projects
  6. Windows Build Instructions
  7. Windows Driver Kit (WDK) - Windows 10 hardware dev
  8. Build Instructions (Windows) - The Chromium Projects
  9. Work around for MSVS 2013 - The Chromium Projects
  10. Problem with landmines.py when building under Microsoft Windows - Google Groups
  11. Unable to build chromium - Google Groups
  12. Mac Build Instructions
  13. BuildBot: Chromium
  14. depot_tools_tutorial(7)
  15. git-rebase-update(1)
  16. Working with Release Branches - The Chromium Projects
  17. 请问怎么取得git 打好的tag所对应的代码呢? - 开源中国社区
  18. Git 分支管理和冲突解决 - 圣骑士wind - 博客园
  19. git checkout 命令详解 - 胡涛儿 - 博客园
  20. Git 中 HEAD 是什么东西,为什么会出现在分支里? - SegmentFault
  21. Git - git-show-ref Documentation
  22. chrome - How do I cross-compile Chromium for ARM? - Unix & Linux Stack Exchange
0 0
原创粉丝点击