GN: don't write separate files for non-binary targets

Binary targets that compile code need to be in separate ninja files for the various flags variables to be properly scoped. But other targets like groups and actions don't. This change skips making separate files for such targets.

The target writers have changed to return the code they want written to the main ninja file, which is either all of the code (for the new integrated case) or a subninja line to reference a written file. This allowed some amount of cleanup in how the Ninja toolchain files were written.

The changes in the ninja toolchain files required more changes in the NinjaBuildWriter because the lists the NinjaBuildWriter were no longer being generated as a side effect of running. The build writer is now more isolated and can run without such precomputed context. There was a fair bit of refactoring required to make this work in ninja_build_writer.cc. Effectively the complexity in NinjaWriter moved to NinjaBuildWriter::RunAndWriteFiles.

A related cleanup is that I noticed the Builder object is RefCountedThreadsafe because it used to be used across threads. But a while ago I changes this to work on the main thread only. I removed the refcounting and changed most places to pass by reference instead of pointer.

GN runtime stats:
 - Desktop Linux: saves 2656 files, 110ms.
 - Android: saves 8825 files, 231ms.
 - Windows: saves 2203 files, 247ms.

Ninja no-op build stats (measures loading time):
 - Desktop Linux: same
 - Android: regressed 50ms (maybe because there's less parsing parallelism and Linux's filesystem is so fast?)
 - Windows: saves 156ms (because Windows' filesystem is so slow.

Review-Url: https://codereview.chromium.org/2152413002
Cr-Original-Commit-Position: refs/heads/master@{#407908}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 8293c354da7aee9e9a7130b3b6f67d9ea43a7230
31 files changed
tree: 1e89f962f97034144e27619b0da523b04a70f5be
  1. tools/