Updating regeneration flow to prevent build.ninja deletion

28 views
Skip to first unread message

Bryan Henry

unread,
Jul 6, 2022, 2:20:33 PM7/6/22
to gn-dev
There was a discussion I'd started about this off-list, but moving it here to gn-dev@ to allow for others to participate or view.

`gn gen` currently has a number of flags that control things like IDE settings, compilation database generation, and so forth. For example, --export-compile-commands was added back in 2018. At the time, there was some discussion here (https://groups.google.com/a/chromium.org/g/gn-dev/c/uzQJX4-zKXo) about how these settings should be provided. That discussion landed on the command line arguments to gen that we have today, but alternatives like globally scoped GN arguments that could be set in args.gn or improved variants of that were also raised.

There is one major downside with the command line arguments today because of a bug (or, at least, unfortunate interaction) between GN and ninja. These arguments are only persisted in the `gn gen` command line that GN generates and drops in build.ninja, since ninja is what initiates regeneration as build inputs change. This is generally fine, but it is much too easy to cause ninja to delete build.ninja - and those settings along with it - today simply by interrupting (e.g. with Ctrl-C) regeneration. This forces the user to manually run `gn gen` again. In the case of GN-using projects like Pigweed, devloper tools like `pw watch` have adapted to automatically run gen if this happens. Unfortunately, the user may not remember what flags they used in the past, and `pw watch` for example doesn't make any attempt to preserve flags. This results in potentially surprising loss of settings and, if you use `pw watch`, poor behavior like your compilation database suddenly not regenerating anymore.

This was all discovered by others in the past and https://bugs.chromium.org/p/gn/issues/detail?id=25 already exists for this. I'm implementing the "best solution-without-changing ninja" proposal from that bug in https://gn-review.googlesource.com/c/gn/+/14200. The change is mostly done modulo a few tweaks and any review-prompted changes. It modifies the flow of regeneration somewhat, so if you're interested in that please take a look; details are captured in the commit message.
Reply all
Reply to author
Forward
0 new messages