Avoid unnecessary "Regenerating ninja files" step after running "gn gen"

Before this change, if you touch args.gn, run "gn gen" and then run
ninja, ninja produces a "Regenerating ninja files" step which
unnecessarily runs "gn gen" again, and this happens under conditions
for which this was previously fixed.

This can be reproduced in the Fuchsia build:

  # Precondition: "Regenerating ninja files" needs to have happened
  # once before.  This will achieve that.
  fx set bringup.x64 --release
  touch out/default/args.gn
  fx build

  # Immediate reproducer: With the bug, "fx build" produces
  # "Regenerating ninja files".
  fx set bringup.x64 --release
  fx build

This problem arose before in issue 136 and was fixed by this change:
https://gn-review.googlesource.com/c/gn/+/10400
("Restat build.ninja after gen", December 2020)

However, that fix no longer has any effect following this change:
https://gn-review.googlesource.com/c/gn/+/14200
("[gn] Prevent build.ninja deletion when regeneration is interrupted",
August 2022)

We can fix this by telling Ninja to restat build.ninja.stamp instead
of build.ninja.

Ideally we would add a test case for this that tests the behaviour of
GN and Ninja together.  As well as preventing another regression, that
would help with explaining the problem, since the conditions for it
are somewhat subtle.  However, GN currently has no integration tests
of that kind.

So ideally I would drop the restat of build.ninja, because it's not
currently necessary.  I'm leaving it place as a defensive measure
because there is no test coverage to ensure that the restats are kept
in sync with the rest of the code, and also because the cost of
keeping it is small.

Bug: 344
Test: manual, see above
Change-Id: Ifb042070710754c486541dde427c3d8bba0fa6a0
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/15940
Reviewed-by: Petr Hosek <phosek@google.com>
Commit-Queue: Petr Hosek <phosek@google.com>
diff --git a/src/gn/command_gen.cc b/src/gn/command_gen.cc
index ec4a766..5d4b75b 100644
--- a/src/gn/command_gen.cc
+++ b/src/gn/command_gen.cc
@@ -447,14 +447,16 @@
   }
 
   // If we have a ninja version that supports restat, we should restat the
-  // build.ninja file so the next ninja invocation will use the right mtime. If
-  // gen is being invoked as part of a re-gen (ie, ninja is invoking gn gen),
-  // then we can elide this restat, as ninja will restat build.ninja anyways
-  // after it is complete.
+  // build.ninja or build.ninja.stamp files so the next ninja invocation
+  // will use the right mtimes. If gen is being invoked as part of a re-gen
+  // (ie, ninja is invoking gn gen), then we can elide this restat, as
+  // ninja will restat the appropriate file anyways after it is complete.
   if (!is_regeneration &&
       build_settings->ninja_required_version() >= Version{1, 10, 0}) {
     std::vector<base::FilePath> files_to_restat{
-        base::FilePath(FILE_PATH_LITERAL("build.ninja"))};
+        base::FilePath(FILE_PATH_LITERAL("build.ninja")),
+        base::FilePath(FILE_PATH_LITERAL("build.ninja.stamp")),
+    };
     if (!InvokeNinjaRestatTool(ninja_executable, build_dir, files_to_restat,
                                err)) {
       return false;