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