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 import os.path | |
6 import time | |
7 | 5 |
8 def CheckChangeOnUpload(input_api, output_api): | 6 def CheckChangeOnUpload(input_api, output_api): |
9 """Warn when changing md_history without vulcanizing.""" | 7 """Warn when changing md_history without vulcanizing.""" |
10 | 8 |
11 def _is_md_history_file(path): | 9 def _is_history_source_file(file): |
12 return (path.startswith('chrome/browser/resources/md_history') and | 10 path = file.LocalPath() |
13 (not path.endswith('externs.js')) and | 11 return (not path.endswith('externs.js') and |
14 (not path.endswith('crisper.js')) and | 12 not path.endswith('crisper.js') and |
15 (not path.endswith('vulcanized.html')) and | 13 not path.endswith('vulcanized.html') and |
16 (path.endswith('js') or path.endswith('html'))) | 14 (path.endswith('.js') or path.endswith('.html'))) |
17 | 15 |
18 paths = [x.LocalPath() for x in input_api.change.AffectedFiles()] | 16 os_path = input_api.os_path |
19 earliest_vulcanize_change = min(os.path.getmtime(x) for x in | 17 earliest_vulcanize_change = min(os_path.getmtime(x) for x in |
20 ['app.vulcanized.html', | 18 ['app.vulcanized.html', |
21 'app.crisper.js', | 19 'app.crisper.js', |
22 'lazy_load.vulcanized.html', | 20 'lazy_load.vulcanized.html', |
23 'lazy_load.crisper.js']) | 21 'lazy_load.crisper.js']) |
24 history_changes = filter(_is_md_history_file, paths) | 22 |
| 23 source_files = input_api.AffectedFiles(file_filter=_is_history_source_file) |
25 latest_history_change = 0 | 24 latest_history_change = 0 |
26 if history_changes: | 25 if source_files: |
27 latest_history_change = max(os.path.getmtime(os.path.split(x)[1]) for x in | 26 latest_history_change = max( |
28 history_changes) | 27 os_path.getmtime(os_path.basename(f.LocalPath())) for f in source_files) |
29 | 28 |
30 if latest_history_change > earliest_vulcanize_change: | 29 if latest_history_change > earliest_vulcanize_change: |
31 return [output_api.PresubmitPromptWarning( | 30 return [output_api.PresubmitPromptWarning( |
32 'Vulcanize must be run when changing files in md_history. See ' | 31 'Vulcanize must be run when changing files in md_history. See ' |
33 'docs/vulcanize.md.')] | 32 'docs/vulcanize.md.')] |
34 return [] | 33 return [] |
OLD | NEW |