OLD | NEW |
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 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 stdout=input_api.subprocess.PIPE, | 1110 stdout=input_api.subprocess.PIPE, |
1111 universal_newlines=True) | 1111 universal_newlines=True) |
1112 (contents, _) = process.communicate(input=contents) | 1112 (contents, _) = process.communicate(input=contents) |
1113 | 1113 |
1114 input_api.json.loads(contents) | 1114 input_api.json.loads(contents) |
1115 except ValueError as e: | 1115 except ValueError as e: |
1116 return e | 1116 return e |
1117 return None | 1117 return None |
1118 | 1118 |
1119 | 1119 |
1120 def _GetIDLParseError(input_api, filename): | |
1121 try: | |
1122 contents = input_api.ReadFile(filename) | |
1123 idl_schema = input_api.os_path.join( | |
1124 input_api.PresubmitLocalPath(), | |
1125 'tools', 'json_schema_compiler', 'idl_schema.py') | |
1126 process = input_api.subprocess.Popen( | |
1127 [input_api.python_executable, idl_schema], | |
1128 stdin=input_api.subprocess.PIPE, | |
1129 stdout=input_api.subprocess.PIPE, | |
1130 stderr=input_api.subprocess.PIPE, | |
1131 universal_newlines=True) | |
1132 (_, error) = process.communicate(input=contents) | |
1133 return error or None | |
1134 except ValueError as e: | |
1135 return e | |
1136 | |
1137 | |
1138 def _CheckParseErrors(input_api, output_api): | 1120 def _CheckParseErrors(input_api, output_api): |
1139 """Check that IDL and JSON files do not contain syntax errors.""" | 1121 """Check that JSON files do not contain syntax errors.""" |
1140 actions = { | 1122 actions = { |
1141 '.idl': _GetIDLParseError, | |
1142 '.json': _GetJSONParseError, | 1123 '.json': _GetJSONParseError, |
1143 } | 1124 } |
1144 # These paths contain test data and other known invalid JSON files. | 1125 # These paths contain test data and other known invalid JSON files. |
1145 excluded_patterns = [ | 1126 excluded_patterns = [ |
1146 r'test[\\\/]data[\\\/]', | 1127 r'test[\\\/]data[\\\/]', |
1147 r'^components[\\\/]policy[\\\/]resources[\\\/]policy_templates\.json$', | 1128 r'^components[\\\/]policy[\\\/]resources[\\\/]policy_templates\.json$', |
1148 ] | 1129 ] |
1149 # Most JSON files are preprocessed and support comments, but these do not. | 1130 # Most JSON files are preprocessed and support comments, but these do not. |
1150 json_no_comments_patterns = [ | 1131 json_no_comments_patterns = [ |
1151 r'^testing[\\\/]', | 1132 r'^testing[\\\/]', |
1152 ] | 1133 ] |
1153 # Only run IDL checker on files in these directories. | |
1154 idl_included_patterns = [ | |
1155 r'^chrome[\\\/]common[\\\/]extensions[\\\/]api[\\\/]', | |
1156 r'^extensions[\\\/]common[\\\/]api[\\\/]', | |
1157 ] | |
1158 | 1134 |
1159 def get_action(affected_file): | 1135 def get_action(affected_file): |
1160 filename = affected_file.LocalPath() | 1136 filename = affected_file.LocalPath() |
1161 return actions.get(input_api.os_path.splitext(filename)[1]) | 1137 return actions.get(input_api.os_path.splitext(filename)[1]) |
1162 | 1138 |
1163 def MatchesFile(patterns, path): | 1139 def MatchesFile(patterns, path): |
1164 for pattern in patterns: | 1140 for pattern in patterns: |
1165 if input_api.re.search(pattern, path): | 1141 if input_api.re.search(pattern, path): |
1166 return True | 1142 return True |
1167 return False | 1143 return False |
1168 | 1144 |
1169 def FilterFile(affected_file): | 1145 def FilterFile(affected_file): |
1170 action = get_action(affected_file) | 1146 action = get_action(affected_file) |
1171 if not action: | 1147 if not action: |
1172 return False | 1148 return False |
1173 path = affected_file.LocalPath() | 1149 path = affected_file.LocalPath() |
1174 | 1150 |
1175 if MatchesFile(excluded_patterns, path): | 1151 if MatchesFile(excluded_patterns, path): |
1176 return False | 1152 return False |
1177 | |
1178 if (action == _GetIDLParseError and | |
1179 not MatchesFile(idl_included_patterns, path)): | |
1180 return False | |
1181 return True | 1153 return True |
1182 | 1154 |
1183 results = [] | 1155 results = [] |
1184 for affected_file in input_api.AffectedFiles( | 1156 for affected_file in input_api.AffectedFiles( |
1185 file_filter=FilterFile, include_deletes=False): | 1157 file_filter=FilterFile, include_deletes=False): |
1186 action = get_action(affected_file) | 1158 action = get_action(affected_file) |
1187 kwargs = {} | 1159 kwargs = {} |
1188 if (action == _GetJSONParseError and | 1160 if (action == _GetJSONParseError and |
1189 MatchesFile(json_no_comments_patterns, affected_file.LocalPath())): | 1161 MatchesFile(json_no_comments_patterns, affected_file.LocalPath())): |
1190 kwargs['eat_comments'] = False | 1162 kwargs['eat_comments'] = False |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 builders.extend(['cros_x86']) | 1698 builders.extend(['cros_x86']) |
1727 | 1699 |
1728 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1700 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
1729 # unless they're .gyp(i) files as changes to those files can break the gyp | 1701 # unless they're .gyp(i) files as changes to those files can break the gyp |
1730 # step on that bot. | 1702 # step on that bot. |
1731 if (not all(re.search('^chrome', f) for f in files) or | 1703 if (not all(re.search('^chrome', f) for f in files) or |
1732 any(re.search('\.gypi?$', f) for f in files)): | 1704 any(re.search('\.gypi?$', f) for f in files)): |
1733 builders.extend(['android_aosp']) | 1705 builders.extend(['android_aosp']) |
1734 | 1706 |
1735 return GetDefaultTryConfigs(builders) | 1707 return GetDefaultTryConfigs(builders) |
OLD | NEW |