1# Copyright 2019 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""" 5Update Chromium to ToT devtools-frontend. 6""" 7 8import argparse 9import os 10import shutil 11import subprocess 12import sys 13 14 15def parse_options(cli_args): 16 parser = argparse.ArgumentParser( 17 description='Roll dependencies from Chromium.') 18 parser.add_argument('chromium_dir', help='Chromium directory') 19 parser.add_argument('devtools_dir', help='DevTools directory') 20 parser.add_argument('reviewer', help='reviewer for the CL') 21 return parser.parse_args(cli_args) 22 23def update(options): 24 # Update from upstream 25 subprocess.check_call(['git', 'fetch', 'origin'], 26 cwd=options.chromium_dir) 27 subprocess.check_call(['git', 'checkout', 'origin/master'], 28 cwd=options.chromium_dir) 29 subprocess.check_call(['git', 'fetch', 'origin'], 30 cwd=options.devtools_dir) 31 # Get commit hashes 32 new_rev = subprocess.check_output(['git', 'rev-parse', 'origin/master'], 33 cwd=options.devtools_dir).strip() 34 old_rev = subprocess.check_output( 35 ['gclient', 'getdep', '--var=devtools_frontend_revision'], 36 cwd=options.chromium_dir).strip() 37 rev_range = '%s..%s' % (old_rev[0:10], new_rev[0:10]) 38 # Create commit message 39 message = 'Update third_party/devtools-frontend %s' % rev_range 40 message = message + '\n\n' 41 message = message + 'https://chromium.googlesource.com/devtools/devtools-frontend/+log/' 42 message = message + rev_range 43 # Display changes 44 subprocess.check_call(['git', 'log', '--oneline', rev_range], 45 cwd=options.devtools_dir) 46 # Set deps 47 subprocess.check_call( 48 ['gclient', 'setdep', '--var=devtools_frontend_revision=%s' % new_rev], 49 cwd=options.chromium_dir) 50 # Create commit 51 subprocess.check_call(['git', 'add', 'DEPS'], cwd=options.chromium_dir) 52 subprocess.check_call( 53 ['git', 54 'checkout', 55 '-b', 56 'devtools_frontend_%s_%s' % (old_rev[0:5], new_rev[0:5])], 57 cwd=options.chromium_dir) 58 subprocess.check_call(['git', 'commit', '-m', message], 59 cwd=options.chromium_dir) 60 # Upload CL 61 subprocess.check_call( 62 ['git', 63 'cl', 64 'upload', 65 '-m', message, 66 '--tbrs=%s' % options.reviewer, 67 '-c'], 68 cwd=options.chromium_dir) 69 subprocess.check_call(['git', 'cl', 'web'], cwd=options.chromium_dir) 70 71 72if __name__ == '__main__': 73 OPTIONS = parse_options(sys.argv[1:]) 74 update(OPTIONS) 75