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

Side by Side Diff: roll_dep.py

Issue 666713004: Add optional <DEPS file> argument to roll-dep. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix error message. Created 6 years, 2 months 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
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 }) 286 })
287 287
288 def update_deps_entry(deps_lines, deps_ast, value_node, new_rev, comment): 288 def update_deps_entry(deps_lines, deps_ast, value_node, new_rev, comment):
289 line_idx = update_node(deps_lines, deps_ast, value_node, new_rev) 289 line_idx = update_node(deps_lines, deps_ast, value_node, new_rev)
290 (content, _, _) = deps_lines[line_idx].partition('#') 290 (content, _, _) = deps_lines[line_idx].partition('#')
291 if comment: 291 if comment:
292 deps_lines[line_idx] = '%s # %s' % (content.rstrip(), comment) 292 deps_lines[line_idx] = '%s # %s' % (content.rstrip(), comment)
293 else: 293 else:
294 deps_lines[line_idx] = content.rstrip() 294 deps_lines[line_idx] = content.rstrip()
295 295
296 def update_deps(soln_path, dep_path, dep_name, new_rev, comment): 296 def update_deps(deps_file, dep_path, dep_name, new_rev, comment):
297 """Update the DEPS file with the new git revision.""" 297 """Update the DEPS file with the new git revision."""
298 commit_msg = '' 298 commit_msg = ''
299 deps_file = os.path.join(soln_path, 'DEPS')
300 with open(deps_file) as fh: 299 with open(deps_file) as fh:
301 deps_content = fh.read() 300 deps_content = fh.read()
302 deps_locals = {} 301 deps_locals = {}
303 def _Var(key): 302 def _Var(key):
304 return deps_locals['vars'][key] 303 return deps_locals['vars'][key]
305 deps_locals['Var'] = _Var 304 deps_locals['Var'] = _Var
306 exec deps_content in {}, deps_locals 305 exec deps_content in {}, deps_locals
307 deps_lines = deps_content.splitlines() 306 deps_lines = deps_content.splitlines()
308 deps_ast = ast.parse(deps_content, deps_file) 307 deps_ast = ast.parse(deps_content, deps_file)
309 deps_node = find_deps_section(deps_ast, 'deps') 308 deps_node = find_deps_section(deps_ast, 'deps')
(...skipping 16 matching lines...) Expand all
326 update_deps_entry(deps_lines, deps_ast, value_node, new_rev, comment) 325 update_deps_entry(deps_lines, deps_ast, value_node, new_rev, comment)
327 commit_msg = generate_commit_message( 326 commit_msg = generate_commit_message(
328 deps_locals['deps_os'][os_name], dep_path, dep_name, new_rev) 327 deps_locals['deps_os'][os_name], dep_path, dep_name, new_rev)
329 if commit_msg: 328 if commit_msg:
330 print 'Pinning %s' % dep_name 329 print 'Pinning %s' % dep_name
331 print 'to revision %s' % new_rev 330 print 'to revision %s' % new_rev
332 print 'in %s' % deps_file 331 print 'in %s' % deps_file
333 with open(deps_file, 'w') as fh: 332 with open(deps_file, 'w') as fh:
334 for line in deps_lines: 333 for line in deps_lines:
335 print >> fh, line 334 print >> fh, line
336 with open(os.path.join(soln_path, '.git', 'MERGE_MSG'), 'a') as fh: 335 deps_file_dir = os.path.normpath(os.path.dirname(deps_file))
336 deps_file_root = Popen(
337 ['git', 'rev-parse', '--show-toplevel'],
338 cwd=deps_file_dir, stdout=PIPE).communicate()[0].strip()
339 with open(os.path.join(deps_file_root, '.git', 'MERGE_MSG'), 'w') as fh:
337 fh.write(commit_msg) 340 fh.write(commit_msg)
338 else: 341 else:
339 print 'Could not find an entry in %s to update.' % deps_file 342 print 'Could not find an entry in %s to update.' % deps_file
340 return 0 if commit_msg else 1 343 return 0 if commit_msg else 1
341 344
342 345
343 def main(argv): 346 def main(argv):
344 if len(argv) != 2 : 347 if len(argv) not in (2, 3):
345 print >> sys.stderr, 'Usage: roll_dep.py <dep path> <svn revision>' 348 print >> sys.stderr, (
349 'Usage: roll_dep.py <dep path> <svn revision> [ <DEPS file> ]')
346 return 1 350 return 1
347 (dep_path, revision) = argv[0:2] 351 (arg_dep_path, revision) = argv[0:2]
348 dep_path = platform_path(dep_path)
349 assert os.path.isdir(dep_path), 'No such directory: %s' % dep_path
350 gclient_root = find_gclient_root() 352 gclient_root = find_gclient_root()
351 soln = get_solution(gclient_root, dep_path) 353 dep_path = platform_path(arg_dep_path)
352 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name'])) 354 if not os.path.exists(dep_path):
355 dep_path = os.path.join(gclient_root, dep_path)
356 assert os.path.isdir(dep_path), 'No such directory: %s' % arg_dep_path
357 if len(argv) > 2:
358 deps_file = argv[2]
359 else:
360 soln = get_solution(gclient_root, dep_path)
361 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name']))
362 deps_file = os.path.join(soln_path, 'DEPS')
353 dep_name = posix_path(os.path.relpath(dep_path, gclient_root)) 363 dep_name = posix_path(os.path.relpath(dep_path, gclient_root))
354 (git_rev, svn_rev) = get_git_revision(dep_path, revision) 364 (git_rev, svn_rev) = get_git_revision(dep_path, revision)
355 comment = ('from svn revision %s' % svn_rev) if svn_rev else None 365 comment = ('from svn revision %s' % svn_rev) if svn_rev else None
356 assert git_rev, 'Could not find git revision matching %s.' % revision 366 assert git_rev, 'Could not find git revision matching %s.' % revision
357 return update_deps(soln_path, dep_path, dep_name, git_rev, comment) 367 return update_deps(deps_file, dep_path, dep_name, git_rev, comment)
358 368
359 if __name__ == '__main__': 369 if __name__ == '__main__':
360 sys.exit(main(sys.argv[1:])) 370 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