Chromium C++ Codebase contributing tricks & tips for myself. I'm using ubuntu 22.04 right now, so other OS docs are likely not up-to-date.
This is docs for ubuntu 22.04, for other OS, please refer to macOS.md or Windows.md
- Git
- Python v3.8+
Install depot_tools ref
mkdir -p ~/code/google/
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ~/code/google/depot_tools
export PATH="${HOME}/code/google/depot_tools:$PATH"
Get the code ref
mkdir -p ~/code/google/chromium && cd ~/code/google/chromium
fetch --nohooks chromium
cd src
./build/install-build-deps.sh
gclient runhooks
"-j=16"
"--malloc-trim"
"--background-index"
"--pch-storage=memory"
gn gen out/Default
gn args out/Default
set args to ref
is_debug=true
symbol_level=1
blink_symbol_level=1
v8_symbol_level=0
enable_nacl=false
Update your checkout ref
~ git rebase-update
~ gclient sync -Df
Faster build ref
- edit
.gclient
file ref
solutions = [
{
...,
"custom_vars": {
# This is the correct instance name for using Chromium's RBE service.
# You can only use it if you were granted access to it. If you use your
# own REAPI-compatible backend, you will need to change this accordingly
# to its requirements.
"rbe_instance": "projects/rbe-chromium-untrusted/instances/default_instance",
},
},
]
- change gn args
gn args out/Default
is_debug=true
symbol_level=1
blink_symbol_level=1
v8_symbol_level=0
enable_nacl=false
# with rbe by google
use_remoteexec = true
reclient_cfg_dir = "../../buildtools/reclient_cfgs/linux"
Start build ref
autoninja -C out/Default chrome
gn ls out/Default
out/Default/chrome
Generate compile_commands.json
ref
# unix like
tools/clang/scripts/generate_compdb.py -p out/Default > compile_commands.json
# powershell
# NOTE: if failed, please check python version, need python3
python tools/clang/scripts/generate_compdb.py -p out/Default | out-file -encoding utf8 compile_commands.json
Logging ref
./out/release/chrome.exe --enable-logging=stderr --v=-1
- in code
#include "base/logging.h"
// ...
LOG(ERROR) << "YOUR LOG" << YOUR_VARIABLE ;
StackTrace ref
#include "base/debug/stack_trace.h"
// ...
LOG(ERROR) << "StackTrace: " << base::debug::StackTrace{};
need --disable-gpu-sandbox
flag if you are debugging gpu process, --no-sandbox
flag if you are debugging one of the renderer processes
run unittests locally ref
- find subset
~ gn refs out/Default --testonly=true --type=executable --all chrome/browser/ui/browser_list_unittest.cc
//chrome/test:unit_tests
- use it without double slash
~ autoninja.bat -C ./out/Default/ 'third_party/blink/renderer/controller:blink_unittests'
ninja: Entering directory `./out/Default/'
[3/3] LINK blink_unittests.exe blink_unittests.exe.pdb
- Run it with gtest_filter
for example, run
TEST(CSSMathExpressionNode, TestProgressNotationComplex)
~ out/Default/unit_tests --gtest_filter="BrowserListUnitTest.*"
Initial setup ref
autoninja -C out/Default blink_tests
Run Web tests ref
third_party/blink/tools/run_web_tests.py -t Default
Stop skip some tests ref
third_party/blink/web_tests/TestExpectations
file contains all the skipped tests, you can remove the line end with [Failure]
to run the test.
Caution: don't add './' to web tests path (like
./third_party/blink/...
), instead usethird_party/blink/...
# To run only some of the tests, specify their directories or filenames as arguments to run_web_tests.py relative to the web test directory (src/third_party/blink/web_tests). For example, to run the fast form tests, use:
third_party/blink/tools/run_web_tests.py fast/forms
# Or you could use the following shorthand:
third_party/blink/tools/run_web_tests.py fast/fo\*
Run WPT tests ref
third_party/blink/tools/run_wpt_tests.py --target=Default --product=headless_shell external/wpt/html/dom
Rebaseline locally ref
third_party/blink/tools/run_web_tests.py --reset-results foo/bar/test.html