OLD | NEW |
---|---|
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 |
11 import imp | 11 import imp |
12 import os | 12 import os |
13 import os.path | |
14 import re | |
13 import scm | 15 import scm |
14 import subprocess | 16 import subprocess |
15 import tempfile | 17 import tempfile |
16 | 18 |
17 def _CheckBuildStatus(input_api, output_api): | 19 def _CheckBuildStatus(input_api, output_api): |
18 results = [] | 20 results = [] |
19 status_check = input_api.canned_checks.CheckTreeIsOpen( | 21 status_check = input_api.canned_checks.CheckTreeIsOpen( |
20 input_api, | 22 input_api, |
21 output_api, | 23 output_api, |
22 json_url='http://dart-status.appspot.com/current?format=json') | 24 json_url='http://dart-status.appspot.com/current?format=json') |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 unformatted_files.append(filename) | 91 unformatted_files.append(filename) |
90 | 92 |
91 if unformatted_files: | 93 if unformatted_files: |
92 return [output_api.PresubmitError( | 94 return [output_api.PresubmitError( |
93 'File output does not match dartfmt.\n' | 95 'File output does not match dartfmt.\n' |
94 'Fix these issues with:\n' | 96 'Fix these issues with:\n' |
95 '%s -w \\\n%s' % (prebuilt_dartfmt, ' \\\n'.join(unformatted_files)))] | 97 '%s -w \\\n%s' % (prebuilt_dartfmt, ' \\\n'.join(unformatted_files)))] |
96 | 98 |
97 return [] | 99 return [] |
98 | 100 |
101 def _CheckNewTests(input_api, output_api): | |
102 testsDirectories = [ | |
103 # Dart 1 tests Dart 2.0 tests | |
Bob Nystrom
2017/07/17 20:38:23
I would say "DDC tests" instead of "Dart 2.0", sin
terry
2017/07/18 13:48:49
Done.
| |
104 # ================= ========================== | |
105 ("tests/language/", "tests/language_strong/"), | |
106 ("tests/corelib/", "tests/corelib_strong/"), | |
107 ("tests/lib/", "tests/lib_strong/"), | |
108 ("tests/html/", "tests/lib_strong/html/"), | |
109 ] | |
110 | |
111 result = [] | |
112 old_locations = re.compile('tests/(language|corelib|lib|html|)/.*\.(dart)') | |
113 | |
114 dart1TestsAdded = [] | |
115 strongTestsExists = [] | |
116 for f in input_api.AffectedFiles(): | |
Jacob
2017/07/17 20:16:34
Indentation seems strange. Ident two spaces by def
terry
2017/07/18 13:48:49
Yes didn't notice that the 2 functions have differ
terry
2017/07/18 13:48:49
Acknowledged.
terry
2017/07/18 13:48:50
Done.
| |
117 if old_locations.match(f.LocalPath()): | |
Jacob
2017/07/17 20:16:34
I believe you should be able to match relative to
terry
2017/07/18 13:48:50
Done.
| |
118 if f.Action() == 'A': | |
119 dart1TestsAdded.append(f.LocalPath()) | |
120 elif f.Action() == 'M': | |
121 # Find all modified tests in Dart 1.0 | |
122 filename = f.LocalPath() | |
123 for oldDir, newDir in testsDirectories: | |
124 if filename.find(oldDir) == 0: | |
125 strongTestFilePathAbs = "%s" % \ | |
126 f.AbsoluteLocalPath().replace(oldDir, newDir) | |
127 if os.path.isfile(strongTestFilePathAbs): | |
128 strongTestsExists.append(f.LocalPath().replace(oldDir, | |
129 newDir)) | |
130 | |
131 # Does a Dart 2.0 strong mode test exist if not its a problem. | |
132 missingStrongTestsChange = [] | |
133 for strongTest in strongTestsExists: | |
134 foundStrongTestModified = False | |
135 for f in input_api.AffectedFiles(): | |
136 if f.LocalPath() == strongTest: | |
137 # Found corresponding strong mode test, great. | |
138 foundStrongTestModified = True | |
139 break; | |
Bob Nystrom
2017/07/17 20:38:24
No ";" in Python. :)
terry
2017/07/18 13:48:50
Done.
| |
140 if not foundStrongTestModified: | |
141 missingStrongTestsChange.append(strongTest) | |
142 | |
143 if missingStrongTestsChange: | |
144 errorList = '%s\n'.join(missingStrongTestsChange) | |
145 result.append(output_api.PresubmitError( | |
146 'Error: Test(s) changed in Dart 1.0 must be changed in the Dart 2.0 ' | |
147 'test too.\n' | |
Bob Nystrom
2017/07/17 20:38:23
How about:
"If you change a Dart 1.0 test, you mu
terry
2017/07/18 13:48:50
Done.
| |
148 'Fix tests:\n%s' % errorList)) | |
149 if dart1TestsAdded: | |
150 errorList = '%s\n'.join(dart1TestsAdded) | |
151 result.append(output_api.PresubmitError( | |
152 'Error: New Dart 1.0 test can not be added the test must be added ' | |
Jacob
2017/07/17 20:16:34
maybe remind users where the dart 2.0 test should
Bob Nystrom
2017/07/17 20:38:24
+1.
It will be the same as the DDC path but with
terry
2017/07/18 13:48:49
Done.
| |
153 'only to Dart 2.0:\n' | |
154 'Fix tests:\n%s' % errorList)) | |
155 | |
156 return result | |
157 | |
99 def CheckChangeOnCommit(input_api, output_api): | 158 def CheckChangeOnCommit(input_api, output_api): |
100 return (_CheckBuildStatus(input_api, output_api) + | 159 return (_CheckBuildStatus(input_api, output_api) + |
160 _CheckNewTests(input_api, output_api) + | |
101 _CheckDartFormat(input_api, output_api)) | 161 _CheckDartFormat(input_api, output_api)) |
102 | 162 |
103 def CheckChangeOnUpload(input_api, output_api): | 163 def CheckChangeOnUpload(input_api, output_api): |
104 return _CheckDartFormat(input_api, output_api) | 164 return (_CheckNewTests(input_api, output_api) + |
165 _CheckDartFormat(input_api, output_api)) | |
OLD | NEW |