Index: PRESUBMIT.py |
diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
index fde5a12f590ee156633047c944e71ceb546280b9..0c6562daceb9bd1baa3bbc641e7c6bdf2317b745 100644 |
--- a/PRESUBMIT.py |
+++ b/PRESUBMIT.py |
@@ -1944,6 +1944,52 @@ def _AndroidSpecificOnUploadChecks(input_api, output_api): |
results.extend(_CheckAndroidToastUsage(input_api, output_api)) |
return results |
+def _CheckNewSourceFileAddedToGn(input_api, output_api): |
+ """Checks new source code files were added to GN files""" |
+ new_source_files = [] |
+ gn_files = [] |
+ |
+ """ Get lists of new source code files and GN files in the commit""" |
+ for f in input_api.AffectedFiles(): |
+ if f.LocalPath().endswith('.gn'): |
+ gn_files.append(f) |
+ continue |
+ if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm', '.java')): |
+ for line in f.GenerateScmDiff().splitlines(): |
+ if line.startswith('@@ -0,0'): |
Dirk Pranke
2016/08/19 20:42:02
You don't need to look at the diff.
f.Action() r
maksims (do not use this acc)
2016/08/23 06:00:18
Done.
|
+ new_source_files.append(f.LocalPath()) |
+ break |
+ |
+ if not new_source_files: |
+ return [] |
+ |
+ if not gn_files: |
Dirk Pranke
2016/08/19 20:42:02
Eventually something like this'll be the right che
maksims (do not use this acc)
2016/08/23 06:00:18
Done.
|
+ return [output_api.PresubmitPromptWarning('The following new' |
+ ' source code files must be added to GN files:\n ' + |
+ '\n '.join(new_source_files))] |
+ |
+ """Get a list of new source code files that CAN BE FOUND in the GN files""" |
+ source_files_listed = [] |
+ for ff in new_source_files: |
+ head, sep, tail = ff.partition('/') |
+ if tail: |
+ source_file_match_pattern = tail + '",' |
+ else: |
+ source_file_match_pattern = ff + '",' |
+ for gn in gn_files: |
+ for line in gn.GenerateScmDiff().splitlines(): |
+ if line.endswith(source_file_match_pattern): |
+ source_files_listed.append(ff) |
+ break |
+ |
+ """Remove files, which has been found in the GN files, from the list""" |
+ for f in source_files_listed: |
+ if f in new_source_files: |
+ new_source_files.remove(f) |
+ |
+ return [output_api.PresubmitPromptWarning('The following new' |
+ ' source code files must be added to GN files:\n ' + |
+ '\n '.join(new_source_files))] |
def _CommonChecks(input_api, output_api): |
"""Checks common to both upload and commit.""" |
@@ -1995,6 +2041,7 @@ def _CommonChecks(input_api, output_api): |
results.extend(_CheckJavaStyle(input_api, output_api)) |
results.extend(_CheckIpcOwners(input_api, output_api)) |
results.extend(_CheckMojoUsesNewWrapperTypes(input_api, output_api)) |
+ results.extend(_CheckNewSourceFileAddedToGn(input_api, output_api)) |
if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |