SUMMARY
There is a new system for doing enable/disable build flags that works a bit differently. Use it for new flags and be prepared to encounter #if BUILDFLAG() in the wild.
MORE INFO
If you're adding a new feature flag, please don't add it globally (common.gypi, build/config/BUILD.gn, etc.). Instead, add it to the lowest-level target that needs to know about it, and use the new generated header system to make headers that allow .cc file to see the define if they want to. This helps keep the build more modular.
If you recall writing a flag that you added to common.gypi, especially one only used in few places, please help convert it.
You key off of these flags like:
#if BUILDFLAG(ENABLE_FOO)
The BUILDFLAG wrapper macro helps prevent some errors. If you forget and do an old-style #ifdef ENABLE_FOO on a new-style flag, it will always be false.
I added a "chrome common features" target that you can add high-level defines for that only the chrome layer needs to know about. This is pretty hooked into the dependency tree so you hopefully won't encounter the problems below.
You can read about the mechanics in //build/buildflag_header.gni
GENERATED HEADER GOTCHAS:
This generates headers at build-time. The following applies to all generated headers (you probably previously encountered these issues the most with protobufs):
- The generate step must be a dependency of any target that uses it, or clean builds will fail (Ninja will notice the header for incremental compiles and will "fix" the ordering). So if you see a compile failure due to a missing header, you probably need to add a dependency. These can be flaky since it depends on the build ordering, so don't ignore it if it goes away!
- In the GN build, the build_header target must only be "somewhere" in the dependency tree. "gn check" will tell if you if you screwed up, but only for the parts of the tree that are whitelisted for "gn check" to run (see src/.gn for the list). Please help expand this list! (*)
- The GYP build is more picky. Since hard dependencies aren't transitive, the entire path from the target where you include the header to the target that generates it must be marked hard, or there must be no intermediate targets. Hopefully we won't have to maintain this much longer.
Brett
(*) Adding a target to "gn check" is easy. Doing this is a nice way to help the GN build without a big time commitment, and helps prevent certain classes of errors.
Open the ".gn" file in "src". Find the big list labeled "check_targets". Add your target. Then run "gn check out/foobar", fix errors it tells you about (almost always just missing deps).