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

Side by Side Diff: deps2git/deps2submodules.py

Issue 10544140: Sometimes DEPS will not pin a revision for a dependency, but just let it float (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: Minimize work to find remote HEAD for floating dependencies Created 8 years, 6 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 """Read .DEPS.git and use the information to update git submodules""" 6 """Read .DEPS.git and use the information to update git submodules"""
7 7
8 import os 8 import os
9 import subprocess 9 import subprocess
10 import sys 10 import sys
11 11
12 from deps_utils import GetDepsContent 12 from deps_utils import GetDepsContent
13 13
14 14
15 def CollateDeps(deps_content): 15 def CollateDeps(deps_content):
16 """ 16 """
17 Take the output of deps_utils.GetDepsContent and return a hash of: 17 Take the output of deps_utils.GetDepsContent and return a hash of:
18 18
19 { submod_name : [ submod_os, submod_url, submod_sha1 ], ... } 19 { submod_name : [ submod_os, submod_url, submod_sha1 ], ... }
20 """ 20 """
21 fixdep = lambda x: x[4:] if x.startswith('src/') else x 21 fixdep = lambda x: x[4:] if x.startswith('src/') else x
22 spliturl = lambda x: x.split('@', 1) 22 spliturl = lambda x: list(x.partition('@')[0::2])
23 submods = {} 23 submods = {}
24 for (dep, url) in deps_content[0].iteritems(): 24 for (dep, url) in deps_content[0].iteritems():
25 submods[fixdep(dep)] = ['all'] + spliturl(url) 25 submods[fixdep(dep)] = ['all'] + spliturl(url)
26 for (deps_os, val) in deps_content[1].iteritems(): 26 for (deps_os, val) in deps_content[1].iteritems():
27 for (dep, url) in val.iteritems(): 27 for (dep, url) in val.iteritems():
28 submods[fixdep(dep)] = [deps_os] + spliturl(url) 28 submods[fixdep(dep)] = [deps_os] + spliturl(url)
29 return submods 29 return submods
30 30
31 31
32 def WriteGitmodules(submods): 32 def WriteGitmodules(submods):
33 """ 33 """
34 Take the output of CollateDeps, use it to write a .gitmodules file and 34 Take the output of CollateDeps, use it to write a .gitmodules file and
35 add submodules to the git index. 35 add submodules to the git index.
36 """ 36 """
37 fh = open('.gitmodules', 'w') 37 fh = open('.gitmodules', 'w')
38 for submod in sorted(submods.keys()): 38 for submod in sorted(submods.keys()):
39 [submod_os, submod_url, submod_sha1] = submods[submod] 39 [submod_os, submod_url, submod_sha1] = submods[submod]
40 print >>fh, '[submodule "%s"]' % submod 40 print >>fh, '[submodule "%s"]' % submod
41 print >>fh, '\tpath = %s' % submod 41 print >>fh, '\tpath = %s' % submod
42 print >>fh, '\turl = %s' % submod_url 42 print >>fh, '\turl = %s' % submod_url
43 print >>fh, '\tos = %s' % submod_os 43 print >>fh, '\tos = %s' % submod_os
44 if not submod_sha1:
45 # We don't know what sha1 to register, so we have to infer it from the
46 # submodule's origin/master.
47 if not os.path.exists(os.path.join(submod, '.git')):
48 # Not cloned yet
49 subprocess.check_call(['git', 'clone', '-n', submod_url, submod])
50 else:
51 # Already cloned; let's fetch
52 subprocess.check_call(['git', 'fetch', 'origin'], cwd=submod)
53 sub = subprocess.Popen(['git', 'rev-list', 'origin/HEAD^!'],
54 cwd=submod, stdout=subprocess.PIPE)
55 submod_sha1 = sub.communicate()[0].rstrip()
44 subprocess.check_call(['git', 'update-index', '--add', 56 subprocess.check_call(['git', 'update-index', '--add',
45 '--cacheinfo', '160000', submod_sha1, submod]) 57 '--cacheinfo', '160000', submod_sha1, submod])
46 fh.close() 58 fh.close()
47 subprocess.check_call(['git', 'add', '.gitmodules']) 59 subprocess.check_call(['git', 'add', '.gitmodules'])
48 60
49 61
50 def RemoveObsoleteSubmodules(): 62 def RemoveObsoleteSubmodules():
51 """ 63 """
52 Delete from the git repository any submodules which aren't in .gitmodules. 64 Delete from the git repository any submodules which aren't in .gitmodules.
53 """ 65 """
(...skipping 17 matching lines...) Expand all
71 83
72 def main(): 84 def main():
73 deps_file = sys.argv[1] if len(sys.argv) > 1 else '.DEPS.git' 85 deps_file = sys.argv[1] if len(sys.argv) > 1 else '.DEPS.git'
74 WriteGitmodules(CollateDeps(GetDepsContent(deps_file))) 86 WriteGitmodules(CollateDeps(GetDepsContent(deps_file)))
75 RemoveObsoleteSubmodules() 87 RemoveObsoleteSubmodules()
76 return 0 88 return 0
77 89
78 90
79 if __name__ == '__main__': 91 if __name__ == '__main__':
80 sys.exit(main()) 92 sys.exit(main())
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