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
gn gen out/Default
Update your checkout ref
~ git rebase-update
~ gclient sync -Df
Faster build ref
gn args out/Default
enable_nacl=false
symbol_level=1
blink_symbol_level=1
v8_symbol_level=0
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