• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Create a CL to update the SKP version."""
6
7
8import argparse
9import os
10import subprocess
11import sys
12import urllib2
13
14import git_utils
15
16
17COMMIT_MSG = '''Update SKP version
18
19Automatic commit by the RecreateSKPs bot.
20
21TBR=rmistry@google.com
22NO_MERGE_BUILDS
23'''
24SKIA_REPO = 'https://skia.googlesource.com/skia.git'
25
26
27def main(target_dir):
28  # We're going to sync a new, clean Skia checkout to upload the CL to update
29  # the SKPs. However, we want to use the scripts from the current checkout,
30  # in order to facilitate running this as a try job.
31  infrabots_dir = os.path.dirname(os.path.realpath(__file__))
32  skp_dir = os.path.join(infrabots_dir, 'assets', 'skp')
33  upload_py = os.path.join(skp_dir, 'upload.py')
34
35  with git_utils.NewGitCheckout(repository=SKIA_REPO):
36    # First verify that there are no gen_tasks diffs.
37    tmp_infrabots_dir = os.path.join(os.getcwd(), 'infra', 'bots')
38    tmp_gen_tasks = os.path.join(tmp_infrabots_dir, 'gen_tasks.go')
39    try:
40      subprocess.check_call(['go', 'run', tmp_gen_tasks, '--test'])
41    except subprocess.CalledProcessError as e:
42      print >> sys.stderr, (
43         'gen_tasks.go failed, not uploading SKP update:\n\n%s' % e.output)
44      sys.exit(1)
45
46    # Upload the new version, land the update CL as the recreate-skps user.
47    with git_utils.GitBranch(branch_name='update_skp_version',
48                             commit_msg=COMMIT_MSG,
49                             commit_queue=True):
50      upload_cmd = ['python', upload_py, '-t', target_dir]
51      if args.chromium_path:
52        chromium_revision = subprocess.check_output(
53            ['git', 'rev-parse', 'HEAD'], cwd=args.chromium_path).rstrip()
54        upload_cmd.extend([
55            '--extra_tags', 'chromium_revision:%s' % chromium_revision])
56      subprocess.check_call(upload_cmd)
57      # We used upload.py from the repo that this script lives in, NOT the temp
58      # repo we've created. Therefore, the VERSION file was written in that repo
59      # so we need to copy it to the temp repo in order to commit it.
60      src = os.path.join(skp_dir, 'VERSION')
61      dst = os.path.join(
62          os.getcwd(), 'infra', 'bots', 'assets', 'skp', 'VERSION')
63      subprocess.check_call(['cp', src, dst])
64      subprocess.check_call(['go', 'run', tmp_gen_tasks])
65      subprocess.check_call([
66          'git', 'add', os.path.join('infra', 'bots', 'tasks.json')])
67
68
69if '__main__' == __name__:
70  parser = argparse.ArgumentParser()
71  parser.add_argument("--target_dir")
72  parser.add_argument("--chromium_path")
73  args = parser.parse_args()
74  main(args.target_dir)
75