Support checking and fixing non-existing header files in GN

BUG=716359

Review-Url: https://codereview.chromium.org/2846593007
Cr-Commit-Position: refs/heads/master@{#468230}
diff --git a/build/check_gn_headers.py b/build/check_gn_headers.py
index 73f1593..0850196e 100755
--- a/build/check_gn_headers.py
+++ b/build/check_gn_headers.py
@@ -112,6 +112,18 @@
   return out
 
 
+def FilterOutDepsedRepo(files, deps):
+  return {f for f in files if not any(f.startswith(d) for d in deps)}
+
+
+def GetNonExistingFiles(lst):
+  out = set()
+  for f in lst:
+    if not os.path.isfile(f):
+      out.add(f)
+  return out
+
+
 def main():
   parser = argparse.ArgumentParser()
   parser.add_argument('--out-dir', default='out/Release')
@@ -134,11 +146,15 @@
   deps_p.start()
 
   d = d_q.get()
+  assert len(GetNonExistingFiles(d)) == 0, \
+      'Found non-existing files in ninja deps'
   gn = gn_q.get()
   missing = d - gn
+  nonexisting = GetNonExistingFiles(gn)
 
   deps = deps_q.get()
-  missing = {m for m in missing if not any(m.startswith(d) for d in deps)}
+  missing = FilterOutDepsedRepo(missing, deps)
+  nonexisting = FilterOutDepsedRepo(nonexisting, deps)
 
   d_p.join()
   gn_p.join()
@@ -149,17 +165,25 @@
     missing -= whitelist
 
   missing = sorted(missing)
+  nonexisting = sorted(nonexisting)
 
   if args.json:
     with open(args.json, 'w') as f:
       json.dump(missing, f)
 
-  if len(missing) == 0:
+  if len(missing) == 0 and len(nonexisting) == 0:
     return 0
 
-  print 'The following files should be included in gn files:'
-  for i in missing:
-    print i
+  if len(missing) > 0:
+    print '\nThe following files should be included in gn files:'
+    for i in missing:
+      print i
+
+  if len(nonexisting) > 0:
+    print '\nThe following non-existing files should be removed from gn files:'
+    for i in nonexisting:
+      print i
+
   return 1