当前位置: 移动技术网 > IT编程>开发语言>c# > Chrome Visual Studio 2005下的编译过程

Chrome Visual Studio 2005下的编译过程

2019年07月18日  | 移动技术网IT编程  | 我要评论
编译篇 研究chrome ,首先得把它编译出来,这对于后续的代码分析和阅读有很大的帮助,想想自己编译出一个 chrome 浏览器来使用,那是一件很炫的事情。 编译环境准

编译篇
研究chrome ,首先得把它编译出来,这对于后续的代码分析和阅读有很大的帮助,想想自己编译出一个 chrome 浏览器来使用,那是一件很炫的事情。

编译环境准备
chrome的编译和 webkit 相比起来,难度上来说,简直是一元二次方程求解和偏微分方程求解的对比(我到现在还没有完整的把 webkit 编译出来,鄙视一下自己)。虽然 chrome 也是从 webkit 演进过来,差不多也就是把 webkit 的 js 引擎替换成了 v8 。但是不得不承认 google 把 webkit 的编译难度降低了几个数量级。

言归正传,chrome 官方网站上公布的是基于 visual studio 2005 进行编译,网上也有兄弟基于 visual studio 2008 编译成功过,但我手头上没有 visual stdio 2008 ,所以无从得知。本文也是以 visual studio2005 环境为例。我曾经在自己家里的电脑上用 visual c++ 2005 express 版本编译过,没有成功。在 xp professional 和 vista home 两个操作系统上均编译成功。

在下载chrome 代码前,需要安装下面几个软件:

1.  安装visual studio 2005.

2.  安装 visual studio 2005 service pack 1 .

3.  安装热补丁 hotfix 947315 .

4.  如果操作系统是vista ,还需要安装 visual studio 2005 service pack 1 update for windows vista 。

5.  安装 windows 2008 sdk 。按照网上说法,如果是visual studio 2008 ,就不需要安装这个了。

6.  配置windows 2008 sdk 。在开始 -> 程序 -> microsoft windows sdk v6.1 > visual studio registration > windows sdk configuration tool .。选择 make current 按钮,幸运的话,应该能一次成功。如果不能成功, chrome 官方网站上有一个 手动配置 的帮助,大家可以参考。

下载 代码
google为 chrome 提供了一个一个部署工具 depot_tools ,包括下载代码、同步代码、上传代码等功能。这个工具采用python 编写的,其中还包含了一些 javascript 脚本。 depot_tools 中包含了一个 gclient 工具,是我们需要关注的重点。

下载代码有几 种 方式:

1.  chrome官网上提供了一个 源代码包 ,可以直接下载下来。不过这个包并不是最新的包。我采用的是这种方法进行下载的,相对来说比较快。

2.  采用svn 客户端工具进行下载,比如 tortoisesvn 客户端工具, svn 服务器地址是 。

3.  采用google 提供的 depot_tools 工具。

l  下载和安装 depot_tools 。

l  把depot_tools 的安装目录设置到系统目录(系统 path 环境变量 ) 中。

l  创建一个存放chrome 代码的目录,比如 d:\chrome 。目录不要包含空格。

l  在命令行下,先将当前目录切换到chrome 代码的目录,例如上面的 (d:\chrome) 。

l  运行 gclient config 命令。gclient 将会先下载 svn 工具和 python 工具,然后调用 svn 进行代码同步。

注意: gclient 中下载svn 和 python 采用的是 javascript 实现。如果在需要设置 proxy 的环境中,则需要需要修改一下脚本。

1. 打开x:\ depot _tools\bootstrap\win\get_file.js文件。其中 x 是你的安装盘符。

2. 将line9-line22 行之间的代码

try {

    xml_http = new activexobject("msxml2.serverxmlhttp");

  } catch (e) {

    wscript.stdout.writeline("[-] xmlhttp " + new number(e.number).tohex() + 

        ": cannot create active-x object (" + e.description) + ").";

    wscript.quit(1);

  }

  try {

    xml_http.open("get", url, false);

  } catch (e) {

    wscript.stdout.writeline("[-] xmlhttp " + new number(e.number).tohex() + 

        ": invalid url.");

    wscript.quit(1);

  }

修改成

try {

    xml_http = new activexobject("msxml2. serverxmlhttp.5.0 ");

  } catch (e) {

    wscript.stdout.writeline("[-] xmlhttp " + new number(e.number).tohex() + 

        ": cannot create active-x object (" + e.description) + ").";

    wscript.quit(1);

  }

  try {

     xml_http.setproxy(2, proxyip:port);

    xml_http.open("get", url, false);

     xml_http. setproxycredentials(username,pwd);

  } catch (e) {

    wscript.stdout.writeline("[-] xmlhttp " + new number(e.number).tohex() + 

        ": invalid url.");

    wscript.quit(1);

  }

