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

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: Review 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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:]
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)
165 if not git_revision:
166 raise RuntimeError('Please \'git fetch origin\' in %s' % dep_path)
159 svn_revision = get_svn_revision(dep_path, git_revision) 167 svn_revision = get_svn_revision(dep_path, git_revision)
160 elif len(revision) > 6: 168 elif len(revision) > 6:
161 git_revision = verify_git_revision(dep_path, revision) 169 git_revision = verify_git_revision(dep_path, revision)
162 if git_revision: 170 if git_revision:
163 svn_revision = get_svn_revision(dep_path, git_revision) 171 svn_revision = get_svn_revision(dep_path, git_revision)
164 else: 172 else:
165 git_revision = convert_svn_revision(dep_path, revision) 173 git_revision = convert_svn_revision(dep_path, revision)
166 svn_revision = revision 174 svn_revision = revision
167 else: 175 else:
168 try: 176 try:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 cwd=dep_path).rstrip() 273 cwd=dep_path).rstrip()
266 274
267 275
268 def generate_commit_message(deps_section, dep_path, dep_name, new_rev): 276 def generate_commit_message(deps_section, dep_path, dep_name, new_rev):
269 (url, _, old_rev) = deps_section[dep_name].partition('@') 277 (url, _, old_rev) = deps_section[dep_name].partition('@')
270 if url.endswith('.git'): 278 if url.endswith('.git'):
271 url = url[:-4] 279 url = url[:-4]
272 old_rev_short = short_rev(old_rev, dep_path) 280 old_rev_short = short_rev(old_rev, dep_path)
273 new_rev_short = short_rev(new_rev, dep_path) 281 new_rev_short = short_rev(new_rev, dep_path)
274 url += '/+log/%s..%s' % (old_rev_short, new_rev_short) 282 url += '/+log/%s..%s' % (old_rev_short, new_rev_short)
275 old_svn_rev = get_svn_revision(dep_path, old_rev) 283 try:
276 new_svn_rev = get_svn_revision(dep_path, new_rev) 284 old_svn_rev = get_svn_revision(dep_path, old_rev)
285 new_svn_rev = get_svn_revision(dep_path, new_rev)
286 except Exception:
287 # Ignore failures that might arise from the repo not being checked out.
288 old_svn_rev = new_svn_rev = None
277 svn_range_str = '' 289 svn_range_str = ''
278 if old_svn_rev and new_svn_rev: 290 if old_svn_rev and new_svn_rev:
279 svn_range_str = ' (svn %s:%s)' % (old_svn_rev, new_svn_rev) 291 svn_range_str = ' (svn %s:%s)' % (old_svn_rev, new_svn_rev)
280 return dedent(ROLL_DESCRIPTION_STR % { 292 return dedent(ROLL_DESCRIPTION_STR % {
281 'dep_path': shorten_dep_path(dep_name), 293 'dep_path': shorten_dep_path(dep_name),
282 'before_rev': old_rev_short, 294 'before_rev': old_rev_short,
283 'after_rev': new_rev_short, 295 'after_rev': new_rev_short,
284 'svn_range': svn_range_str, 296 'svn_range': svn_range_str,
285 'revlog_url': url, 297 'revlog_url': url,
286 }) 298 })
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 ['git', 'rev-parse', '--show-toplevel'], 349 ['git', 'rev-parse', '--show-toplevel'],
338 cwd=deps_file_dir, stdout=PIPE).communicate()[0].strip() 350 cwd=deps_file_dir, stdout=PIPE).communicate()[0].strip()
339 with open(os.path.join(deps_file_root, '.git', 'MERGE_MSG'), 'w') as fh: 351 with open(os.path.join(deps_file_root, '.git', 'MERGE_MSG'), 'w') as fh:
340 fh.write(commit_msg) 352 fh.write(commit_msg)
341 else: 353 else:
342 print 'Could not find an entry in %s to update.' % deps_file 354 print 'Could not find an entry in %s to update.' % deps_file
343 return 0 if commit_msg else 1 355 return 0 if commit_msg else 1
344 356
345 357
346 def main(argv): 358 def main(argv):
359 parser = optparse.OptionParser()
360 parser.add_option('--no-verify-revision',
361 help='Don\'t verify the revision passed in. This '
362 'also skips adding an svn revision comment '
363 'for git dependencies and requires the passed '
364 'revision to be a git hash.',
365 default=False, action='store_true')
366 (options, argv) = parser.parse_args(argv)
347 if len(argv) not in (2, 3): 367 if len(argv) not in (2, 3):
348 print >> sys.stderr, ( 368 print >> sys.stderr, (
349 'Usage: roll_dep.py <dep path> <svn revision> [ <DEPS file> ]') 369 'Usage: roll_dep.py [options] <dep path> <svn revision> '
370 '[ <DEPS file> ]')
350 return 1 371 return 1
351 (arg_dep_path, revision) = argv[0:2] 372 (arg_dep_path, revision) = argv[0:2]
352 gclient_root = find_gclient_root() 373 gclient_root = find_gclient_root()
353 dep_path = platform_path(arg_dep_path) 374 dep_path = platform_path(arg_dep_path)
354 if not os.path.exists(dep_path): 375 if not os.path.exists(dep_path):
355 dep_path = os.path.join(gclient_root, dep_path) 376 dep_path = os.path.join(gclient_root, dep_path)
356 assert os.path.isdir(dep_path), 'No such directory: %s' % arg_dep_path 377 if not options.no_verify_revision:
378 # Only require the path to exist if the revision should be verified. A path
379 # to e.g. os deps might not be checked out.
380 assert os.path.isdir(dep_path), 'No such directory: %s' % arg_dep_path
357 if len(argv) > 2: 381 if len(argv) > 2:
358 deps_file = argv[2] 382 deps_file = argv[2]
359 else: 383 else:
360 soln = get_solution(gclient_root, dep_path) 384 soln = get_solution(gclient_root, dep_path)
361 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name'])) 385 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name']))
362 deps_file = os.path.join(soln_path, 'DEPS') 386 deps_file = os.path.join(soln_path, 'DEPS')
363 dep_name = posix_path(os.path.relpath(dep_path, gclient_root)) 387 dep_name = posix_path(os.path.relpath(dep_path, gclient_root))
364 (git_rev, svn_rev) = get_git_revision(dep_path, revision) 388 if options.no_verify_revision:
365 comment = ('from svn revision %s' % svn_rev) if svn_rev else None 389 assert is_git_hash(revision), (
366 assert git_rev, 'Could not find git revision matching %s.' % revision 390 'The passed revision %s must be a git hash when skipping revision '
391 'verification.' % revision)
392 git_rev = revision
393 comment = None
394 else:
395 (git_rev, svn_rev) = get_git_revision(dep_path, revision)
396 comment = ('from svn revision %s' % svn_rev) if svn_rev else None
397 assert git_rev, 'Could not find git revision matching %s.' % revision
367 return update_deps(deps_file, dep_path, dep_name, git_rev, comment) 398 return update_deps(deps_file, dep_path, dep_name, git_rev, comment)
368 399
369 if __name__ == '__main__': 400 if __name__ == '__main__':
370 sys.exit(main(sys.argv[1:])) 401 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