2019-04-16 19:15:21 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright 2019 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
|
2021-03-25 13:04:43 +00:00
|
|
|
from __future__ import print_function
|
2019-04-17 16:32:07 +00:00
|
|
|
import os
|
|
|
|
import re
|
2019-04-16 19:15:21 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from infra import git
|
|
|
|
from infra import go
|
|
|
|
|
2019-04-17 16:32:07 +00:00
|
|
|
_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
_REPO_ROOT = os.path.realpath(os.path.join(_TOOLS_DIR, os.pardir))
|
|
|
|
_INFRA_BOTS = os.path.join(_REPO_ROOT, 'infra', 'bots')
|
|
|
|
sys.path.insert(0, _INFRA_BOTS)
|
|
|
|
import git_utils
|
|
|
|
|
2019-04-16 19:15:21 +00:00
|
|
|
|
|
|
|
REFS_HEADS_PREFIX = 'refs/heads/'
|
|
|
|
CHROME_REF_PREFIX = REFS_HEADS_PREFIX + 'chrome/m'
|
2019-04-17 16:32:07 +00:00
|
|
|
SK_MILESTONE_H = os.path.join('include', 'core', 'SkMilestone.h')
|
|
|
|
SK_MILESTONE_TMPL = r'#define SK_MILESTONE %s'
|
|
|
|
SK_MILESTONE_RE = SK_MILESTONE_TMPL % r'(\d+)'
|
|
|
|
SKIA_REPO = 'https://skia.googlesource.com/skia.git'
|
2020-05-13 17:48:55 +00:00
|
|
|
SUPPORTED_CHROME_BRANCHES = 3
|
2019-04-17 16:32:07 +00:00
|
|
|
UPDATE_MILESTONE_COMMIT_MSG = '''Update Skia milestone to %d'''
|
2019-04-16 19:15:21 +00:00
|
|
|
|
|
|
|
|
2019-04-17 16:32:07 +00:00
|
|
|
def get_current_milestone():
|
|
|
|
'''Read SkMilestone.h and parse out the current milestone.'''
|
|
|
|
sk_milestone = os.path.join(_REPO_ROOT, SK_MILESTONE_H)
|
|
|
|
with open(sk_milestone, 'r') as f:
|
|
|
|
contents = f.read()
|
|
|
|
for line in contents.splitlines():
|
|
|
|
m = re.match(SK_MILESTONE_RE, line)
|
|
|
|
if m:
|
|
|
|
return int(m.groups()[0])
|
|
|
|
print >> sys.stderr, (
|
|
|
|
'Failed to parse %s; has the format changed?' % SK_MILESTONE_H)
|
|
|
|
sys.exit(1)
|
2019-04-16 19:15:21 +00:00
|
|
|
|
|
|
|
|
2019-04-17 16:32:07 +00:00
|
|
|
def create_new_branch(new_branch, branch_at):
|
|
|
|
'''Create a temporary checkout of the repo, create the new branch and push.'''
|
|
|
|
b = new_branch[len(REFS_HEADS_PREFIX):]
|
|
|
|
with git_utils.NewGitCheckout(SKIA_REPO, local=_REPO_ROOT):
|
|
|
|
git.git('checkout', '-b', b)
|
|
|
|
git.git('reset', '--hard', branch_at)
|
|
|
|
git.git('push', '--set-upstream', 'origin', b)
|
|
|
|
|
|
|
|
|
|
|
|
def update_milestone(m):
|
|
|
|
'''Update SkMilestone.h to match the given milestone number.'''
|
|
|
|
with git_utils.NewGitCheckout(SKIA_REPO, local=_REPO_ROOT):
|
|
|
|
with git_utils.GitBranch(
|
|
|
|
'update_milestone', UPDATE_MILESTONE_COMMIT_MSG % m):
|
|
|
|
with open(SK_MILESTONE_H, 'r+') as f:
|
|
|
|
contents = re.sub(
|
|
|
|
SK_MILESTONE_RE, SK_MILESTONE_TMPL % str(m), f.read(), flags=re.M)
|
|
|
|
f.seek(0)
|
|
|
|
f.write(contents)
|
|
|
|
f.truncate()
|
|
|
|
git.git('diff')
|
|
|
|
|
|
|
|
|
|
|
|
def update_infra_config(old_branch, new_branch):
|
|
|
|
'''Create a CL to add infra support for the new branch and remove the old.'''
|
2019-04-16 19:15:21 +00:00
|
|
|
owner = git.git('config', 'user.email').rstrip()
|
|
|
|
if not owner:
|
2019-04-17 16:32:07 +00:00
|
|
|
print >> sys.stderr, ('No configured git user; please run '
|
|
|
|
'"git config user.email <your email>".')
|
2019-04-16 19:15:21 +00:00
|
|
|
sys.exit(1)
|
2019-12-05 19:29:38 +00:00
|
|
|
go.mod_download()
|
|
|
|
go.install(go.INFRA_GO+'/go/supported_branches/cmd/new-branch')
|
2019-04-16 19:15:21 +00:00
|
|
|
subprocess.check_call(['new-branch',
|
2019-06-04 16:36:43 +00:00
|
|
|
'--branch', new_branch[len(REFS_HEADS_PREFIX):],
|
|
|
|
'--delete', old_branch[len(REFS_HEADS_PREFIX):],
|
2019-04-18 12:54:33 +00:00
|
|
|
'--owner', owner,
|
|
|
|
'--exclude-trybots=chromium.*',
|
2019-12-04 12:18:57 +00:00
|
|
|
'--exclude-trybots=.*Android_Framework.*',
|
2020-02-28 17:29:53 +00:00
|
|
|
'--exclude-trybots=.*G3_Framework.*',
|
2021-01-08 14:06:54 +00:00
|
|
|
'--exclude-trybots=.*CanvasKit.*',
|
|
|
|
'--exclude-trybots=.*PathKit.*',
|
2019-12-04 12:18:57 +00:00
|
|
|
'--submit'])
|
2019-04-16 19:15:21 +00:00
|
|
|
|
|
|
|
|
2019-04-17 16:32:07 +00:00
|
|
|
def main():
|
2019-06-04 16:36:43 +00:00
|
|
|
if len(sys.argv) != 2 or '--help' in sys.argv or '-h' in sys.argv:
|
2019-04-17 16:32:07 +00:00
|
|
|
print >> sys.stderr, 'Usage: %s <commit hash for branch>' % sys.argv[0]
|
|
|
|
sys.exit(1)
|
2019-04-18 12:54:33 +00:00
|
|
|
go.check()
|
2019-04-17 16:32:07 +00:00
|
|
|
branch_at = sys.argv[1]
|
|
|
|
m = get_current_milestone()
|
|
|
|
new_branch = '%s%d' % (CHROME_REF_PREFIX, m)
|
|
|
|
old_branch = '%s%d' % (CHROME_REF_PREFIX, m-SUPPORTED_CHROME_BRANCHES)
|
2021-03-25 13:04:43 +00:00
|
|
|
print('Creating branch %s and removing support (eg. CQ) for %s' % (
|
|
|
|
new_branch, old_branch))
|
2019-04-17 16:32:07 +00:00
|
|
|
create_new_branch(new_branch, branch_at)
|
|
|
|
update_milestone(m+1)
|
|
|
|
update_infra_config(old_branch, new_branch)
|
|
|
|
|
|
|
|
|
2019-04-16 19:15:21 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|