编译 代码
如果你是下载的源代码包,则需要先解压,这个代码包是双重压缩。估计要把所有代码解压下来,半个小时左右,我在我的本本上是花了将近半个小时时间才解压出来,解压下来所有代码的大小是3 个多 g 。

从网上搜索了很久相关chrome 编译相关的材料,大家都反馈在 src\chrome 目录下有 chrome.sln 文件,直接打开这个 sln 就可以利用 visual studio 2005 进行编译了。但是我翻遍所有代码却找不到这个文件,让我郁闷了很久,开始怀疑是我下的代码版本问题,在线查看了 chrome 的 svn 目录,发现最新版本也没有这个文件了。检查一下网上的那些文章基本上都是 2008 年的文章,开始怀疑是否是 chrome 做了改变,但是从 chrome 的官网上:

building chromium

1  open the  chrome/chrome.sln  solution file in visual studio and build the solution. this can take from 25 minutes to 1 hour.

2  if you just want the chromium browser, and none of the tests, you can speed up your build by right-clicking the  chrome  project in the solution explorer and selecting  build . you may want to make sure this project is the  startup  project (which will display as bold) by right-clicking it and selecting  set as startup project . this will make chromium (as opposed to some random test) build and run when you press  f5 .

来看,似乎没有更新。最后在线翻阅了chrome 的开发 group 论坛,才知道 chrome 确实作了修改,原来代码中的那些 .sln 、 .vcproj 文件全部抛弃了, google 自己开发了一个脚本工具 gyp 工具,这个工具也是采用python 编写的。 gyp 采用了自定义的一套规则,用于生成各种工程文件。我们可以看一下下面这个gyp 文件。

{

  'includes': [

    '../../build/common.gypi',

  ],

  'targets': [

    {

      'target_name': 'memory_watcher',

      'type': 'shared_library',

      'msvs_guid': '3bd81303-4e14-4559-aa69-b30c3bab08dd',

      'dependencies': [

        '../../base/base.gyp:base',

      ],

      'defines': [

        'build_memory_watcher',

      ],

      'include_dirs': [

        '../..',

      ],

      'sources': [

        'call_stack.cc',

        'call_stack.h',

        'dllmain.cc',

        'hotkey.h',

        'ia32_modrm_map.cc',

        'ia32_opcode_map.cc',

        'memory_hook.cc',

        'memory_hook.h',

        'memory_watcher.cc',

        'memory_watcher.h',

        'mini_disassembler.cc',

        'preamble_patcher.cc',

        'preamble_patcher.h',

        'preamble_patcher_with_stub.cc',

      ],

    },

  ],

}

 

其实这个文件的内容和visual studio 2005 中的 .vcproj 文件虽然有比较大的差别,但是描述的东西没有太大变化,更简单更简洁一些而已。无非描述了工程的文件,编译设置等内容。

下面描述一下编译步骤:

1.  运行命令行工具。

2.  切换到chrome 主目录下(我的电脑是 d:\chrome 目录)。

3.  执行gclient runhooks --force 。这个命令将会调用 gyp 工具,对 chrome.gyp 进行解析,生成各个 visual studio2005 工程文件。

4.  双击chrome/chrome.sln 文件,即可打开 visual studio 2005 ,一共有 215 个工程,非常庞大。

右键选择解决方案,选择生成解决方案,编译开始了。这个过程在我的本本里是持续了2 个小时左右, cpu 前一个多小时都是持续 100% ,害得我连看电影都卡的不行了。编译后的文件放置在 chrome\debug 目录下(我编译的是 debug 版本)。整个编译下来, debug 目录增加了将近 7 个 g 的东东,实在是恐怖!要编译 chrome ,至少要保留 10 个 g 的空间。

总结
整个编译chrome 的过程说实话还是花了我不少的力气,不过看着编译出来的 chrome, 心里还是很 happy 的。

 


在我编译的过程中主要遇到的几个问题:

1.  公司有visual studio2005 ,可是因为 proxy 的原因, depot_tools 工具无法进行,为了突破 proxy 的限制,花了不少力气。

    2. chrome工程组织方式发生了变化,但在官网上没有更新,网上其他的资料都是基于旧的版本介绍,所以在适应新的 gyp 方式方面花了不少力气。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网