| 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 from webkitpy.common.memoized import memoized | 5 from webkitpy.w3c.chromium_finder import absolute_chromium_dir, absolute_chromiu
m_wpt_dir |
| 6 from webkitpy.common.webkit_finder import WebKitFinder | |
| 7 | 6 |
| 8 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/external/wpt/' | 7 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/external/wpt/' |
| 9 | 8 |
| 10 | 9 |
| 11 class ChromiumCommit(object): | 10 class ChromiumCommit(object): |
| 12 | 11 |
| 13 def __init__(self, host, sha=None, position=None): | 12 def __init__(self, host, sha=None, position=None): |
| 14 """ | 13 """ |
| 15 Args: | 14 Args: |
| 16 host: A Host object | 15 host: A Host object |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 if position and not sha: | 27 if position and not sha: |
| 29 if position.startswith('Cr-Commit-Position: '): | 28 if position.startswith('Cr-Commit-Position: '): |
| 30 position = position[len('Cr-Commit-Position: '):] | 29 position = position[len('Cr-Commit-Position: '):] |
| 31 | 30 |
| 32 sha = self.position_to_sha(position) | 31 sha = self.position_to_sha(position) |
| 33 | 32 |
| 34 assert len(sha) == 40, 'Expected SHA-1 hash, got {}'.format(sha) | 33 assert len(sha) == 40, 'Expected SHA-1 hash, got {}'.format(sha) |
| 35 self.sha = sha | 34 self.sha = sha |
| 36 self.position = position | 35 self.position = position |
| 37 | 36 |
| 37 self.absolute_chromium_dir = absolute_chromium_dir(host) |
| 38 self.absolute_chromium_wpt_dir = absolute_chromium_wpt_dir(host) |
| 39 |
| 38 def num_behind_master(self): | 40 def num_behind_master(self): |
| 39 """Returns the number of commits this commit is behind origin/master. | 41 """Returns the number of commits this commit is behind origin/master. |
| 40 It is inclusive of this commit and of the latest commit. | 42 It is inclusive of this commit and of the latest commit. |
| 41 """ | 43 """ |
| 42 return len(self.host.executive.run_command([ | 44 return len(self.host.executive.run_command([ |
| 43 'git', 'rev-list', '{}..origin/master'.format(self.sha) | 45 'git', 'rev-list', '{}..origin/master'.format(self.sha) |
| 44 ], cwd=self.absolute_chromium_dir()).splitlines()) | 46 ], cwd=self.absolute_chromium_dir).splitlines()) |
| 45 | 47 |
| 46 def position_to_sha(self, commit_position): | 48 def position_to_sha(self, commit_position): |
| 47 return self.host.executive.run_command([ | 49 return self.host.executive.run_command([ |
| 48 'git', 'crrev-parse', commit_position | 50 'git', 'crrev-parse', commit_position |
| 49 ], cwd=self.absolute_chromium_dir()).strip() | 51 ], cwd=absolute_chromium_dir).strip() |
| 50 | 52 |
| 51 def subject(self): | 53 def subject(self): |
| 52 return self.host.executive.run_command([ | 54 return self.host.executive.run_command([ |
| 53 'git', 'show', '--format=%s', '--no-patch', self.sha | 55 'git', 'show', '--format=%s', '--no-patch', self.sha |
| 54 ], cwd=self.absolute_chromium_dir()) | 56 ], cwd=self.absolute_chromium_dir) |
| 55 | 57 |
| 56 def body(self): | 58 def body(self): |
| 57 return self.host.executive.run_command([ | 59 return self.host.executive.run_command([ |
| 58 'git', 'show', '--format=%b', '--no-patch', self.sha | 60 'git', 'show', '--format=%b', '--no-patch', self.sha |
| 59 ], cwd=self.absolute_chromium_dir()) | 61 ], cwd=absolute_chromium_dir) |
| 60 | 62 |
| 61 def author(self): | 63 def author(self): |
| 62 return self.host.executive.run_command([ | 64 return self.host.executive.run_command([ |
| 63 'git', 'show', '--format="%aN <%aE>"', '--no-patch', self.sha | 65 'git', 'show', '--format="%aN <%aE>"', '--no-patch', self.sha |
| 64 ], cwd=self.absolute_chromium_dir()) | 66 ], cwd=self.absolute_chromium_dir) |
| 65 | 67 |
| 66 def message(self): | 68 def message(self): |
| 67 """Returns a string with a commit's subject and body.""" | 69 """Returns a string with a commit's subject and body.""" |
| 68 return self.host.executive.run_command([ | 70 return self.host.executive.run_command([ |
| 69 'git', 'show', '--format=%B', '--no-patch', self.sha | 71 'git', 'show', '--format=%B', '--no-patch', self.sha |
| 70 ], cwd=self.absolute_chromium_dir()) | 72 ], cwd=self.absolute_chromium_dir) |
| 71 | 73 |
| 72 def filtered_changed_files(self): | 74 def filtered_changed_files(self): |
| 73 """Makes a patch with just changes in files in the WPT dir for a given c
ommit.""" | 75 """Makes a patch with just changes in files in the WPT dir for a given c
ommit.""" |
| 74 changed_files = self.host.executive.run_command([ | 76 changed_files = self.host.executive.run_command([ |
| 75 'git', 'diff-tree', '--name-only', '--no-commit-id', '-r', self.sha, | 77 'git', 'diff-tree', '--name-only', '--no-commit-id', '-r', self.sha, |
| 76 '--', self.absolute_chromium_wpt_dir() | 78 '--', self.absolute_chromium_wpt_dir |
| 77 ], cwd=self.absolute_chromium_dir()).splitlines() | 79 ], cwd=self.absolute_chromium_dir).splitlines() |
| 78 | 80 |
| 79 blacklist = [ | 81 blacklist = [ |
| 80 'MANIFEST.json', | 82 'MANIFEST.json', |
| 81 self.host.filesystem.join('resources', 'testharnessreport.js'), | 83 self.host.filesystem.join('resources', 'testharnessreport.js'), |
| 82 ] | 84 ] |
| 83 qualified_blacklist = [CHROMIUM_WPT_DIR + f for f in blacklist] | 85 qualified_blacklist = [CHROMIUM_WPT_DIR + f for f in blacklist] |
| 84 | 86 |
| 85 return [f for f in changed_files if f not in qualified_blacklist and not
self.is_baseline(f)] | 87 return [f for f in changed_files if f not in qualified_blacklist and not
self.is_baseline(f)] |
| 86 | 88 |
| 87 @staticmethod | 89 @staticmethod |
| 88 def is_baseline(basename): | 90 def is_baseline(basename): |
| 89 # TODO(qyearsley): Find a better, centralized place for this. | 91 # TODO(qyearsley): Find a better, centralized place for this. |
| 90 return basename.endswith('-expected.txt') | 92 return basename.endswith('-expected.txt') |
| 91 | 93 |
| 92 def format_patch(self): | 94 def format_patch(self): |
| 93 """Makes a patch with only exportable changes.""" | 95 """Makes a patch with only exportable changes.""" |
| 94 filtered_files = self.filtered_changed_files() | 96 filtered_files = self.filtered_changed_files() |
| 95 | 97 |
| 96 if not filtered_files: | 98 if not filtered_files: |
| 97 return '' | 99 return '' |
| 98 | 100 |
| 99 return self.host.executive.run_command([ | 101 return self.host.executive.run_command([ |
| 100 'git', 'format-patch', '-1', '--stdout', self.sha, '--' | 102 'git', 'format-patch', '-1', '--stdout', self.sha, '--' |
| 101 ] + filtered_files, cwd=self.absolute_chromium_dir()) | 103 ] + filtered_files, cwd=self.absolute_chromium_dir) |
| 102 | |
| 103 @memoized | |
| 104 def absolute_chromium_wpt_dir(self): | |
| 105 finder = WebKitFinder(self.host.filesystem) | |
| 106 return finder.path_from_webkit_base('LayoutTests', 'external', 'wpt') | |
| 107 | |
| 108 @memoized | |
| 109 def absolute_chromium_dir(self): | |
| 110 finder = WebKitFinder(self.host.filesystem) | |
| 111 return finder.chromium_base() | |
| OLD | NEW |