Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index 24eff148e8edd10478aca0c11163d7b303c135fe..11e046eabede6202dc04f4918c47f3541c6458d0 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): |
|
kjellander_webrtc
2017/05/08 18:51:59
Prefix this with _ to show it's an internal functi
mbonadei
2017/05/09 07:31:19
Done.
|
| + # We need to wait until we have an input_api object and use this |
| + # roundabout construct to import prebubmit_checks_lis because this file is |
|
kjellander_webrtc
2017/05/08 18:51:59
prebubmit_checks_lis -> prebubmit_checks_lib
mbonadei
2017/05/09 07:31:19
Done.
|
| + # 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(), '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))) |
|
kjellander_webrtc
2017/05/08 18:51:59
+2 spaces indent to get 4-spaces hanging indent.
mbonadei
2017/05/09 07:31:19
Done.
|
| + return results |