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

Unified Diff: PRESUBMIT.py

Issue 2872493002: Adding PRESUBMIT check on orphan headers files. (Closed)
Patch Set: adding shebang line Created 3 years, 7 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 | tools_webrtc/presubmit_checks_lib/check_orphan_headers.py » ('j') | 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 694624e56d042ac395a122aec8ad67deb1edca44..e13c9a05a4611940ff7f0a9578fe128847bd8a24 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -575,6 +575,7 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckJSONParseErrors(input_api, output_api))
results.extend(_RunPythonTests(input_api, output_api))
results.extend(_CheckUsageOfGoogleProtobufNamespace(input_api, output_api))
+ results.extend(_CheckOrphanHeaders(input_api, output_api))
return results
@@ -602,3 +603,33 @@ def CheckChangeOnCommit(input_api, output_api):
input_api, output_api,
json_url='http://webrtc-status.appspot.com/current?format=json'))
return results
+
+
+def _CheckOrphanHeaders(input_api, output_api):
+ # We need to wait until we have an input_api object and use this
+ # roundabout construct to import prebubmit_checks_lib because this file is
+ # eval-ed and thus doesn't have __file__.
+ error_msg = """Header file {} is not listed in any GN target.
+ Please create a target or add it to an existing one in {}"""
+ results = []
+ original_sys_path = sys.path
+ try:
+ sys.path = sys.path + [input_api.os_path.join(
+ input_api.PresubmitLocalPath(), 'tools_webrtc', 'presubmit_checks_lib')]
+ from check_orphan_headers import GetBuildGnPathFromFilePath
+ from check_orphan_headers import IsHeaderInBuildGn
+ finally:
+ # Restore sys.path to what it was before.
+ sys.path = original_sys_path
+
+ for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
+ if f.LocalPath().endswith('.h'):
+ file_path = os.path.abspath(f.LocalPath())
+ root_dir = os.getcwd()
+ gn_file_path = GetBuildGnPathFromFilePath(file_path, os.path.exists,
+ root_dir)
+ in_build_gn = IsHeaderInBuildGn(file_path, gn_file_path)
+ if not in_build_gn:
+ results.append(output_api.PresubmitError(error_msg.format(
+ file_path, gn_file_path)))
+ return results
« no previous file with comments | « no previous file | tools_webrtc/presubmit_checks_lib/check_orphan_headers.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698