OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 class ExternsChecker(object): | 5 class ExternsChecker(object): |
6 _UPDATE_MESSAGE = """To update the externs, run: | 6 _UPDATE_MESSAGE = """To update the externs, run: |
7 src/ $ python tools/json_schema_compiler/compiler.py\ | 7 src/ $ python tools/json_schema_compiler/compiler.py\ |
8 %s --root=. --generator=externs > %s""" | 8 %s --root=. --generator=externs > %s""" |
9 | 9 |
10 def __init__(self, input_api, output_api, api_pairs): | 10 def __init__(self, input_api, output_api, api_pairs): |
11 self._input_api = input_api | 11 self._input_api = input_api |
12 self._output_api = output_api | 12 self._output_api = output_api |
13 self._api_pairs = api_pairs | 13 self._api_pairs = api_pairs |
14 | 14 |
15 for path in api_pairs.keys() + api_pairs.values(): | 15 for path in api_pairs.keys() + api_pairs.values(): |
16 if not input_api.os_path.exists(path): | 16 if not input_api.os_path.exists(path): |
17 raise OSError('Path Not Found: %s' % path) | 17 raise OSError('Path Not Found: %s' % path) |
18 | 18 |
19 def RunChecks(self): | 19 def RunChecks(self): |
20 bad_files = [] | 20 bad_files = [] |
21 affected = [f.AbsoluteLocalPath() for f in self._input_api.AffectedFiles()] | 21 affected = [f.AbsoluteLocalPath() for f in |
| 22 self._input_api.change.AffectedFiles()] |
22 for path in affected: | 23 for path in affected: |
23 pair = self._api_pairs.get(path) | 24 pair = self._api_pairs.get(path) |
24 if pair != None and pair not in affected: | 25 if pair != None and pair not in affected: |
25 bad_files.append({'source': path, 'extern': pair}) | 26 bad_files.append({'source': path, 'extern': pair}) |
26 results = [] | 27 results = [] |
27 if bad_files: | 28 if bad_files: |
28 replacements = (('<source_file>', '<output_file>') if len(bad_files) > 1 | 29 replacements = (('<source_file>', '<output_file>') if len(bad_files) > 1 |
29 else (bad_files[0]['source'], bad_files[0]['extern'])) | 30 else (bad_files[0]['source'], bad_files[0]['extern'])) |
30 long_text = self._UPDATE_MESSAGE % replacements | 31 long_text = self._UPDATE_MESSAGE % replacements |
31 results.append(self._output_api.PresubmitPromptWarning( | 32 results.append(self._output_api.PresubmitPromptWarning( |
32 str('Found updated extension api files without updated extern files. ' | 33 str('Found updated extension api files without updated extern files. ' |
33 'Please update the extern files.'), | 34 'Please update the extern files.'), |
34 [f['source'] for f in bad_files], | 35 [f['source'] for f in bad_files], |
35 long_text)) | 36 long_text)) |
36 return results | 37 return results |
OLD | NEW |