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

Side by Side Diff: PRESUBMIT.py

Issue 2987883002: Don't treat unparseable files as presubmit dartfmt errors. (Closed)
Patch Set: Created 3 years, 5 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 Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 4
5 """Top-level presubmit script for Dart. 5 """Top-level presubmit script for Dart.
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 24 matching lines...) Expand all
35 windows = utils.GuessOS() == 'win32' 35 windows = utils.GuessOS() == 'win32'
36 if windows: 36 if windows:
37 prebuilt_dartfmt += '.bat' 37 prebuilt_dartfmt += '.bat'
38 38
39 if not os.path.isfile(prebuilt_dartfmt): 39 if not os.path.isfile(prebuilt_dartfmt):
40 print('WARNING: dartfmt not found: %s' % (prebuilt_dartfmt)) 40 print('WARNING: dartfmt not found: %s' % (prebuilt_dartfmt))
41 return [] 41 return []
42 42
43 def HasFormatErrors(filename=None, contents=None): 43 def HasFormatErrors(filename=None, contents=None):
44 args = [prebuilt_dartfmt, '--set-exit-if-changed'] 44 args = [prebuilt_dartfmt, '--set-exit-if-changed']
45 if contents: 45 if not contents:
46 process = subprocess.Popen(args, 46 args += [filename, '-n']
47 stdout=subprocess.PIPE,
48 stdin=subprocess.PIPE
49 )
50 out, err = process.communicate(input=contents)
51 47
52 # There was a bug in the return code dartfmt returns when reading from 48 process = subprocess.Popen(args,
53 # stdin so we have to check whether the content matches rather than using 49 stdout=subprocess.PIPE,
54 # the return code. When the next version of the dartfmt lands in the sdk 50 stdin=subprocess.PIPE
55 # we can switch this line to "return process.returncode != 0" 51 )
56 return out != contents 52 process.communicate(input=contents)
57 else: 53
58 try: 54 # Check for exit code 1 explicitly to distinguish it from a syntax error
59 subprocess.check_output(args + [filename, '-n']) 55 # in the file (exit code 65). The repo contains many Dart files that are
60 except subprocess.CalledProcessError: 56 # known to have syntax errors for testing purposes and which can't be
61 return True 57 # parsed and formatted. Don't treat those as errors.
62 return False 58 return process.returncode == 1
63 59
64 unformatted_files = [] 60 unformatted_files = []
65 for git_file in input_api.AffectedTextFiles(): 61 for git_file in input_api.AffectedTextFiles():
66 filename = git_file.AbsoluteLocalPath() 62 filename = git_file.AbsoluteLocalPath()
67 if filename.endswith('.dart'): 63 if filename.endswith('.dart'):
68 if HasFormatErrors(filename=filename): 64 if HasFormatErrors(filename=filename):
69 old_version_has_errors = False 65 old_version_has_errors = False
70 try: 66 try:
71 path = git_file.LocalPath() 67 path = git_file.LocalPath()
72 if windows: 68 if windows:
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 return result 164 return result
169 165
170 def CheckChangeOnCommit(input_api, output_api): 166 def CheckChangeOnCommit(input_api, output_api):
171 return (_CheckBuildStatus(input_api, output_api) + 167 return (_CheckBuildStatus(input_api, output_api) +
172 _CheckNewTests(input_api, output_api) + 168 _CheckNewTests(input_api, output_api) +
173 _CheckDartFormat(input_api, output_api)) 169 _CheckDartFormat(input_api, output_api))
174 170
175 def CheckChangeOnUpload(input_api, output_api): 171 def CheckChangeOnUpload(input_api, output_api):
176 return (_CheckNewTests(input_api, output_api) + 172 return (_CheckNewTests(input_api, output_api) +
177 _CheckDartFormat(input_api, output_api)) 173 _CheckDartFormat(input_api, output_api))
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