blob: e58ab8dbad92b056e7f708f44465e815a228bc7a [file] [log] [blame]
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Utility functions used both when importing and exporting."""
import logging
from webkitpy.w3c.chromium_commit import ChromiumCommit
from webkitpy.w3c.chromium_finder import absolute_chromium_dir
CSS_DEST_NAME = 'csswg-test'
# TODO(qyearsley): This directory should be able to be constructed with
# WebKitFinder and WPT_DEST_NAME, plus the string "external".
CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/external/wpt/'
# Our mirrors of the official w3c repos, which we pull from.
_log = logging.getLogger(__name__)
def exportable_commits_since(chromium_commit_hash, host, local_wpt):
"""Lists exportable commits after a certain point.
chromium_commit_hash: The SHA of the Chromium commit from which this
method will look. This commit is not included in the commits searched.
host: A Host object.
local_wpt: A LocalWPT instance, used to see whether a Chromium commit
can be applied cleanly in the upstream repo.
A list of ChromiumCommit objects for commits that are exportable after
the given commit, in chronological order.
chromium_repo_root = host.executive.run_command([
'git', 'rev-parse', '--show-toplevel'
], cwd=absolute_chromium_dir(host)).strip()
wpt_path = chromium_repo_root + '/' + CHROMIUM_WPT_DIR
commit_range = '{}..HEAD'.format(chromium_commit_hash)
commit_hashes = host.executive.run_command([
'git', 'rev-list', commit_range, '--reverse', '--', wpt_path
], cwd=absolute_chromium_dir(host)).splitlines()
chromium_commits = [ChromiumCommit(host, sha=sha) for sha in commit_hashes]
return [commit for commit in chromium_commits if is_exportable(commit, local_wpt)]
def is_exportable(chromium_commit, local_wpt):
"""Checks whether a given patch is exportable and can be applied."""
patch = chromium_commit.format_patch()
return ('NOEXPORT=true' not in chromium_commit.message() and
not chromium_commit.message().startswith('Import ') and
patch and
local_wpt.test_patch(patch, chromium_commit))