Commit a3d7c4b3 authored by stip@chromium.org's avatar stip@chromium.org

Add got_revision support for apply_issue.

BUG=170427

Review URL: https://codereview.chromium.org/60613005

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@236101 0039d316-1c4b-4281-b951-d872f2087c98
parent c61894cc
#!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Wraps gclient calls with annotated output.
Note that you will have to use -- to stop option parsing for gclient flags.
To run `gclient sync --gclientfile=.gclient` and annotate got_v8_revision:
`annotated_gclient.py --revision-mapping='{"src/v8": "got_v8_revision"}' --
sync --gclientfile=.gclient`
"""
import contextlib
import json
import optparse
import os
import subprocess
import sys
import tempfile
@contextlib.contextmanager
def temp_filename(suffix='', prefix='tmp'):
output_fd, output_file = tempfile.mkstemp(suffix=suffix, prefix=prefix)
os.close(output_fd)
yield output_file
try:
os.remove(output_file)
except OSError as e:
print 'Error cleaning up temp file %s: %s' % (output_file, e)
def parse_got_revision(filename, revision_mapping):
result = {}
with open(filename) as f:
data = json.load(f)
for path, info in data['solutions'].iteritems():
# gclient json paths always end with a slash
path = path.rstrip('/')
if path in revision_mapping:
propname = revision_mapping[path]
result[propname] = info['revision']
return result
def emit_buildprops(got_revisions):
for prop, revision in got_revisions.iteritems():
print '@@@SET_BUILD_PROPERTY@%s@%s@@@' % (prop, revision)
def main():
parser = optparse.OptionParser(
description=('Runs gclient and annotates the output with any '
'got_revisions.'))
parser.add_option('--revision-mapping', default='{}',
help='json dict of directory-to-property mappings.')
parser.add_option('--suffix', default='gclient',
help='tempfile suffix')
opts, args = parser.parse_args()
revision_mapping = json.loads(opts.revision_mapping)
if not args:
parser.error('Must provide arguments to gclient.')
if any(a.startswith('--output-json') for a in args):
parser.error('Can\'t call annotated_gclient with --output-json.')
with temp_filename(opts.suffix) as f:
cmd = ['gclient']
cmd.extend(args)
cmd.extend(['--output-json', f])
p = subprocess.Popen(cmd)
p.wait()
if p.returncode == 0:
revisions = parse_got_revision(f, revision_mapping)
emit_buildprops(revisions)
return p.returncode
if __name__ == '__main__':
sys.exit(main())
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
""" """
import getpass import getpass
import json
import logging import logging
import optparse import optparse
import os import os
...@@ -16,6 +17,7 @@ import urllib2 ...@@ -16,6 +17,7 @@ import urllib2
import breakpad # pylint: disable=W0611 import breakpad # pylint: disable=W0611
import annotated_gclient
import checkout import checkout
import fix_encoding import fix_encoding
import gclient_utils import gclient_utils
...@@ -67,6 +69,9 @@ def main(): ...@@ -67,6 +69,9 @@ def main():
help='Rietveld server') help='Rietveld server')
parser.add_option('--no-auth', action='store_true', parser.add_option('--no-auth', action='store_true',
help='Do not attempt authenticated requests.') help='Do not attempt authenticated requests.')
parser.add_option('--revision-mapping', default='{}',
help='When running gclient, annotate the got_revisions '
'using the revision-mapping.')
options, args = parser.parse_args() options, args = parser.parse_args()
logging.basicConfig( logging.basicConfig(
format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s',
...@@ -80,6 +85,8 @@ def main(): ...@@ -80,6 +85,8 @@ def main():
if not options.server: if not options.server:
parser.error('Require a valid server') parser.error('Require a valid server')
options.revision_mapping = json.loads(options.revision_mapping)
if options.password == '-': if options.password == '-':
print('Reading password') print('Reading password')
options.password = sys.stdin.readline().strip() options.password = sys.stdin.readline().strip()
...@@ -178,14 +185,24 @@ def main(): ...@@ -178,14 +185,24 @@ def main():
gclient_path = os.path.join(BASE_DIR, 'gclient') gclient_path = os.path.join(BASE_DIR, 'gclient')
if sys.platform == 'win32': if sys.platform == 'win32':
gclient_path += '.bat' gclient_path += '.bat'
return subprocess.call( with annotated_gclient.temp_filename(suffix='gclient') as f:
[ cmd = [
gclient_path, 'sync', gclient_path, 'sync',
'--revision', base_rev, '--revision', base_rev,
'--nohooks', '--nohooks',
'--delete_unversioned_trees', '--delete_unversioned_trees',
], ]
cwd=gclient_root) if options.revision_mapping:
cmd.extend(['--output-json', f])
retcode = subprocess.call(cmd, cwd=gclient_root)
if retcode == 0 and options.revision_mapping:
revisions = annotated_gclient.parse_got_revision(
f, options.revision_mapping)
annotated_gclient.emit_buildprops(revisions)
return retcode
return 0 return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment