| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 Blink. | 5 """Top-level presubmit script for Blink. |
| 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 |
| 11 import sys |
| 12 |
| 11 | 13 |
| 12 _EXCLUDED_PATHS = () | 14 _EXCLUDED_PATHS = () |
| 13 | 15 |
| 14 | 16 |
| 15 def _CheckForVersionControlConflictsInFile(input_api, f): | 17 def _CheckForVersionControlConflictsInFile(input_api, f): |
| 16 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') | 18 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') |
| 17 errors = [] | 19 errors = [] |
| 18 for line_num, line in f.ChangedContents(): | 20 for line_num, line in f.ChangedContents(): |
| 19 if pattern.match(line): | 21 if pattern.match(line): |
| 20 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) | 22 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 # We should figure out what license checks we actually want to use. | 41 # We should figure out what license checks we actually want to use. |
| 40 license_header = r'.*' | 42 license_header = r'.*' |
| 41 | 43 |
| 42 results = [] | 44 results = [] |
| 43 results.extend(input_api.canned_checks.PanProjectChecks( | 45 results.extend(input_api.canned_checks.PanProjectChecks( |
| 44 input_api, output_api, excluded_paths=_EXCLUDED_PATHS, | 46 input_api, output_api, excluded_paths=_EXCLUDED_PATHS, |
| 45 maxlen=800, license_header=license_header)) | 47 maxlen=800, license_header=license_header)) |
| 46 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) | 48 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) |
| 47 results.extend(_CheckPatchFiles(input_api, output_api)) | 49 results.extend(_CheckPatchFiles(input_api, output_api)) |
| 48 results.extend(_CheckTestExpectations(input_api, output_api)) | 50 results.extend(_CheckTestExpectations(input_api, output_api)) |
| 51 results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
| 49 return results | 52 return results |
| 50 | 53 |
| 51 | 54 |
| 52 def _CheckSubversionConfig(input_api, output_api): | 55 def _CheckSubversionConfig(input_api, output_api): |
| 53 """Verifies the subversion config file is correctly setup. | 56 """Verifies the subversion config file is correctly setup. |
| 54 | 57 |
| 55 Checks that autoprops are enabled, returns an error otherwise. | 58 Checks that autoprops are enabled, returns an error otherwise. |
| 56 """ | 59 """ |
| 57 join = input_api.os_path.join | 60 join = input_api.os_path.join |
| 58 if input_api.platform == 'win32': | 61 if input_api.platform == 'win32': |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if child.returncode != 0: | 138 if child.returncode != 0: |
| 136 results.append(output_api.PresubmitError( | 139 results.append(output_api.PresubmitError( |
| 137 'check-webkit-style failed', [stderrdata])) | 140 'check-webkit-style failed', [stderrdata])) |
| 138 except Exception as e: | 141 except Exception as e: |
| 139 results.append(output_api.PresubmitNotifyResult( | 142 results.append(output_api.PresubmitNotifyResult( |
| 140 'Could not run check-webkit-style', [str(e)])) | 143 'Could not run check-webkit-style', [str(e)])) |
| 141 | 144 |
| 142 return results | 145 return results |
| 143 | 146 |
| 144 | 147 |
| 148 def _CheckUnwantedDependencies(input_api, output_api): |
| 149 """Runs checkdeps on #include statements added in this |
| 150 change. Breaking - rules is an error, breaking ! rules is a |
| 151 warning. |
| 152 """ |
| 153 # We need to wait until we have an input_api object and use this |
| 154 # roundabout construct to import checkdeps because this file is |
| 155 # eval-ed and thus doesn't have __file__. |
| 156 original_sys_path = sys.path |
| 157 try: |
| 158 sys.path = sys.path + [input_api.os_path.realpath(input_api.os_path.join
( |
| 159 input_api.PresubmitLocalPath(), '..', '..', 'tools', 'checkdeps'
))] |
| 160 import checkdeps |
| 161 from cpp_checker import CppChecker |
| 162 from rules import Rule |
| 163 finally: |
| 164 # Restore sys.path to what it was before. |
| 165 sys.path = original_sys_path |
| 166 |
| 167 added_includes = [] |
| 168 for f in input_api.AffectedFiles(): |
| 169 if not CppChecker.IsCppFile(f.LocalPath()): |
| 170 continue |
| 171 |
| 172 changed_lines = [line for line_num, line in f.ChangedContents()] |
| 173 added_includes.append([f.LocalPath(), changed_lines]) |
| 174 |
| 175 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
| 176 |
| 177 error_descriptions = [] |
| 178 warning_descriptions = [] |
| 179 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
| 180 added_includes): |
| 181 description_with_path = '%s\n %s' % (path, rule_description) |
| 182 if rule_type == Rule.DISALLOW: |
| 183 error_descriptions.append(description_with_path) |
| 184 else: |
| 185 warning_descriptions.append(description_with_path) |
| 186 |
| 187 results = [] |
| 188 if error_descriptions: |
| 189 results.append(output_api.PresubmitError( |
| 190 'You added one or more #includes that violate checkdeps rules.', |
| 191 error_descriptions)) |
| 192 if warning_descriptions: |
| 193 results.append(output_api.PresubmitPromptOrNotify( |
| 194 'You added one or more #includes of files that are temporarily\n
' |
| 195 'allowed but being removed. Can you avoid introducing the\n' |
| 196 '#include? See relevant DEPS file(s) for details and contacts.', |
| 197 warning_descriptions)) |
| 198 return results |
| 199 |
| 200 |
| 145 def CheckChangeOnUpload(input_api, output_api): | 201 def CheckChangeOnUpload(input_api, output_api): |
| 146 results = [] | 202 results = [] |
| 147 results.extend(_CommonChecks(input_api, output_api)) | 203 results.extend(_CommonChecks(input_api, output_api)) |
| 148 results.extend(_CheckStyle(input_api, output_api)) | 204 results.extend(_CheckStyle(input_api, output_api)) |
| 149 return results | 205 return results |
| 150 | 206 |
| 151 | 207 |
| 152 def CheckChangeOnCommit(input_api, output_api): | 208 def CheckChangeOnCommit(input_api, output_api): |
| 153 results = [] | 209 results = [] |
| 154 results.extend(_CommonChecks(input_api, output_api)) | 210 results.extend(_CommonChecks(input_api, output_api)) |
| 155 results.extend(input_api.canned_checks.CheckTreeIsOpen( | 211 results.extend(input_api.canned_checks.CheckTreeIsOpen( |
| 156 input_api, output_api, | 212 input_api, output_api, |
| 157 json_url='http://blink-status.appspot.com/current?format=json')) | 213 json_url='http://blink-status.appspot.com/current?format=json')) |
| 158 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 214 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 159 input_api, output_api)) | 215 input_api, output_api)) |
| 160 results.extend(_CheckSubversionConfig(input_api, output_api)) | 216 results.extend(_CheckSubversionConfig(input_api, output_api)) |
| 161 return results | 217 return results |
| 162 | 218 |
| 163 def GetPreferredTrySlaves(project, change): | 219 def GetPreferredTrySlaves(project, change): |
| 164 return ['linux_layout_rel', 'mac_layout_rel', 'win_layout_rel'] | 220 return ['linux_layout_rel', 'mac_layout_rel', 'win_layout_rel'] |
| OLD | NEW |