Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: roll_dep.py

Issue 801643004: Allow to skip revision check in roll-dep. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This scripts takes the path to a dep and an svn revision, and updates the 6 """This scripts takes the path to a dep and an svn revision, and updates the
7 parent repo's DEPS file with the corresponding git revision. Sample invocation: 7 parent repo's DEPS file with the corresponding git revision. Sample invocation:
8 8
9 [chromium/src]$ roll-dep third_party/WebKit 12345 9 [chromium/src]$ roll-dep third_party/WebKit 12345
10 10
11 After the script completes, the DEPS file will be dirty with the new revision. 11 After the script completes, the DEPS file will be dirty with the new revision.
12 The user can then: 12 The user can then:
13 13
14 $ git add DEPS 14 $ git add DEPS
15 $ git commit 15 $ git commit
16 """ 16 """
17 17
18 import ast 18 import ast
19 import optparse
19 import os 20 import os
20 import re 21 import re
21 import sys 22 import sys
22 23
23 from itertools import izip 24 from itertools import izip
24 from subprocess import check_output, Popen, PIPE 25 from subprocess import check_output, Popen, PIPE
25 from textwrap import dedent 26 from textwrap import dedent
26 27
27 28
28 SHA1_RE = re.compile('^[a-fA-F0-9]{40}$') 29 SHA1_RE = re.compile('^[a-fA-F0-9]{40}$')
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 gclient_locals = {} 74 gclient_locals = {}
74 execfile(gclient_path, {}, gclient_locals) 75 execfile(gclient_path, {}, gclient_locals)
75 for soln in gclient_locals['solutions']: 76 for soln in gclient_locals['solutions']:
76 soln_relpath = platform_path(soln['name'].rstrip('/')) + os.sep 77 soln_relpath = platform_path(soln['name'].rstrip('/')) + os.sep
77 if (dep_path.startswith(soln_relpath) or 78 if (dep_path.startswith(soln_relpath) or
78 cwd.startswith(os.path.join(gclient_root, soln_relpath))): 79 cwd.startswith(os.path.join(gclient_root, soln_relpath))):
79 return soln 80 return soln
80 assert False, 'Could not determine the parent project for %s' % dep_path 81 assert False, 'Could not determine the parent project for %s' % dep_path
81 82
82 83
84 def is_git_hash(revision):
85 """Determines if a given revision is a git hash."""
86 return SHA1_RE.match(revision)
87
88
83 def verify_git_revision(dep_path, revision): 89 def verify_git_revision(dep_path, revision):
84 """Verify that a git revision exists in a repository.""" 90 """Verify that a git revision exists in a repository."""
85 p = Popen(['git', 'rev-list', '-n', '1', revision], 91 p = Popen(['git', 'rev-list', '-n', '1', revision],
86 cwd=dep_path, stdout=PIPE, stderr=PIPE) 92 cwd=dep_path, stdout=PIPE, stderr=PIPE)
87 result = p.communicate()[0].strip() 93 result = p.communicate()[0].strip()
88 if p.returncode != 0 or not SHA1_RE.match(result): 94 if p.returncode != 0 or not is_git_hash(result):
89 result = None 95 result = None
90 return result 96 return result
91 97
92 98
93 def get_svn_revision(dep_path, git_revision): 99 def get_svn_revision(dep_path, git_revision):
94 """Given a git revision, return the corresponding svn revision.""" 100 """Given a git revision, return the corresponding svn revision."""
95 p = Popen(['git', 'log', '-n', '1', '--pretty=format:%B', git_revision], 101 p = Popen(['git', 'log', '-n', '1', '--pretty=format:%B', git_revision],
96 stdout=PIPE, cwd=dep_path) 102 stdout=PIPE, cwd=dep_path)
97 (log, _) = p.communicate() 103 (log, _) = p.communicate()
98 assert p.returncode == 0, 'git log %s failed.' % git_revision 104 assert p.returncode == 0, 'git log %s failed.' % git_revision
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 log_p.terminate() 152 log_p.terminate()
147 grep_p.terminate() 153 grep_p.terminate()
148 raise RuntimeError('No match for revision %d; %s' % (revision, err_msg)) 154 raise RuntimeError('No match for revision %d; %s' % (revision, err_msg))
149 155
150 156
151 def get_git_revision(dep_path, revision): 157 def get_git_revision(dep_path, revision):
152 """Convert the revision argument passed to the script to a git revision.""" 158 """Convert the revision argument passed to the script to a git revision."""
153 svn_revision = None 159 svn_revision = None
154 if revision.startswith('r'): 160 if revision.startswith('r'):
155 git_revision = convert_svn_revision(dep_path, revision[1:]) 161 git_revision = convert_svn_revision(dep_path, revision[1:])
156 svn_revision = revision[1:] 162 svn_revision = revision[1:]
jochen (gone - plz use gerrit) 2014/12/12 10:08:36 nit. add if not git_revision: raise RuntimeError('
Michael Achenbach 2014/12/12 10:24:06 Done. I assume you meant two lines below as this c
157 elif re.search('[a-fA-F]', revision): 163 elif re.search('[a-fA-F]', revision):
158 git_revision = verify_git_revision(dep_path, revision) 164 git_revision = verify_git_revision(dep_path, revision)
159 svn_revision = get_svn_revision(dep_path, git_revision) 165 svn_revision = get_svn_revision(dep_path, git_revision)
160 elif len(revision) > 6: 166 elif len(revision) > 6:
161 git_revision = verify_git_revision(dep_path, revision) 167 git_revision = verify_git_revision(dep_path, revision)
162 if git_revision: 168 if git_revision:
163 svn_revision = get_svn_revision(dep_path, git_revision) 169 svn_revision = get_svn_revision(dep_path, git_revision)
164 else: 170 else:
165 git_revision = convert_svn_revision(dep_path, revision) 171 git_revision = convert_svn_revision(dep_path, revision)
166 svn_revision = revision 172 svn_revision = revision
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 cwd=dep_path).rstrip() 271 cwd=dep_path).rstrip()
266 272
267 273
268 def generate_commit_message(deps_section, dep_path, dep_name, new_rev): 274 def generate_commit_message(deps_section, dep_path, dep_name, new_rev):
269 (url, _, old_rev) = deps_section[dep_name].partition('@') 275 (url, _, old_rev) = deps_section[dep_name].partition('@')
270 if url.endswith('.git'): 276 if url.endswith('.git'):
271 url = url[:-4] 277 url = url[:-4]
272 old_rev_short = short_rev(old_rev, dep_path) 278 old_rev_short = short_rev(old_rev, dep_path)
273 new_rev_short = short_rev(new_rev, dep_path) 279 new_rev_short = short_rev(new_rev, dep_path)
274 url += '/+log/%s..%s' % (old_rev_short, new_rev_short) 280 url += '/+log/%s..%s' % (old_rev_short, new_rev_short)
275 old_svn_rev = get_svn_revision(dep_path, old_rev) 281 try:
276 new_svn_rev = get_svn_revision(dep_path, new_rev) 282 old_svn_rev = get_svn_revision(dep_path, old_rev)
283 new_svn_rev = get_svn_revision(dep_path, new_rev)
284 except Exception:
jochen (gone - plz use gerrit) 2014/12/12 10:08:36 when can this happen? I thought get_svn_revision j
Michael Achenbach 2014/12/12 10:24:06 It contains also an assertion that raises if git l
285 # Ignore failures that might arise from the repo not being checked out.
286 old_svn_rev = new_svn_rev = None
277 svn_range_str = '' 287 svn_range_str = ''
278 if old_svn_rev and new_svn_rev: 288 if old_svn_rev and new_svn_rev:
279 svn_range_str = ' (svn %s:%s)' % (old_svn_rev, new_svn_rev) 289 svn_range_str = ' (svn %s:%s)' % (old_svn_rev, new_svn_rev)
280 return dedent(ROLL_DESCRIPTION_STR % { 290 return dedent(ROLL_DESCRIPTION_STR % {
281 'dep_path': shorten_dep_path(dep_name), 291 'dep_path': shorten_dep_path(dep_name),
282 'before_rev': old_rev_short, 292 'before_rev': old_rev_short,
283 'after_rev': new_rev_short, 293 'after_rev': new_rev_short,
284 'svn_range': svn_range_str, 294 'svn_range': svn_range_str,
285 'revlog_url': url, 295 'revlog_url': url,
286 }) 296 })
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 ['git', 'rev-parse', '--show-toplevel'], 347 ['git', 'rev-parse', '--show-toplevel'],
338 cwd=deps_file_dir, stdout=PIPE).communicate()[0].strip() 348 cwd=deps_file_dir, stdout=PIPE).communicate()[0].strip()
339 with open(os.path.join(deps_file_root, '.git', 'MERGE_MSG'), 'w') as fh: 349 with open(os.path.join(deps_file_root, '.git', 'MERGE_MSG'), 'w') as fh:
340 fh.write(commit_msg) 350 fh.write(commit_msg)
341 else: 351 else:
342 print 'Could not find an entry in %s to update.' % deps_file 352 print 'Could not find an entry in %s to update.' % deps_file
343 return 0 if commit_msg else 1 353 return 0 if commit_msg else 1
344 354
345 355
346 def main(argv): 356 def main(argv):
357 parser = optparse.OptionParser()
358 parser.add_option('--no-verify-revision',
359 help='Don\'t verify the revision passed in. This '
360 'also skips adding an svn revision comment '
361 'for git dependencies and requires the passed '
362 'revision to be a git hash.',
363 default=False, action='store_true')
364 (options, argv) = parser.parse_args(argv)
347 if len(argv) not in (2, 3): 365 if len(argv) not in (2, 3):
348 print >> sys.stderr, ( 366 print >> sys.stderr, (
349 'Usage: roll_dep.py <dep path> <svn revision> [ <DEPS file> ]') 367 'Usage: roll_dep.py [options] <dep path> <svn revision> '
368 '[ <DEPS file> ]')
350 return 1 369 return 1
351 (arg_dep_path, revision) = argv[0:2] 370 (arg_dep_path, revision) = argv[0:2]
352 gclient_root = find_gclient_root() 371 gclient_root = find_gclient_root()
353 dep_path = platform_path(arg_dep_path) 372 dep_path = platform_path(arg_dep_path)
354 if not os.path.exists(dep_path): 373 if not os.path.exists(dep_path):
355 dep_path = os.path.join(gclient_root, dep_path) 374 dep_path = os.path.join(gclient_root, dep_path)
356 assert os.path.isdir(dep_path), 'No such directory: %s' % arg_dep_path 375 if not options.no_verify_revision:
376 # Only require the path to exist if the revision should be verified. A path
377 # to e.g. os deps might not be checked out.
378 assert os.path.isdir(dep_path), 'No such directory: %s' % arg_dep_path
357 if len(argv) > 2: 379 if len(argv) > 2:
358 deps_file = argv[2] 380 deps_file = argv[2]
359 else: 381 else:
360 soln = get_solution(gclient_root, dep_path) 382 soln = get_solution(gclient_root, dep_path)
361 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name'])) 383 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name']))
362 deps_file = os.path.join(soln_path, 'DEPS') 384 deps_file = os.path.join(soln_path, 'DEPS')
363 dep_name = posix_path(os.path.relpath(dep_path, gclient_root)) 385 dep_name = posix_path(os.path.relpath(dep_path, gclient_root))
364 (git_rev, svn_rev) = get_git_revision(dep_path, revision) 386 if options.no_verify_revision:
365 comment = ('from svn revision %s' % svn_rev) if svn_rev else None 387 assert is_git_hash(revision), (
366 assert git_rev, 'Could not find git revision matching %s.' % revision 388 'The passed revision %s must be a git hash when skipping revision '
389 'verification.' % revision)
390 git_rev = revision
391 comment = None
392 else:
393 (git_rev, svn_rev) = get_git_revision(dep_path, revision)
394 comment = ('from svn revision %s' % svn_rev) if svn_rev else None
395 assert git_rev, 'Could not find git revision matching %s.' % revision
367 return update_deps(deps_file, dep_path, dep_name, git_rev, comment) 396 return update_deps(deps_file, dep_path, dep_name, git_rev, comment)
368 397
369 if __name__ == '__main__': 398 if __name__ == '__main__':
370 sys.exit(main(sys.argv[1:])) 399 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698