Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 class _WarningEntry(object): | |
|
Dan Beam
2016/02/23 03:15:24
nit: is this better than a dict or a tuple? can t
Devlin
2016/02/23 23:12:39
Tuple yes (I originally had it like that and decid
| |
| 6 def __init__(self, source, extern): | |
| 7 self.source = source | |
| 8 self.extern = extern | |
| 9 | |
|
Dan Beam
2016/02/23 03:15:24
\n\n between file-level globals
Devlin
2016/02/23 23:12:39
Moot
| |
| 10 class ExternsChecker(object): | |
| 11 COMMAND_STUB = str('src/ $ python tools/json_schema_compiler/compiler.py %s ' | |
|
Dan Beam
2016/02/23 03:15:24
nit: prefix with _ (also, STUB seems a bit odd...
Devlin
2016/02/23 23:12:39
I like _COMMAND_TEMPLATE, done.
| |
| 12 '--root=. --generator=externs > %s') | |
| 13 | |
| 14 def __init__(self, input_api, output_api, api_pairs): | |
| 15 self._api_pairs = api_pairs | |
| 16 self._input_api = input_api | |
| 17 self._output_api = output_api | |
| 18 | |
| 19 def _GetCommand(self, source, dest): | |
| 20 return self.COMMAND_STUB % (source, dest) | |
| 21 | |
| 22 def _GetWarningText(self, entries): | |
| 23 if (len(entries) == 1): | |
|
Dan Beam
2016/02/23 03:15:24
if len(entries) == 1:
Devlin
2016/02/23 23:12:39
Done.
| |
| 24 return str('To update the externs, run "%s"' % | |
| 25 self._GetCommand(entries[0].source, entries[0].extern)) | |
| 26 return str('To update the externs, run "%s"' % | |
| 27 self._GetCommand('<source_file>', '<output_file>')) | |
| 28 | |
| 29 def RunChecks(self): | |
| 30 bad_files = [] | |
| 31 affected = [f.LocalPath() for f in self._input_api.AffectedFiles()] | |
| 32 for path in affected: | |
| 33 pair = self._api_pairs.get(path) | |
| 34 if pair != None and pair not in affected: | |
| 35 bad_files.append(_WarningEntry(path, pair)) | |
| 36 results = [] | |
| 37 if len(bad_files) > 0: | |
|
Dan Beam
2016/02/23 03:15:24
nit: if bad_files:
Devlin
2016/02/23 23:12:39
Ah, right, done.
| |
| 38 results.append(self._output_api.PresubmitPromptWarning( | |
| 39 str('Found updated extension api files without updated extern files. ' | |
| 40 'Please update the extern files.'), | |
| 41 [f.source for f in bad_files], | |
| 42 self._GetWarningText(bad_files))) | |
| 43 return results | |
| OLD | NEW |