I would like to add a new option to the `gn gen` command to generate a JSON file that maps GN labels to lists of Ninja target paths.
This will be used by Fuchsia to improve developer workflows, in particular supporting building targets directly by passing their GN label (e.g. `fx build <label>`) instead of their Ninja output paths, as well as improving certain error messages when build commands break.
The former is important for our long-term migration to Bazel, i.e. we want developers to not rely on Ninja-specific output paths, and in the future, `fx build` will also recognize Bazel target labels in addition to GN one.
A prototype has been implemented, see
CL1 and
CL2 on Gerrit.
The change does not introduce much complexity, nor does it modify GN behavior, or slows down `gn gen` when the option is not used. The generation takes only 400ms on a large Fuchsia build plan, and produces a file with a very simple schema, i.e.:
{
"gn_label1": [ "path1", "path2" ],
"gn_label2": [ "path3" ],
...
}
Which is trivial to process (separately) into a faster binary format, to make queries fast in both directions.
Alternatives considered were to rely on the `project.json` file but:
- Generating this file is far slower (up to 8 seconds on top of 13 seconds for regular options).
- The output file is 10x to 20x larger, and parsing it to extract target outputs is slow.
- It does not include all Ninja output paths (e.g. stamp files), that we need in our use case.
Let me know what you think and if you have objections.
- Digit