def _exportable_commits_since(chromium_commit_hash, host, local_wpt, wpt_github, require_clean=True, verify_merged_pr=False): """Lists exportable commits after the given commit. Args: chromium_commit_hash: The SHA of the Chromium commit from which this method will look. This commit is not included in the commits searched. Return values and remaining arguments are the same as exportable_commits_over_last_n_commits. """ 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) skipped_revs = ['^' + rev for rev in SKIPPED_REVISIONS] command = ['git', 'rev-list', commit_range] + skipped_revs + ['--reverse', '--', wpt_path] commit_hashes = host.executive.run_command(command, cwd=absolute_chromium_dir(host)).splitlines() chromium_commits = [ChromiumCommit(host, sha=sha) for sha in commit_hashes] exportable_commits = [] errors = [] for commit in chromium_commits: state, error = get_commit_export_state(commit, local_wpt, wpt_github, verify_merged_pr) if require_clean: success = state == CommitExportState.EXPORTABLE_CLEAN else: success = state in (CommitExportState.EXPORTABLE_CLEAN, CommitExportState.EXPORTABLE_DIRTY) if success: exportable_commits.append(commit) elif error != '': errors.append('The following commit did not apply cleanly:\nSubject: %s (%s)\n%s' % (commit.subject(), commit.url(), error)) return exportable_commits, errors
def __init__(self, host, sha=None, position=None): """Initializes a ChomiumCommit object, given a sha or commit position. Args: host: A Host object. sha: A Chromium commit SHA hash. position: A commit position footer string of the form: 'Cr-Commit-Position: refs/heads/master@{#431915}' or just the commit position string: 'refs/heads/master@{#431915}' """ self.host = host self.absolute_chromium_dir = absolute_chromium_dir(host) self.absolute_chromium_wpt_dir = absolute_chromium_wpt_dir(host) assert sha or position, 'requires sha or position' assert not (sha and position), 'cannot accept both sha and position' if position: if position.startswith('Cr-Commit-Position: '): position = position[len('Cr-Commit-Position: '):] sha = self.position_to_sha(position) else: position = self.sha_to_position(sha) assert len(sha) == 40, 'Expected SHA-1 hash, got {}'.format(sha) assert sha and position, 'ChromiumCommit should have sha and position after __init__' self.sha = sha self.position = position
def main(): parser = argparse.ArgumentParser( description='Get stats on WPT usage in Chromium') parser.add_argument('chromium_src', help='Path to the src/ folder of a Chromium checkout') parser.add_argument( '--csv-file', default='wpt-usage.csv', help='CSV file for results; also used to load existing results') parser.add_argument('--since', default='2019-01', help='Month to start at (inclusive)') parser.add_argument('--until', default=datetime.datetime.now().strftime('%Y-%m'), help='Month to end at (exclusive)') args = parser.parse_args() # We depend on the blinkpy library, so temporarily modify sys.path to bring # it in. blink_tools = os.path.join(args.chromium_src, 'third_party', 'blink', 'tools') sys.path.insert(0, blink_tools) from blinkpy.common.host import Host from blinkpy.w3c.chromium_finder import absolute_chromium_dir sys.path.remove(blink_tools) since = args.since until = args.until print('Processing WPT usage from', since, 'until', until) # Get existing CSV data, if any. usage = ChromiumWPTUsageDB(args.csv_file) try: usage.read() since = get_next_month(usage.values()[-1]['date']) print('Found existing CSV file, processing from', since, 'until', until) except (IOError, AssertionError): # Non-fatal error pass if not date_is_before(since, until): print('No data to update, finished!') return host = Host() chromium_dir = absolute_chromium_dir(host) while date_is_before(since, until): print('Getting stats for', since) next_month = get_next_month(since) usage.add(get_stats(host, chromium_dir, since, next_month)) since = next_month usage.write()
def fetch_current_revision_commit(self, host): """Fetches the git commit for the latest revision of CL. This method fetches the commit corresponding to the latest revision of CL to local Chromium repository, but does not checkout the commit to the working tree. All changes in the CL are squashed into this one commit, regardless of how many revisions have been uploaded. Args: host: A Host object for git invocation. Returns: A ChromiumCommit object (the fetched commit). """ git = host.git(absolute_chromium_dir(host)) url = self.current_revision['fetch']['http']['url'] ref = self.current_revision['fetch']['http']['ref'] git.run(['fetch', url, ref]) sha = git.run(['rev-parse', 'FETCH_HEAD']).strip() return ChromiumCommit(host, sha=sha)