Do not remove build.ninja.d during `gn clean` Calling `gn clean` would remove the `build.ninja.d` file unexpectedly, which resulted in the nexty `gn clean` call to fail with a "This does not look like a build directory" error. The reason for this is a recent change [1] which modified how the dummy `build.ninja` and `build.ninja.d` files generated by `gn clean` (to force a regeneration on the next Ninja invocation) are written: - Before the CL, the code removed everything except `args.gn`, then wrote the dummy `build.ninja` and `build.ninja.d`. - After the CL, the code wrote `build.ninja` and `build.ninja.d`, then removed everything except `args.gn` and `build.ninja` (this removing the just-written `build.ninja.d` file). This fixes the issue by ensuring that `build.ninja.d` is not removed. Moreover, this relaxes the build directory check logic a little, by accepting a directory that only contains an `args.gn` file, without a `build.ninja.d` file in it. [1] https://gn-review.googlesource.com/c/gn/+/14200 Bug: None Change-Id: Ie06ab751bed5a749a63bf200b50424abdcf0fdcf Reviewed-on: https://gn-review.googlesource.com/c/gn/+/14500 Reviewed-by: Takuto Ikuta <tikuta@google.com> Commit-Queue: David Turner <digit@google.com> Reviewed-by: Petr Hosek <phosek@google.com>
diff --git a/src/gn/command_clean.cc b/src/gn/command_clean.cc index e6c52fc..6dcc163 100644 --- a/src/gn/command_clean.cc +++ b/src/gn/command_clean.cc
@@ -24,10 +24,12 @@ base::FilePath build_dir(setup->build_settings().GetFullPath( SourceDir(setup->build_settings().build_dir().value()))); - // NOTE: Not all GN builds have args.gn file hence we check here + // NOTE: Not all GN builds have args.gn file hence we also check here // if a build.ninja.d files exists instead. + base::FilePath args_gn_file = build_dir.AppendASCII("args.gn"); base::FilePath build_ninja_d_file = build_dir.AppendASCII("build.ninja.d"); - if (!base::PathExists(build_ninja_d_file)) { + if (!base::PathExists(args_gn_file) && + !base::PathExists(build_ninja_d_file)) { Err(Location(), base::StringPrintf( "%s does not look like a build directory.\n", @@ -42,10 +44,13 @@ return false; } - // Erase everything but (user-created) args.gn and the build.ninja we just - // wrote. - const base::FilePath::CharType* remaining[]{FILE_PATH_LITERAL("args.gn"), - FILE_PATH_LITERAL("build.ninja")}; + // Erase everything but (user-created) args.gn and the build.ninja files we + // just wrote. + const base::FilePath::CharType* remaining[]{ + FILE_PATH_LITERAL("args.gn"), + FILE_PATH_LITERAL("build.ninja"), + FILE_PATH_LITERAL("build.ninja.d"), + }; base::FileEnumerator traversal( build_dir, false, base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES);