upload_skps.py 2.7 KB

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