Chromium Code Reviews| 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 logging | 5 import logging |
| 6 from webkitpy.w3c.local_wpt import LocalWPT | 6 from webkitpy.w3c.local_wpt import LocalWPT |
| 7 from webkitpy.w3c.chromium_wpt import ChromiumWPT | |
| 8 from webkitpy.w3c.chromium_commit import ChromiumCommit | 7 from webkitpy.w3c.chromium_commit import ChromiumCommit |
| 8 from webkitpy.w3c.deps_updater import DepsUpdater | |
| 9 | 9 |
| 10 _log = logging.getLogger(__name__) | 10 _log = logging.getLogger(__name__) |
| 11 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' | |
|
qyearsley
2016/12/16 00:45:17
Nit: Optional: Could add a blank line after `impor
| |
| 11 | 12 |
| 12 | 13 |
| 13 class TestExporter(object): | 14 class TestExporter(object): |
| 14 | 15 |
| 15 def __init__(self, host, wpt_github, dry_run=False): | 16 def __init__(self, host, wpt_github, dry_run=False): |
| 16 self.host = host | 17 self.host = host |
| 17 self.wpt_github = wpt_github | 18 self.wpt_github = wpt_github |
| 18 self.dry_run = dry_run | 19 self.dry_run = dry_run |
| 19 | 20 |
| 20 def run(self): | 21 def run(self): |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 37 _log.info('PR merged!') | 38 _log.info('PR merged!') |
| 38 elif len(pull_requests) > 1: | 39 elif len(pull_requests) > 1: |
| 39 _log.error(pull_requests) | 40 _log.error(pull_requests) |
| 40 # TODO(jeffcarp): Print links to PRs | 41 # TODO(jeffcarp): Print links to PRs |
| 41 raise Exception('More than two in-flight PRs!') | 42 raise Exception('More than two in-flight PRs!') |
| 42 | 43 |
| 43 # Second, look for exportable commits in Chromium | 44 # Second, look for exportable commits in Chromium |
| 44 # At this point, no in-flight PRs should exist | 45 # At this point, no in-flight PRs should exist |
| 45 # If there was an issue merging, it should have errored out | 46 # If there was an issue merging, it should have errored out |
| 46 local_wpt = LocalWPT(self.host, use_github=False) | 47 local_wpt = LocalWPT(self.host, use_github=False) |
| 47 chromium_wpt = ChromiumWPT(self.host) | |
| 48 | 48 |
| 49 # TODO(jeffcarp): have the script running this fetch Chromium origin/mas ter | 49 # TODO(jeffcarp): have the script running this fetch Chromium origin/mas ter |
| 50 # TODO(jeffcarp): move WPT fetch out of its constructor to match planned ChromiumWPT pattern | 50 # TODO(jeffcarp): move WPT fetch out of its constructor to match planned ChromiumWPT pattern |
| 51 | 51 |
| 52 wpt_commit, chromium_commit = local_wpt.most_recent_chromium_commit() | 52 wpt_commit, chromium_commit = local_wpt.most_recent_chromium_commit() |
| 53 assert chromium_commit, 'No Chromium commit found, this is impossible' | 53 assert chromium_commit, 'No Chromium commit found, this is impossible' |
| 54 | 54 |
| 55 wpt_behind_master = local_wpt.commits_behind_master(wpt_commit) | 55 wpt_behind_master = local_wpt.commits_behind_master(wpt_commit) |
| 56 | 56 |
| 57 _log.info('\nLast Chromium export commit in web-platform-tests:') | 57 _log.info('\nLast Chromium export commit in web-platform-tests:') |
| 58 _log.info('web-platform-tests@%s', wpt_commit) | 58 _log.info('web-platform-tests@%s', wpt_commit) |
| 59 _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_mas ter) | 59 _log.info('(%d behind web-platform-tests@origin/master)', wpt_behind_mas ter) |
| 60 | 60 |
| 61 _log.info('\nThe above WPT commit points to the following Chromium commi t:') | 61 _log.info('\nThe above WPT commit points to the following Chromium commi t:') |
| 62 _log.info('chromium@%s', chromium_commit.sha) | 62 _log.info('chromium@%s', chromium_commit.sha) |
| 63 _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behi nd_master()) | 63 _log.info('(%d behind chromium@origin/master)', chromium_commit.num_behi nd_master()) |
| 64 | 64 |
| 65 # TODO(jeffcarp): Have this function return ChromiumCommits | 65 exportable_commits = self.exportable_commits_since(chromium_commit.sha) |
| 66 exportable_commits = chromium_wpt.exportable_commits_since(chromium_comm it.sha) | |
| 67 | 66 |
| 68 if not exportable_commits: | 67 if not exportable_commits: |
| 69 _log.info('No exportable commits found in Chromium, stopping.') | 68 _log.info('No exportable commits found in Chromium, stopping.') |
| 70 return | 69 return |
| 71 | 70 |
| 72 _log.info('Found %d exportable commits in Chromium:', len(exportable_com mits)) | 71 _log.info('Found %d exportable commits in Chromium:', len(exportable_com mits)) |
| 73 for commit in exportable_commits: | 72 for commit in exportable_commits: |
| 74 _log.info('- %s %s', commit, chromium_wpt.subject(commit)) | 73 _log.info('- %s %s', commit, commit.subject()) |
| 75 | 74 |
| 76 outbound_commit = ChromiumCommit(self.host, sha=exportable_commits[0]) | 75 outbound_commit = exportable_commits[0] |
| 77 _log.info('Picking the earliest commit and creating a PR') | 76 _log.info('Picking the earliest commit and creating a PR') |
| 78 _log.info('- %s %s', outbound_commit.sha, outbound_commit.subject()) | 77 _log.info('- %s %s', outbound_commit.sha, outbound_commit.subject()) |
| 79 | 78 |
| 80 patch = outbound_commit.format_patch() | 79 patch = outbound_commit.format_patch() |
| 81 message = outbound_commit.message() | 80 message = outbound_commit.message() |
| 82 | 81 |
| 83 # TODO: now do a test comparison of patch against local WPT | 82 # TODO: now do a test comparison of patch against local WPT |
| 84 | 83 |
| 85 if self.dry_run: | 84 if self.dry_run: |
| 86 _log.info('[dry_run] Stopping before creating PR') | 85 _log.info('[dry_run] Stopping before creating PR') |
| 87 _log.info('\n\n[dry_run] message:') | 86 _log.info('\n\n[dry_run] message:') |
| 88 _log.info(message) | 87 _log.info(message) |
| 89 _log.info('\n\n[dry_run] patch:') | 88 _log.info('\n\n[dry_run] patch:') |
| 90 _log.info(patch) | 89 _log.info(patch) |
| 91 return | 90 return |
| 92 | 91 |
| 93 local_branch_name = local_wpt.create_branch_with_patch(message, patch) | 92 local_branch_name = local_wpt.create_branch_with_patch(message, patch) |
| 94 | 93 |
| 95 response_data = self.wpt_github.create_pr( | 94 response_data = self.wpt_github.create_pr( |
| 96 local_branch_name=local_branch_name, | 95 local_branch_name=local_branch_name, |
| 97 desc_title=outbound_commit.subject(), | 96 desc_title=outbound_commit.subject(), |
| 98 body=outbound_commit.body()) | 97 body=outbound_commit.body()) |
| 99 | 98 |
| 100 _log.info('Create PR response: %s', response_data) | 99 _log.info('Create PR response: %s', response_data) |
| 100 | |
| 101 def exportable_commits_since(self, commit): | |
| 102 """Returns SHAs of exportable commits since `commit` in chronological or der. | |
| 103 | |
| 104 Args: | |
| 105 commit: The SHA of the Chromium commit from which this method will l ook. | |
| 106 """ | |
| 107 toplevel = self.host.executive.run_command([ | |
|
qyearsley
2016/12/16 00:45:17
toplevel is the repo root, right? Is this necessar
jeffcarp
2016/12/16 20:07:10
Yep, I can rename it to repo_root. Is there a clea
| |
| 108 'git', 'rev-parse', '--show-toplevel' | |
| 109 ]).strip() | |
| 110 | |
| 111 commits = self.host.executive.run_command([ | |
| 112 'git', 'rev-list', '{}..HEAD'.format(commit), '--reverse', | |
| 113 '--', toplevel + '/' + CHROMIUM_WPT_DIR | |
| 114 ]).splitlines() | |
| 115 | |
| 116 chromium_commits = [ChromiumCommit(self.host, sha=c) for c in commits] | |
| 117 | |
| 118 def is_exportable(chromium_commit): | |
| 119 message = chromium_commit.message() | |
| 120 return ( | |
| 121 'NOEXPORT=true' not in message | |
| 122 and not message.startswith('Import ') | |
| 123 # TODO(jeffcarp): change this to allow any commit with | |
| 124 # any non-expectation changes to be exportable | |
| 125 and not self._has_expectations(chromium_commit) | |
| 126 ) | |
|
qyearsley
2016/12/16 00:45:17
Doesn't make much of a difference here, but this c
jeffcarp
2016/12/16 20:07:10
It seemed cleaner to have it in here because it's
| |
| 127 | |
| 128 return filter(is_exportable, chromium_commits) | |
| 129 | |
| 130 def _has_expectations(self, chromium_commit): | |
| 131 files = self.host.executive.run_command([ | |
| 132 'git', 'diff-tree', '--no-commit-id', | |
| 133 '--name-only', '-r', chromium_commit.sha | |
| 134 ]).splitlines() | |
| 135 | |
| 136 return any(DepsUpdater.is_baseline(f) for f in files) | |
| OLD | NEW |