Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: PRESUBMIT.py

Issue 2252043004: [Presubmit tests] Warn when new source files are not added to GN/GYPi files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698