Compilation
When studying Chrome, you must first compile it, which will be of great help to subsequent code analysis and reading. Think about compiling a Chrome browser to use by yourself, which is a very dazzling thing.
Compilation environment preparation
Compared with WebKit, Chrome's compilation is simply a comparison between solving a quadratic equation and partial differential equation (I have not yet compiled WebKit completely, so I despise myself). Although Chrome has evolved from WebKit, it almost replaced WebKit's JS engine with V8. But it has to be admitted that Google has reduced the compilation difficulty of WebKit by orders of magnitude.
Back to the topic, the official Chrome website announced that it is compiled based on Visual Studio 2005. There are brothers online that have successfully compiled based on Visual Studio 2008, but I don’t have Visual Studio 2008 on hand, so I have no way to know. This article also takes the Visual Studio2005 environment as an example. I have compiled it with Visual C++ 2005 Express on my own computer at home, but it has not been successful. Compiled successfully on both XP Professional and Vista Home operating systems.
Before downloading Chrome code, you need to install the following software:
1. Install Visual Studio 2005.
2. Install Visual Studio 2005 Service Pack 1.
3. Install hot patch Hotfix 947315.
4. If the operating system is Vista, you also need to install Visual Studio 2005 Service Pack 1 Update for Windows Vista.
5. Install the Windows 2008 SDK. According to the online saying, if it is Visual Studio 2008, you don't need to install this.
6. Configure the Windows 2008 SDK. In Start -> Programs -> Microsoft Windows SDK v6.1 > Visual Studio Registration > Windows SDK Configuration Tool. Select the make current button. If you are lucky, you should succeed in one go. If it fails, there is a manual configuration help on the official Chrome website, you can refer to it.
Download Code
Google provides Chrome with deployment tools deposit_tools, including download code, synchronize code, upload code and other functions. This tool is written in Python and also contains some Javascript scripts. Depot_tools contains a gclient tool, which is the focus of our attention.
There are several ways to download the code:
1. A source code package is provided on the official Chrome website, which can be downloaded directly. But this package is not the latest one. I used this method to download it, which is relatively fast.
2. Use SVN client tools to download, such as the TortoiseSVN client tool, the SVN server address is/svn/trunk/src 。
3. Use the deposit_tools tool provided by Google.
l Download and install deposit_tools.
l Set the installation directory of deposit_tools to the system directory (system Path environment variable).
l Create a directory that stores Chrome code, such as d:\chrome. Do not contain spaces in the directory.
l On the command line, first switch the current directory to the directory of the chrome code, such as (d:\chrome) above.
l Run gclient config/svn/trunk/srcOrder. Gclient will first download the svn tool and python tool, and then call svn to synchronize the code.
Note: The svn and python download in gclient use javascript implementation. If you need to set proxy, you need to modify the script.
1. Open the X:\depot _tools\bootstrap\win\get_file.js file. Where X is your installation drive letter.
2. Convert the code between Line9-Line22 lines
try {
xml_http = new ActiveXObject("");
} catch (e) {
("[-] XMLHTTP " + new Number().toHex() +
": Cannot create Active-X object (" + ) + ").";
(1);
}
try {
xml_http.open("GET", url, false);
} catch (e) {
("[-] XMLHTTP " + new Number().toHex() +
": invalid URL.");
(1);
}
Modify to
try {
xml_http = new ActiveXObject("MSXML2. ServerXMLHTTP.5.0 ");
} catch (e) {
("[-] XMLHTTP " + new Number().toHex() +
": Cannot create Active-X object (" + ) + ").";
(1);
}
try {
xml_http.setProxy(2, proxyIP:Port);
xml_http.open("GET", url, false);
xml_http. setProxyCredentials(username,pwd);
} catch (e) {
("[-] XMLHTTP " + new Number().toHex() +
": invalid URL.");
(1);
}
Compile code
If you are downloading the source code package, you need to decompress first. This code package is double compression. It is estimated that all the code needs to be decompressed. It took me about half an hour to decompress it on my notebook. The size of all codes is more than 3 G.
I have searched online for a long time for relevant Chrome compilation materials. Everyone has reported that there is a file in the src\chrome directory. Just open this sln and you can use Visual Studio 2005 to compile. But I searched through all the code but couldn't find this file, which made me depressed for a long time. I began to suspect that it was the code version I downloaded. I checked the SVN directory of Chrome online and found that the latest version did not have this file. Check out the articles on the Internet, which are basically 2008 articles, and start to wonder if Chrome has made changes, but from the official website of Chrome:
Building Chromium
1 Open the chrome/ 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 .
Looks like there is no update. Finally, I read the Chrome development group forum online and found out that Chrome has indeed made changes. All the .sln and .vcproj files in the original code have been abandoned. Google developed a script tool GYP tool, which is also written in python. GYP adopts a custom set of rules to generate various project files. We can take a look at the following gyp file.
{
'includes': [
'../../build/',
],
'targets': [
{
'target_name': 'memory_watcher',
'type': 'shared_library',
'msvs_guid': '3BD81303-4E14-4559-AA69-B30C3BAB08DD',
'dependencies': [
'../../base/:base',
],
'defines': [
'BUILD_MEMORY_WATCHER',
],
'include_dirs': [
'../..',
],
'sources': [
'call_stack.cc',
'call_stack.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',
],
},
],
}
In fact, although the content of this file is quite different from the .vcproj file in visual studio 2005, the description has not changed much, and it is just a simpler and more concise. It simply describes the project's files, compilation settings, etc.
The compilation steps are described below:
1. Run the command line tool.
2. Switch to the Chrome home directory (my computer is the d:\chrome directory).
3. Execute gclient runhooks --force. This command will call the GYP tool, parse it, and generate each Visual Studio2005 project file.
4. Double-click the chrome/ file to open Visual Studio 2005. There are 215 projects in total, which is very large.
Right-click to select the solution, select Generate solution, and compilation begins. This process lasted about 2 hours in my notebook, and the CPU lasted 100% more than an hour before, which made me unable to even get stuck watching movies. The compiled file is placed in the chrome\debug directory (I compiled the debug version). After the entire compilation, the Debug directory has added nearly 7 G things, which is really scary! To compile Chrome, you must reserve at least 10 G of space.
Summarize
To be honest, the entire process of compiling Chrome still took a lot of effort, but looking at the compiled Chrome, I still feel very happy.
Several main problems I encountered during the compilation process:
1. The company has Visual Studio2005, but due to Proxy, the depot_tools tool cannot be used. It took a lot of effort to break through the limitations of proxy.
2. The organization method of Chrome project has changed, but it has not been updated on the official website. Other information on the Internet is based on the old version, so I have spent a lot of effort to adapt to the new gyp method.