Can’t make the #ChromeDevSummit this year? Catch all the content (and more!) on the livestream, or join your peers for a CDS Extended event at a hosted location nearby. To learn more, check out the Chrome Dev Summit 2019 website.

The Chromium Chronicle: Preprocessing Source

Episode 7: October 2019

by Bruce Dawson in Seattle

Sometimes it is helpful to compile a single Chromium source file by hand, perhaps to experiment with compiler optimization options, to preprocess it to a single file to understand some subtle macro details, or to minimize a compiler bug.

A few tricks will let a Chromium developer find and execute the command that compiles a particular source file, with modifications as needed.

Start by going to your output directory and using autoninja (or ninja) to compile the file of interest (and any dependencies) using the ^ suffix. This suffix tells ninja to build the output of the specified file—version.o in this case. Then, touch the file, and compile it (and only it) again with the -v (verbose) flag to ninja:

On Linux or OSX:

$ autoninja ../../base/version.cc^
$ touch ../../base/version.cc
$ autoninja -v ../../base/version.cc^

In the Windows cmd shell ^ is a special character and must be escaped:

C:\> autoninja ../../base/version.cc^^
C:\> touch ../../base/version.cc
C:\> autoninja -v ../../base/version.cc^^

Typical output of the autoninja -v command looks like this (significantly trimmed):

..\..\third_party\llvm-build\Release+Asserts\bin\clang-cl.exe /nologo /showIncludes -imsvc ...

This command allows you to compile the file of interest. To get the preprocessed output, use the following steps:

On Linux or OSX, remove the -o obj/base/base/version.o block from the end, and add -E. This tells the compiler to print the preprocessed file to stdout.

Redirect the output to a file, like this:

../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD ... -E >version.i

On Windows, remove the /showIncludes option from the beginning (it prints a line of output for each #include) and then add /P in order to preprocess the file instead of compiling it. The results will be saved in the current directory in version.i:

..\..\third_party\llvm-build\Release+Asserts\bin\clang-cl.exe /nologo -imsvc ... /P

Now you can examine the preprocessed file to see what the macros are actually doing, or make experimental compiler-switch changes and recompile to see what happens.

Additional Resources

  • Fast Chrome Builds: For more build-optimization tips (focused on Windows).
  • ETW: Find out how to find Windows performance problems—in Chrome or in the build—by reading the ETW (also known as Xperf) docs.
Was this page helpful?
Yes
What was the best thing about this page?
It helped me complete my goal(s)
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It had the information I needed
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It had accurate information
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It was easy to read
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
Something else
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
No
What was the worst thing about this page?
It didn't help me complete my goal(s)
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It was missing information I needed
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It had inaccurate information
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It was hard to read
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
Something else
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.

rss_feed Subscribe to our RSS or Atom feed and get the latest updates in your favorite feed reader!