1#!/usr/bin/env python 2# Copyright (c) 2016 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""This script takes a Clang revision as an argument, it then 7creates a feature branch, puts this revision into update.py, uploads 8a CL, triggers Clang Upload try bots, and tells what to do next""" 9 10import argparse 11import fnmatch 12import itertools 13import os 14import re 15import shutil 16import subprocess 17import sys 18 19# Path constants. 20THIS_DIR = os.path.dirname(__file__) 21UPDATE_PY_PATH = os.path.join(THIS_DIR, "update.py") 22CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..')) 23 24is_win = sys.platform.startswith('win32') 25 26def PatchRevision(clang_revision, clang_sub_revision): 27 with open(UPDATE_PY_PATH, 'rb') as f: 28 content = f.read() 29 m = re.search("CLANG_REVISION = '([0-9]+)'", content) 30 clang_old_revision = m.group(1) 31 content = re.sub("CLANG_REVISION = '[0-9]+'", 32 "CLANG_REVISION = '{}'".format(clang_revision), 33 content, count=1) 34 content = re.sub("CLANG_SUB_REVISION=[0-9]+", 35 "CLANG_SUB_REVISION={}".format(clang_sub_revision), 36 content, count=1) 37 with open(UPDATE_PY_PATH, 'wb') as f: 38 f.write(content) 39 return clang_old_revision 40 41 42def Git(args): 43 # Needs shell=True on Windows due to git.bat in depot_tools. 44 subprocess.check_call(["git"] + args, shell=is_win) 45 46def main(): 47 parser = argparse.ArgumentParser(description='upload new clang revision') 48 parser.add_argument('clang_revision', metavar='CLANG_REVISION', 49 type=int, nargs=1, 50 help='Clang revision to build the toolchain for.') 51 parser.add_argument('clang_sub_revision', metavar='CLANG_SUB_REVISION', 52 type=int, nargs='?', default=1, 53 help='Clang sub-revision to build the toolchain for.') 54 55 args = parser.parse_args() 56 57 clang_revision = args.clang_revision[0] 58 clang_sub_revision = args.clang_sub_revision 59 # Needs shell=True on Windows due to git.bat in depot_tools. 60 git_revision = subprocess.check_output( 61 ["git", "rev-parse", "origin/master"], shell=is_win).strip() 62 print "Making a patch for Clang revision r{}-{}".format( 63 clang_revision, clang_sub_revision) 64 print "Chrome revision: {}".format(git_revision) 65 clang_old_revision = PatchRevision(clang_revision, clang_sub_revision) 66 67 Git(["checkout", "-b", "clang-{}-{}".format( 68 clang_revision, clang_sub_revision)]) 69 Git(["add", UPDATE_PY_PATH]) 70 71 commit_message = 'Ran `{}`.'.format(' '.join(sys.argv)) 72 Git(["commit", "-m", "Roll clang {}:{}.\n\n{}".format( 73 clang_old_revision, clang_revision, commit_message)]) 74 75 Git(["cl", "upload", "-f"]) 76 Git(["cl", "try", "-b", "linux_upload_clang", "-r", git_revision]) 77 Git(["cl", "try", "-b", "mac_upload_clang", "-r", git_revision]) 78 Git(["cl", "try", "-b", "win_upload_clang", "-r", git_revision]) 79 80 print ("Please, wait until the try bots succeeded " 81 "and then push the binaries to goma.") 82 83if __name__ == '__main__': 84 sys.exit(main()) 85