chrome笔记

本文详细介绍了在Ubuntu环境下编译Chromium的过程,包括下载tarball、解压、设置环境变量、配置gclient、运行hooks、安装依赖库以及使用ninja编译。在编译过程中遇到了gclient runhooks出错的问题,通过修改相关脚本解决了下载问题,最终成功编译并运行Chromium,但出现了找不到SurfaceTextureListener类的错误。此外,文章还提供了不同环境下的编译步骤和注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Ubuntu11.10编译chromium for android

http://blog.youkuaiyun.com/jaylinzhou/article/details/9012993


gclient runhooks 出错:

subprocess.CalledProcessError: Command '['curl', '-L', 'https://commondatastorage.googleapis.com/nativeclient-archive2/toolchain/12356/sysroot-arm-trusted.tgz', '-o', '/home/sin/workspace/prj/chrome/androidchrome/src/arm-sysroot/sysroot-arm-trusted.tgz']' returned non-zero exit status 28
Error: Command /usr/bin/python src/build/linux/install-arm-sysroot.py --linux-only returned non-zero exit status 1 in /home/sin/workspace/prj/chrome/androidchrome

无法下载, 修改src/build/linux/install-arm-sysroot.p直接退出

ninja -C out/Debug content_shell_apk

生成out/Debug/apks/ContentShell.apk


2.3 运行错误:

I/chromium( 2420): [INFO:library_loader_hooks.cc(117)] Chromium logging enabled: level = 0, default verbosity = 0
I/dalvikvm( 2420): Failed resolving Lorg/chromium/ui/gl/SurfaceTextureListener; interface 77 'Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;'
W/dalvikvm( 2420): Link of class 'Lorg/chromium/ui/gl/SurfaceTextureListener;' failed

