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

Side by Side Diff: PRESUBMIT.py

Issue 258473002: Add simple PRESUBMIT check to ensure that all files ending with .json can (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: fix comments Created 6 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for Chromium. 5 """Top-level presubmit script for Chromium.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl. 8 for more details about the presubmit API built into gcl.
9 """ 9 """
10 10
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 action = 'name="{0}"'.format(action_name) 1055 action = 'name="{0}"'.format(action_name)
1056 if action not in current_actions: 1056 if action not in current_actions:
1057 return [output_api.PresubmitPromptWarning( 1057 return [output_api.PresubmitPromptWarning(
1058 'File %s line %d: %s is missing in ' 1058 'File %s line %d: %s is missing in '
1059 'tools/metrics/actions/actions.xml. Please run ' 1059 'tools/metrics/actions/actions.xml. Please run '
1060 'tools/metrics/actions/extract_actions.py to update.' 1060 'tools/metrics/actions/extract_actions.py to update.'
1061 % (f.LocalPath(), line_num, action_name))] 1061 % (f.LocalPath(), line_num, action_name))]
1062 return [] 1062 return []
1063 1063
1064 1064
1065 def _CheckJSONParsability(input_api, output_api):
1066 results = []
1067 file_filter = lambda f: f.LocalPath().endswith('.json')
1068 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1069 with open(fpath.LocalPath(), 'r') as f:
1070 try:
1071 input_api.json.load(f)
1072 except ValueError:
1073 results.append(output_api.PresubmitError(
1074 "File %r does not parse as valid JSON" % (fpath.LocalPath())
1075 ))
1076 return results
1077
1078
1065 def _CheckJavaStyle(input_api, output_api): 1079 def _CheckJavaStyle(input_api, output_api):
1066 """Runs checkstyle on changed java files and returns errors if any exist.""" 1080 """Runs checkstyle on changed java files and returns errors if any exist."""
1067 original_sys_path = sys.path 1081 original_sys_path = sys.path
1068 try: 1082 try:
1069 sys.path = sys.path + [input_api.os_path.join( 1083 sys.path = sys.path + [input_api.os_path.join(
1070 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] 1084 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1071 import checkstyle 1085 import checkstyle
1072 finally: 1086 finally:
1073 # Restore sys.path to what it was before. 1087 # Restore sys.path to what it was before.
1074 sys.path = original_sys_path 1088 sys.path = original_sys_path
(...skipping 30 matching lines...) Expand all
1105 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) 1119 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
1106 results.extend( 1120 results.extend(
1107 input_api.canned_checks.CheckChangeHasNoTabs( 1121 input_api.canned_checks.CheckChangeHasNoTabs(
1108 input_api, 1122 input_api,
1109 output_api, 1123 output_api,
1110 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) 1124 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1111 results.extend(_CheckSpamLogging(input_api, output_api)) 1125 results.extend(_CheckSpamLogging(input_api, output_api))
1112 results.extend(_CheckForAnonymousVariables(input_api, output_api)) 1126 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1113 results.extend(_CheckCygwinShell(input_api, output_api)) 1127 results.extend(_CheckCygwinShell(input_api, output_api))
1114 results.extend(_CheckUserActionUpdate(input_api, output_api)) 1128 results.extend(_CheckUserActionUpdate(input_api, output_api))
1129 results.extend(_CheckJSONParsability(input_api, output_api))
1115 1130
1116 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): 1131 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1117 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( 1132 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1118 input_api, output_api, 1133 input_api, output_api,
1119 input_api.PresubmitLocalPath(), 1134 input_api.PresubmitLocalPath(),
1120 whitelist=[r'^PRESUBMIT_test\.py$'])) 1135 whitelist=[r'^PRESUBMIT_test\.py$']))
1121 return results 1136 return results
1122 1137
1123 1138
1124 def _CheckSubversionConfig(input_api, output_api): 1139 def _CheckSubversionConfig(input_api, output_api):
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 builders.extend(['cros_x86']) 1509 builders.extend(['cros_x86'])
1495 1510
1496 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it 1511 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1497 # unless they're .gyp(i) files as changes to those files can break the gyp 1512 # unless they're .gyp(i) files as changes to those files can break the gyp
1498 # step on that bot. 1513 # step on that bot.
1499 if (not all(re.search('^chrome', f) for f in files) or 1514 if (not all(re.search('^chrome', f) for f in files) or
1500 any(re.search('\.gypi?$', f) for f in files)): 1515 any(re.search('\.gypi?$', f) for f in files)):
1501 builders.extend(['android_aosp']) 1516 builders.extend(['android_aosp'])
1502 1517
1503 return GetDefaultTryConfigs(builders) 1518 return GetDefaultTryConfigs(builders)
OLDNEW
« 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