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

Unified Diff: PRESUBMIT.py

Issue 2278093004: Reland [Presubmit tests] Warn when new source files are not added to GN/GYPi files. (Closed)
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 e2e042336926e54a01f47dd33769c9a534c7c92c..310091e538370de4ed866daddb207ab714bd20e1 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1946,6 +1946,52 @@ def _AndroidSpecificOnUploadChecks(input_api, output_api):
results.extend(_CheckAndroidToastUsage(input_api, output_api))
return results
+def _CheckNewSourceFileAddedToGnGypi(input_api, output_api):
+ """Checks new source code files were added to GN/GYPi files"""
+ new_source_files = []
+ gn_gypi_files = []
+
+ """ Get lists of new source code files and GN/GYPi files in the commit"""
+ for f in input_api.AffectedFiles():
+ if f.LocalPath().endswith(('.gn', '.gypi')):
+ gn_gypi_files.append(f)
+ continue
+ if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm', '.java')):
+ if f.Action() == 'A':
+ new_source_files.append(f.LocalPath())
+
+ if not new_source_files:
+ return []
+
+ if not gn_gypi_files:
+ return [output_api.PresubmitPromptWarning('The following new'
+ ' source code files must be added to GN/GYPI files:\n ' +
+ '\n '.join(new_source_files))]
+
+ """Get a list of new source code files that CAN BE FOUND in the GN/GYPI
+ files"""
+ source_files_listed = []
+ for f in new_source_files:
+ head, sep, tail = f.rpartition('/')
+ source_file_match_pattern = tail
+ for g in gn_gypi_files:
+ for line in g.GenerateScmDiff().splitlines():
+ if line.endswith((source_file_match_pattern + '",',
+ source_file_match_pattern + '\',')):
+ source_files_listed.append(f)
+ 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)
+
+ if new_source_files:
+ return [output_api.PresubmitPromptWarning('The following new'
+ ' source code files must be added to GN/GYPI files:\n ' +
+ '\n '.join(new_source_files))]
+
+ return []
def _CommonChecks(input_api, output_api):
"""Checks common to both upload and commit."""
@@ -2208,6 +2254,7 @@ def CheckChangeOnUpload(input_api, output_api):
input_api.canned_checks.CheckGNFormatted(input_api, output_api))
results.extend(_CheckUmaHistogramChanges(input_api, output_api))
results.extend(_AndroidSpecificOnUploadChecks(input_api, output_api))
+ results.extend(_CheckNewSourceFileAddedToGnGypi(input_api, output_api))
return results
« 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