W/System.err( 2420): java.lang.NoClassDefFoundError: org.chromium.ui.gl.SurfaceTextureListener
W/System.err( 2420): at org.chromium.content.app.LibraryLoader.nativeLibraryLoaded(Native Method)
W/System.err( 2420): at org.chromium.content.app.LibraryLoader.initializeAlreadyLocked(LibraryLoader.java:156)
W/System.err( 2420): at org.chromium.content.app.LibraryLoader.ensureInitialized(LibraryLoader.java:63)
W/System.err( 2420): at org.chromium.content_shell_apk.ContentShellActivity.onCreate(ContentShellActivity.java:63)
W/System.err( 2420): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err( 2420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
W/System.err( 2420): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
W/System.err( 2420): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
W/System.err( 2420): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
W/System.err( 2420): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 2420): at android.os.Looper.loop(Looper.java:130)
W/System.err( 2420): at android.app.ActivityThread.main(ActivityThread.java:3691)
W/System.err( 2420): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 2420): at java.lang.reflect.Method.invoke(Method.java:507)
W/System.err( 2420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
W/System.err( 2420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
W/System.err( 2420): at dalvik.system.NativeStart.main(Native Method)
W/System.err( 2420): Caused by: java.lang.ClassNotFoundException: org.chromium.ui.gl.SurfaceTextureListener in loader dalvik.system.PathClassLoader[/data/app/org.chromium.content_shell_apk-1.apk]
W/System.err( 2420): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
W/System.err( 2420): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
W/System.err( 2420): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
W/System.err( 2420): ... 17 more
F/chromium( 2420): [FATAL:jni_android.cc(116)] Check failed: !ClearException(env) && clazz. Failed to find class org/chromium/ui/gl/SurfaceTextureListener



chrome下载编译

======================

gclient sync --force 就开始同步下载代码了,现在的任务就是等待,根据你的网络情况,可能需要下载半天到一天以上不等,如果中途出错,只需要重新执行gclient sync –-force,会自动接着上次的下载(really??)。注意一定要加--force参数选项,否则可能下载不齐全。

=======================

进入chromium代码目录“D:\chromium\home\src_tarball\tarball\chromium\src”,运行命令“gclientsync--force”,将会进行代码更新及第三方代码库的更新,并生成工程文件。实际上,该命令首先根据.glcient文件设置代码库参数,然后搜索所有的DEPS文件,根据文件中的列表下载源代码(根据平台下载本平台支持的代码);之后会执行“gclientrunhooks”命令的内容,生成平台支持的工程文件。如果我们不想更新代码,不运行“gclientsync”而直接运行“gclientrunhooks”也可以,这样直接生成工程文件。这一步时间会更久一些,一定要耐心。(后续再更新代码可以去掉--force参数)

    不过由于网络或网站的原因,有时一些代码或工具下载会失败,导致syncerror。比如我这里就出现“ download_nacl_toolchains.py ”返回失败的现象,原因是到“ commondatastorage.googleapis..com ”下载nativeclient支持的工具包(共4个)时失败,请参考 这篇文章 中的方法 ,基本思路就是找到工具包下载地址,手动下载后再放到相关目录下执行。 [注] :以上问题追踪发现原因的https地址下载失败率比较高,尝试改为http下载方式后成功。具体方法为:打开“D:\chromium\home\src_tarball\tarball\chromium\src\native_client\build\toolchainbinaries.py ”文件,将头部的“BASE_DOWNLOAD_URL ”和“BASE_ONCE_DOWNLOAD_URL ”定义中的https改为http即可。
    如果想生成makefile等文件,可以进入 代码目录“ D:\chromium\home\src_tarball\tarball\chromium\src”,运行命令“gclientrunhooks”,chromium将用GYP文件生成makefile和工程文件。同样是漫长的等待。不过执行该步骤前,请先参考执行第6步的 “componentbuild”设置
    6,编译
   开始编译前还要做一个动作,设置“component build”(也叫“shared library”或“multi-dllbuild”),即将chrome默认build一个静态库改为编译多个动态库,原因是默认编译静态库时,将会生成一个非常大的 “chrome_dll.pdb”文件(超过1G),而vs2010不支持生成超过1G的文件。
   具体方法请参考官方说明 Component build / Shared Library / Multi-DLLbuild,我采用的是第3种方法,即在 D:\chromium\home\src_tarball\tarball\chromium”目录下新建一个“ chromium.gyp_env ”文件,在其中输入“{'GYP_DEFINES':'component=shared_library'} # use space to delimit additionaldefines. ”保存。然后再执行“ gclient runhooks ”重新生成工程文件。
   OK,现在打开“D:\chromium\home\src_tarball\tarball\chromium\src\chrome\chrome.sln ”文件编译吧,这次的时间更长(我这里竟然有6个小时),但编译成功的喜悦更重要,如果编译的是debug,那么在“D:\chromium\home\src_tarball\tarball\chromium\src\build\Debug ”下已经生成了chrome.exe,运行一下看看效果吧!

======================

二、成功的经历

1.环境Ubuntu10.4.4 -desktop-amd64 + VMware Workstation 9 


2.步骤参考https://code.google.com/p/chromium/wiki/LinuxBuildInstructions,这里写的比较详细,我的步骤可以简化为,下载完tarball后,


   a.安装git-core


   b.build/install-build-deps.sh


 c.Install depot_tools   git clone  https://chromium.googlesource.com/chromium/tools/depot_tools.git


 d..bashrc添加 export PATH="$PATH":`pwd`/depot_tools


 e.gclient sync --force


 f.ninja -C out/Debug chrome

======================

下载tarball

在Chromium官网的Get the Code页面可以找到tarball下载链接
http://chromium-browser-source.commondatastorage.googleapis.com/chromium_tarball.html

 -xzvf chromium.r####.tgz

解压到当前目录

使用git下载depot_tools

git clone https://chromium.googlesource.com//tools/depot_tools.git

添加depot_tools到环境变量

修改~/.bashrc

export =$PATH:your depot_tools location

配置gclient

在chromium目录下执行

gclient config http://src.chromium.org/svn/trunk/src

runhooks

在chromium目录下执行

#配置ninja
export GYP_GENERATORS=ninja
gclient runhooks

安装所有依赖的库

 ./src/buildinstall-build-deps.sh

需要安装的库特别多,可能需要比较长的时间。

使用ninja编译

编译需要在src目录下

#Debug版
ninja  out/Debug chrome
#Release版
ninja  out/Release chrome
#编译sandbox
ninja  outDebug sand_box

=========ok=============

第一步:下载源码:
Google为Chromium项目提供了一个源码下载管理的工具depot_toos 
安装好后,把depot_toos 所在的路径添加到环境变量中,路径上不要带空格,切记。
1.初始化gclient的下载地址
 

gclient config http://src.chromium.org/svn/trunk/src

2.下载源码
gclient sync 

这一步的时间比较长,中间过程经常会被打断或出现假死的情况,重新直接下面命令就OK,

gclient sync

这个命令支持断点续传。
当gclient sync命令执行完成后,会运行.gyp文件,生成Windows平台VS可以识别的项目工程vcproj
sln项目工程文件,你就可以在src/chrome目录下看到有一个chrome.sln的工程文件,如果没有说明
glcient sync命令没有执行完,重新运行。






chrome初始化

Our WinMain function is in chrome/app/main.cc, and is linked in thechrome project.

  1. WinMain launches the Google Update Client, which is the installer/autoupdater. It will find the subdirectory for the current version, and loadchrome.dll from there.

  2. It calls ChromeMain in the newly loaded library, which is in chrome_main.cc in the chrome_dll project.

  3. ChromeMain does initialization for common components, and then forwards to eitherRendererMain inchrome/renderer/renderer_main.cc if the command line flag indicates that this should be a subprocess, orBrowserMain inchrome/browser/browser_main.cc if not to load a new copy of the application. Since this is startup, we're launching the browser.

  4. BrowserMain does common browser initialization. It has different modes for running installed webapps, connecting to the automation system if the browser is being tested, etc.

  5. It calls LaunchWithProfile in browser_init.cc which creates a newBrowser object inchrome/browser/ui/browser.cc. This object encapsulates one toplevel window in the application. The first tab is appended at this time.

Tab startup & initial navigation

  1. Browser::AddTab in chrome/browser/ui/browser.cc is called to append a new tab.

  2. It will create a new TabContents object from browser/tab_contents/tab_contents.cc

  3. TabContents creates a RenderViewHost (chrome/browser/renderer_host/render_view_host.cc) via theRenderViewHostManager's Init function inchrome/browser/tab_contents/render_view_host_manager.cc). Depending on theSiteInstance, theRenderViewHost either spawns a new renderer process, or re-uses an existingRenderProcessHost.RenderProcessHost is the object in the browser that represents a single renderer subprocess.

  4. The NavigationController inchrome/browser/tab_contents/navigation_controller.cc which is owned by the tab contents, is instructed to navigate to the URL for the new tab inNavigationController::LoadURL. "Navigating from the URL bar" from step 3 onward describes what happens from this point.









chrome启动参数

http://blog.sina.com.cn/s/blog_9df1c3cd01011i0p.html

  
http://src.chromium.org/svn/trunk/src/chrome/common/chrome_switches.cc
参数:--user-data-dir=UserDataDir
用途:自订使用者帐户资料夹(如:–user-data-dir="D:\temp\Chrome UserData")
参数:--start-maximized
用途:启动就最大化
参数:--no-sandbox
用途:取消沙盒模式
参数:--single-process
用途:单进程(程序、执行绪)运行
参数:--process-per-tab
用途:每个分页使用单独进程
参数:--process-per-site
用途:每个站点使用单独进程
参数:--in-process-plugins
用途:插件不启用单独进程
参数:--disable-popup-blocking
用途:禁用弹出拦截
参数:--disable-javascript
用途:禁用JavaScript
参数:--disable-java
用途:禁用Java
参数:--disable-plugins
用途:禁用插件
参数:–disable-images
用途:禁用图像
参数:--incognito
用途:启动后直接进入直接无痕浏览(隐身模式)
参数:--omnibox-popup-count=”num”
用途:将网址列弹出的提示选单数量改为num个
参数:--disk-cache-size
用途:设置cache文件的大小,如最大值为40MB, 则可添加参数--disk-cache-size=41943040
参数:--disk-cache-dir
用途:设定缓存存放路径,可以自行设定到高速磁盘(ramdisk),例如:--disk-cache-dir="Z:",不过个人感觉速度没有增快
参数:--enable-vertical-tabs
用途:调整chrome游览器标签存放在左边,非顶部
–purge-memory-button
--enable-internal-flash
地址栏功能:
about:version - 显示当前版本 也可以是chrome-resource://about/
about:plugins - 显示已安装插件,Google Chrome支持Active X!
about:histograms - 显示历史记录
about:dns - 显示DNS状态
about:cache, 重定向到 view-cache: 显示缓存页面
view-cache:stats - 缓存状态
about:stats - 显示状态
about:network - 很酷的网络工具
about:internets - 这应该算是一个彩蛋
chrome-resource://new-tab/ - 新标签页
about:memory - 可以查看内存和进程占用。也可以Shift+ESC,点击Statistics fornerds(傻瓜统计信息)

如何转移chrome缓存目录







这是 Google 对  http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html 的缓存。 这是该网页在 2014年8月30日 18:00:30 GMT 的快照。  当前页在此期间可能已经更改。  了解详情
提示:要在此页面上快速找到您的搜索字词,请按  Ctrl+F 或者  ⌘-F(苹果机),然后使用查找栏搜索。

 

DESCRIPTION

The Chromium depot_tools(7) suite contains many git workflow-enhancing tools which are designed to work together to enable anyone to wrangle the Chromium codebase expertly. This tutorial explains how to do development on Chromium using these tools. This will cover:

Please refer to the manpages (or --help output) for details about any of the commands mentioned in this tutorial.

Note
If your platform does not support manpages (or you prefer something a bit more expressive than plain text) you can find all documentation in html form in the [DEPOT_TOOLS]/man/html folder.

PREREQUISITES

This tutorial assumes basic familiarity with git terminology and concepts. If you need to brush up on these, the following are very good resources:

  • Think like (a) Git - A lighthearted overview of git. If you’re sorta-familiar with git, but not comfortable with it, then give this a look.

  • Git Immersion Tutorial - An in-depth git tutorial.

  • pcottle’s Visual Git Branching - An excellent interactive/graphical demo on how git handles commits, branches, and shows the operations git performs on them.

  • Pro Git book - “The” book for learning git from basics to advanced concepts. A bit dry, but very through.

If you’ve tried these out and are still having some trouble getting started, there are many other resources online which should help. If you’re really reallystuck, then chat up one of the Chromium infrastructure team members for some pointers.

Litmus Test

If you know what git addgit statusgit commit do and you know essentially what git rebase does, then you should know enough to follow along.

SETTING UP

GET DEPOT TOOLS

LINUX / MAC

Clone the depot_tools repository:

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools

Add depot_tools to the end of your PATH (you will probably want to put this in your ~/.bashrc or ~/.zshrc). Assuming you cloned depot_tools to/path/to/depot_tools:

$ export PATH=$PATH:/path/to/depot_tools
WINDOWS

Download the depot_tools bundle and extract it somewhere.

Warning
DO NOT use drag-n-drop or copy-n-paste extract from Explorer, this will not extract the hidden “.git” folder which is necessary for depot_tools to autoupdate itself. You can use “Extract all…” from the context menu though.

Add depot_tools to the end of your PATH. Assuming you unzipped the bundle to C:\workspace\depot_tools:

With Administrator access:

Control Panel → System and Security → System → Advanced system settings

Modify the PATH system variable to include C:\workspace\depot_tools.

Without Administrator access:

Control Panel → User Accounts → User Accounts → Change my environment variables

Add a PATH user variable: %PATH%;C:\workspace\depot_tools.

From a cmd.exe shell, run the command gclient (without arguments). On first run, gclient will install all the Windows-specific bits needed to work with the code, including msysgit and python.

Note
  • If you run gclient from a non-cmd shell (e.g., cygwin, PowerShell), it may appear to run properly, but msysgit, python, and other tools may not get installed correctly.

  • If you see strange errors with the file system on the first run of gclient, you may want to disable Windows Indexing.

  • If you are running Windows XP and see errors like “The system cannot execute the specified program”, try installing the“Microsoft Visual C++ 2008 Redistributable Package”.

BOOTSTRAPPING CONFIGURATION

If you have never used git before, you’ll need to set some global git configurations; substitute your name and email address in the following commands:

$ git config --global user.name “John Doe”
$ git config --global user.email “jdoe@email.com”
$ git config --global core.autocrlf false
$ git config --global core.filemode false
$ # and for fun!
$ git config --global color.ui true

TL;DR

$ # get the code
$ # In an empty directory:
$ fetch {chromium,blink,...}

$ # Update third_party repos and run pre-compile hooks
$ gclient sync

$ # Make a new change and upload it for review
$ git new-branch <branch_name>
$ # repeat: [edit, git add, git commit]
$ git cl upload

$ # After change is reviewed, commit with the CQ
$ git cl set_commit
$ # Note that the committed hash which lands will /not/ match the
$ # commit hashes of your local branch.

GETTING THE CODE

Pick an empty directory and run one of the following:

$ fetch chromium  # Basic checkout for desktop Chromium
$ fetch blink     # Chromium code with Blink checked out to tip-of-tree
$ 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.

CREATING / UPLOADING A CL

Note
The remainder of the tutorial assumes that your current working directory is the src/ folder mentioned in Getting the code.

Each CL corresponds exactly with a single branch in git. Any time you want to begin a new CL:

$ git new-branch <branch_name>

This will create and checkout a new branch named branch_name which will track the default upstream branch (origin/master). See git-new-branch(1)for more features.

Commit as many changes as you like to this branch. When you want to upload it for review, run:

$ git cl upload

This will take the diff of your branch against its upstream branch (in that case origin/master), and will post it to the Chromium code review site.

UPDATING THE CODE

Inevitably, you’ll want to pull in changes from the main Chromium repo. This is pretty easy with depot_tools:

$ git rebase-update

This command will update all of your CLs to contain the latest code from their upstreams. It will also automatically clean up CLs which have been committed and a couple other nice things. See git-rebase-update(1) for the full scoop.

One thing to look out for are merge conflicts. These happen for exactly the same as they do with SVN, but the experience is a little more controllable with git. git rebase-update will try to rebase all your branches for you, but if it encounters a merge conflict in one, it will halt and leave you in a rebase conflict state (see git-rebase(1)). Resolving git rebase merge conflicts is beyond the scope of this tutorial, but there are many good sources online (see the Prerequisites for some).

Sometimes you’re pretty certain that you’ve committed a certain branch, but git rebase-update isn’t able to tell that for sure. This is usually because your branch doesn’t rebase cleanly. You could just delete the branch with git branch -D <branch>, but you’d like to double check the diff of your branch against its upstream before deleting it. If this is the case you can abort the rebase started by git rebase-update, and then run git-squash-branch(1) to flatten your branch into a single commit. When you run git rebase-update again, you’ll get a (hopefully) much smaller / saner diff. If it turns out you were wrong about your branch being fully committed, you can use git-reflog(1) to reset your branch back to where it was before. If the diff looks inconsequential, you can use git rebase --skip to ignore it, and then git rebase-update will clean it up for you.

Once you’re done resolving all of the merge conflict, just run git rebase-update, and it will pick up where it left off. Once the command has finished updating all of your branches, it will return you back to the branch you started on.

Note
Running git rebase-update will update all your branches, but it will not automatically run gclient sync to update your dependencies.

MANAGING MULTIPLE CLS

Sometimes you want to work on more than one CL at once (say, you have a CL posted for review and want to work on something else). For each CL that you want to work on, just use git new-branch <branch_name>.

Once you start to have more than one CL at a time, it can be easy to lose your bearings. Fortunately, depot_tools has two tools to help you out:

$ git map
* 7dcfe47        (frozen_changes) 2014-03-12 ~ FREEZE.unindexed
* 4b0c180        2014-03-12 ~ modfile
* 59a7cca        2014-03-12 ~ a deleted file
* 6bec695        (origin/master) 2014-03-11 ~ Add neat feature    <(frozen_changes)
* d15a38a        2014-03-11 ~ Epic README update
* d559894        (master) 2014-03-11 ~ Important upstream change
| * 9c311fd      (cool_feature) 2014-03-11 ~ Respond to CL comments
| | * 2a1eeb2    (subfeature) 2014-03-11 ~ integrate with CoolService
| | * d777af6    2014-03-11 ~ slick commenting action
| |/
| * 265803a      2014-03-11 ~ another improvement    <(subfeature)
| * 6d831ac      (spleen_tag) 2014-03-11 ~ Refactor spleen
| * 82e74ab      2014-03-11 ~ Add widget
|/
* d08c5b3        (bogus_noparent) 2014-03-11 ~ Wonderful beginnings    <(cool_feature)

Note that this example repo is in dire need of a git-rebase-update(1)!

$ git map-branches
origin/master
  cool_feature
    subfeature
  frozen_changes *
  master
git-map(1)

This tool shows you the history of all of your branches in a pseudo-graphical format. In particular, it will show you which commits all of your branches are on, which commit you currently have checked out, and more. Check out the doc for the full details.

git-map-branches(1)

This tool just shows you which branches you have in your repo, and their upstream relationship to each other (as well as which branch you have checked out at the moment).

Additionally, sometimes you need to switch between branches, but you’ve got work in progress. You could use git-stash(1), but that can be tricky to manage because you need to remember which branches you stashed what changes on. Helpfully depot_tools includes two tools which can greatly assist in case:

git-freeze(1) allows you to put the current branch in 'suspended animation' by committing your changes to a specially-named commit on the top of your current branch. When you come back to your branch later, you can just run git-thaw(1) to get your work-in-progress changes back to what they were.

Another useful tool is git-rename-branch(1). Unlike git branch -m <old> <new>, this tool will correctly preserve the upstream relationships of your branch compared to its downstreams.

Finally, take a look at git-upstream-diff(1). This will show you the combined diff for all the commits on your branch against the upstream tracking branch. This is exactly what git cl upload will push up to code review. Additionally, consider trying the --wordwise argument to get a colorized per-word diff (instead of a per-line diff).

MANAGING DEPENDENT CLS

Now that you know how to manage independent CLs, we’ll see how to manage dependent CLs. Dependent CLs are useful when your second (or third or fourth or …) CL depends on the changes in one of your other CLs (such as: CL 2 won’t compile without CL 1, but you want to submit them as two separate reviews).

Like all of the other CLs we’ve created, we use git-new-branch(1), but this time with an extra argument. First, git checkout the branch you want to base the new one on (i.e. CL 1), and then run:

$ git new-branch --upstream_current <branch_name>

This will make a new branch which tracks the current branch as its upstream (as opposed to origin/master). All changes you commit to this branch will be in addition to the previous branch, but when you git cl upload, you will only upload the diff for the dependent (child) branch. You may have as many branches nested in this fashion as you like.

git-map(1) and git-map-branches(1) are particularly helpful when you have dependent branches. In addition, there are two helper commands which let you traverse your working copy up and down this tree of branches: git-nav-upstream(1) and git-nav-downstream(1).

Sometimes when dealing with dependent CLs, it turns out that you accidentally based a branch on the wrong upstream, but since then you’ve committed changes to it, or even based another branch off of that one. Or you discover that you have two independent CLs that would actually be much better off as dependent CLs. In instances like these, you can check out the offending branch and use git-reparent-branch(1) to move it to track a different parent. Note that this can also be used to move a branch from tracking origin/master to lkgr or vice versa.

EXAMPLE WALKTHROUGH

This section will demo what a typical workflow looks like when writing, updating, and committing multiple CLs.

$ fetch chromium
... truncated output ...
$ cd src

(only on linux)

$ ./build/install-build-deps.sh
... truncated output ...

Pull in all dependencies for HEAD

$ gclient sync
... truncated output ...

Let's fix something!

$ git new-branch fix_typo
$ echo -e '/Banana\ns/Banana/Kuun\nwq' | ed build/whitespace_file.txt
1503
1501
It was a Domo-Banana.
It was a Domo-Kuun.
$ git commit -am 'Fix terrible typo.'
[fix_typo 615ffa7] Fix terrible typo.
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git map
* 615ffa7	 (fix_typo) 2014-04-10 ~ Fix terrible typo.
* beec6f4	 (origin/master, origin/HEAD) 2014-04-10 ~ Make ReflectorImpl use mailboxes    <(fix_typo)
* 41290e0	 2014-04-10 ~ don't use glibc-specific execinfo.h on uclibc builds
* a76fde7	 2014-04-10 ~ [fsp] Add requestUnmount() method together with the request manager.
* 9de7a71	 2014-04-10 ~ linux_aura: Use system configuration for middle clicking the titlebar.
* 073b0c2	 2014-04-10 ~ ContentView->ContentViewCore in ContentViewRenderView
* 2250f53	 2014-04-10 ~ ozone: evdev: Filter devices by path
* 33a7a74	 2014-04-10 ~ Always output seccomp error messages to stderr
$ git status
# On branch fix_typo
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
$ git cl upload -r domo@chromium.org --send-mail
... truncated output ...

While we wait for feedback, let's do something else.

$ git new-branch chap2
$ git map-branches
origin/master
  chap2 *
  fix_typo
$ cat >> build/whitespace_file.txt <<EOF

"You recall what happened on Mulholland drive?" The ceiling fan rotated slowly
overhead, barely disturbing the thick cigarette smoke. No doubt was left about
when the fan was last cleaned.
EOF
$ git status
# On branch chap2
# Your branch is up-to-date with 'origin/master'.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   build/whitespace_file.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

Someone on the code review pointed out that our typo-fix has a typo :( We're still working on 'chap2' but we really want to land 'fix_typo', so let's switch over and fix it.

$ git freeze
$ git checkout fix_typo
Switched to branch 'fix_typo'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
$ echo -e '/Kuun\ns/Kuun/Kun\nwq' | ed build/whitespace_file.txt
1501
1500
It was a Domo-Kuun.
It was a Domo-Kun.
$ git upstream-diff --wordwise
diff --git a/build/whitespace_file.txt b/build/whitespace_file.txt
index 3eba355..57cdcee 100644
--- a/build/whitespace_file.txt
+++ b/build/whitespace_file.txt
@@ -17,7 +17,7 @@ swept up the streets (for it is in London that our scene lies), rattling along
the housetops, and fiercely agitating the scanty flame of the lamps that
struggled against the elements. A hooded figure emerged.

It was a Domo-BananaKun.

"What took you so long?", inquired his wife.

$ git commit -am 'Fix typo for good!'
[fix_typo 2c0ad9c] Fix typo for good!
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git cl upload
... truncated output ...

Since we got lgtm, let the CQ land it.

$ git cl set_commit
$ git map
* 0e2e52e	 (chap2) 2014-04-10 ~ FREEZE.unindexed
| * 2c0ad9c	 (fix_typo) 2014-04-10 ~ Fix typo for good!
| * 615ffa7	 2014-04-10 ~ Fix terrible typo.
|/
* beec6f4	 (origin/master, origin/HEAD) 2014-04-10 ~ Make ReflectorImpl use mailboxes    <(chap2, fix_typo)
* 41290e0	 2014-04-10 ~ don't use glibc-specific execinfo.h on uclibc builds
* a76fde7	 2014-04-10 ~ [fsp] Add requestUnmount() method together with the request manager.
* 9de7a71	 2014-04-10 ~ linux_aura: Use system configuration for middle clicking the titlebar.
* 073b0c2	 2014-04-10 ~ ContentView->ContentViewCore in ContentViewRenderView
* 2250f53	 2014-04-10 ~ ozone: evdev: Filter devices by path
* 33a7a74	 2014-04-10 ~ Always output seccomp error messages to stderr

Switch back to where we were using the nav* commands (for fun... git checkout would work here too)

$ git map-branches
origin/master
  chap2
  fix_typo *
$ git nav-upstream
Note: checking out 'origin/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at beec6f4... Make ReflectorImpl use mailboxes
$ git nav-downstream
Please select a downstream branch
  0. chap2
  1. fix_typo
Selection (0-1)[0]: 0
Previous HEAD position was beec6f4... Make ReflectorImpl use mailboxes
Switched to branch 'chap2'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
$ git map-branches
origin/master
  chap2 *
  fix_typo

Now we can pick up on chapter2 where we left off.

$ git thaw
$ git diff
diff --git a/build/whitespace_file.txt b/build/whitespace_file.txt
index 3eba355..9d08d9d 100644
--- a/build/whitespace_file.txt
+++ b/build/whitespace_file.txt
@@ -34,3 +34,7 @@ with his fork, watching the runny jelly spread and pool across his plate,
 like the blood of a dying fawn. \"It reminds me of that time --\" he started, as
 his wife cut in quickly: \"-- please. I can't bear to hear it.\". A flury of
 images coming from the past flowed through his mind.
+
+"You recall what happened on Mulholland drive?" The ceiling fan rotated slowly
+overhead, barely disturbing the thick cigarette smoke. No doubt was left about
+when the fan was last cleaned.
$ cat >> build/whitespace_file.txt <<EOF

There was an poignant pause.
EOF
$ git diff
diff --git a/build/whitespace_file.txt b/build/whitespace_file.txt
index 3eba355..e3a55de 100644
--- a/build/whitespace_file.txt
+++ b/build/whitespace_file.txt
@@ -34,3 +34,9 @@ with his fork, watching the runny jelly spread and pool across his plate,
 like the blood of a dying fawn. \"It reminds me of that time --\" he started, as
 his wife cut in quickly: \"-- please. I can't bear to hear it.\". A flury of
 images coming from the past flowed through his mind.
+
+"You recall what happened on Mulholland drive?" The ceiling fan rotated slowly
+overhead, barely disturbing the thick cigarette smoke. No doubt was left about
+when the fan was last cleaned.
+
+There was an poignant pause.
$ git commit -am 'Finish chapter 2'
[chap2 ceef712] Finish chapter 2
 1 file changed, 6 insertions(+)
$ git map
* ceef712	 (chap2) 2014-04-10 ~ Finish chapter 2
| * 2c0ad9c	 (fix_typo) 2014-04-10 ~ Fix typo for good!
| * 615ffa7	 2014-04-10 ~ Fix terrible typo.
|/
* beec6f4	 (origin/master, origin/HEAD) 2014-04-10 ~ Make ReflectorImpl use mailboxes    <(chap2, fix_typo)
* 41290e0	 2014-04-10 ~ don't use glibc-specific execinfo.h on uclibc builds
* a76fde7	 2014-04-10 ~ [fsp] Add requestUnmount() method together with the request manager.
* 9de7a71	 2014-04-10 ~ linux_aura: Use system configuration for middle clicking the titlebar.
* 073b0c2	 2014-04-10 ~ ContentView->ContentViewCore in ContentViewRenderView
* 2250f53	 2014-04-10 ~ ozone: evdev: Filter devices by path
* 33a7a74	 2014-04-10 ~ Always output seccomp error messages to stderr
$ git cl upload -r domo@chromium.org --send-mail
... truncated output ...

We poke a committer until they lgtm :)

$ git cl set_commit

While that runs through the CQ, let's get started on chapter 3. Since we know that chapter 3 depends on chapter 2, we'll track the current chapter2 branch.

$ git new-branch --upstream_current chap3
$ cat >> build/whitespace_file.txt <<EOF

CHAPTER 3:
Mr. Usagi felt that something wasn't right. Shortly after the Domo-Kun left he
began feeling sick.
EOF
$ git commit -am 'beginning of chapter 3'
[chap3 7d4238a] beginning of chapter 3
 1 file changed, 4 insertions(+)
$ git map
* 7d4238a	 (chap3) 2014-04-10 ~ beginning of chapter 3
* ceef712	 (chap2) 2014-04-10 ~ Finish chapter 2    <(chap3)
| * 2c0ad9c	 (fix_typo) 2014-04-10 ~ Fix typo for good!
| * 615ffa7	 2014-04-10 ~ Fix terrible typo.
|/
* beec6f4	 (origin/master, origin/HEAD) 2014-04-10 ~ Make ReflectorImpl use mailboxes    <(chap2, fix_typo)
* 41290e0	 2014-04-10 ~ don't use glibc-specific execinfo.h on uclibc builds
* a76fde7	 2014-04-10 ~ [fsp] Add requestUnmount() method together with the request manager.
* 9de7a71	 2014-04-10 ~ linux_aura: Use system configuration for middle clicking the titlebar.
* 073b0c2	 2014-04-10 ~ ContentView->ContentViewCore in ContentViewRenderView
* 2250f53	 2014-04-10 ~ ozone: evdev: Filter devices by path
* 33a7a74	 2014-04-10 ~ Always output seccomp error messages to stderr

We haven't updated the code in a while, so let's do that now.

$ git rebase-update
Fetching origin
From https://upstream
   beec6f4..59cdb73  master     -> origin/master
Rebasing: chap2
Rebasing: fix_typo
Failed! Attempting to squash fix_typo ... Success!
Rebasing: chap3
Deleted branch fix_typo (was 5d26fec).
Reparented chap3 to track origin/master (was tracking chap2)
Deleted branch chap2 (was 5d26fec).

Well look at that. The CQ landed our typo and chapter2 branches already and git rebase-update cleaned them up for us.

$ gclient sync
... truncated output ...
$ git map
* 93fe917	 (chap3) 2014-04-10 ~ beginning of chapter 3
* 5d26fec	 (origin/master, origin/HEAD) 2014-04-10 ~ Finish chapter 2    <(chap3)
* df7fefb	 2014-04-10 ~ Revert 255617, due to it not tracking use of the link doctor page properly.
* 4b39cda	 2014-04-10 ~ Fix terrible typo.
* 248c5b6	 2014-04-10 ~ Temporarily CHECK(trial) in ChromeRenderProcessObserver::OnSetFieldTrialGroup.
* 8171df8	 2014-04-10 ~ Remove AMD family check for the flapper crypto accelerator.
* d6a30d2	 2014-04-10 ~ Change the Pica load benchmark to listen for the polymer-ready event
* beec6f4	 2014-04-10 ~ Make ReflectorImpl use mailboxes
* 41290e0	 2014-04-10 ~ don't use glibc-specific execinfo.h on uclibc builds
* a76fde7	 2014-04-10 ~ [fsp] Add requestUnmount() method together with the request manager.
* 9de7a71	 2014-04-10 ~ linux_aura: Use system configuration for middle clicking the titlebar.
* 073b0c2	 2014-04-10 ~ ContentView->ContentViewCore in ContentViewRenderView
* 2250f53	 2014-04-10 ~ ozone: evdev: Filter devices by path
* 33a7a74	 2014-04-10 ~ Always output seccomp error messages to stderr

Someone on IRC mentions that they actually landed a chapter 3 already! We should pull their changes before continuing. Brace for a code conflict!

$ git rebase-update
Fetching origin
From https://upstream
   5d26fec..59cdb73  master     -> origin/master
Rebasing: chap2
... lots of output, it's a conflict alright :(...
$ git diff
diff --cc build/whitespace_file.txt
index 1293282,f903ea2..0000000
--- a/build/whitespace_file.txt
+++ b/build/whitespace_file.txt
@@@ -42,4 -42,5 +42,9 @@@ when the fan was last cleaned
  There was an poignant pause.

  CHAPTER 3:
++<<<<<<< HEAD
 +Hilariousness! This chapter is awesome!
++=======
+ Mr. Usagi felt that something wasn't right. Shortly after the Domo-Kun left he
+ began feeling sick.
++>>>>>>> beginning of chapter 3

Oh, well, that's not too bad. In fact... that's a terrible chapter 3!

$ $EDITOR build/whitespace_file.txt
... /me deletes bad chapter 3 ...
$ git add build/whitespace_file.txt
$ git diff --cached
diff --git a/build/whitespace_file.txt b/build/whitespace_file.txt
index 1293282..f903ea2 100644
--- a/build/whitespace_file.txt
+++ b/build/whitespace_file.txt
@@ -42,4 +42,5 @@ when the fan was last cleaned.
 There was an poignant pause.

 CHAPTER 3:
-Hilariousness! This chapter is awesome!
+Mr. Usagi felt that something wasn't right. Shortly after the Domo-Kun left he
+began feeling sick.

Much better

$ git rebase --continue
Applying: beginning of chapter 3
$ git rebase-update
Fetching origin
chap3 up-to-date
$ gclient sync
... truncated output ...
$ git map
* 1cb4f5b	 (chap3) 2014-04-10 ~ beginning of chapter 3
* 59cdb73	 (origin/master, origin/HEAD) 2014-04-10 ~ Refactor data interchange format.    <(chap3)
* 34676a3	 2014-04-10 ~ Ensure FS is exited for all not-in-same-page navigations.
* 7d4784e	 2014-04-10 ~ Add best chapter2 ever!
* 5d26fec	 2014-04-10 ~ Finish chapter 2
* df7fefb	 2014-04-10 ~ Revert 255617, due to it not tracking use of the link doctor page properly.
* 4b39cda	 2014-04-10 ~ Fix terrible typo.
* 248c5b6	 2014-04-10 ~ Temporarily CHECK(trial) in ChromeRenderProcessObserver::OnSetFieldTrialGroup.
* 8171df8	 2014-04-10 ~ Remove AMD family check for the flapper crypto accelerator.
* d6a30d2	 2014-04-10 ~ Change the Pica load benchmark to listen for the polymer-ready event
* beec6f4	 2014-04-10 ~ Make ReflectorImpl use mailboxes
* 41290e0	 2014-04-10 ~ don't use glibc-specific execinfo.h on uclibc builds
* a76fde7	 2014-04-10 ~ [fsp] Add requestUnmount() method together with the request manager.
* 9de7a71	 2014-04-10 ~ linux_aura: Use system configuration for middle clicking the titlebar.
* 073b0c2	 2014-04-10 ~ ContentView->ContentViewCore in ContentViewRenderView
* 2250f53	 2014-04-10 ~ ozone: evdev: Filter devices by path
* 33a7a74	 2014-04-10 ~ Always output seccomp error messages to stderr
$ git cl upload
... truncated output ...

So there you have the basic flow. Note that you don’t have to do chromium development using these tools. Any git workflow is compatible, as long as git cl upload is able to upload good patches.

CONCLUSION

Hopefully that gives you a good starting overview on Chromium development using depot_tools. If you have questions which weren’t answered by this tutorial or the man pages for the tools (see the index of all tools here: depot_tools(7)), please feel free to ask.

GLOSSARY

CL

change-list. This is a diff which you would like to commit to the codebase.

DEPS

A file in the chromium checkout which gclient sync uses to determine what dependencies to pull in. This file also contains hooks.

LKGR

Last Known Good Revision. This is a git-tag(1) which tracks the last version of origin/master which has passed the full set of testing on the main Chromium waterfall.

CHROMIUM DEPOT_TOOLS

Part of the chromium depot_tools(7) suite. These tools are meant to assist with the development of chromium and related projects. Download the tools from here.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值