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

Side by Side Diff: deps2git.py

Issue 281183003: Eliminate redundant work and control parallelism. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/deps2git
Patch Set: Created 6 years, 7 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 | git_tools.py » ('j') | 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 """Convert SVN based DEPS into .DEPS.git for use with NewGit.""" 6 """Convert SVN based DEPS into .DEPS.git for use with NewGit."""
7 7
8 import collections 8 import collections
9 from cStringIO import StringIO
9 import json 10 import json
10 import optparse 11 import optparse
11 import os 12 import os
12 import Queue 13 import Queue
13 import shutil 14 import shutil
14 import subprocess 15 import subprocess
15 import sys 16 import sys
17 import threading
16 import time 18 import time
17 19
18 from multiprocessing.pool import ThreadPool
19
20 import deps_utils 20 import deps_utils
21 import git_tools 21 import git_tools
22 import svn_to_git_public 22 import svn_to_git_public
23 23
24 try:
25 import git_cache
26 except ImportError:
27 for p in os.environ['PATH'].split(os.pathsep):
28 if (os.path.basename(p) == 'depot_tools' and
29 os.path.exists(os.path.join(p, 'git_cache.py'))):
30 sys.path.append(p)
31 import git_cache
32
33 Job = collections.namedtuple(
34 'Job',
35 ['dep', 'git_url', 'dep_url', 'path', 'git_host', 'dep_rev', 'svn_branch'])
36
37 ConversionResults = collections.namedtuple(
38 'ConversionResults',
39 ['new_deps', 'deps_vars', 'bad_git_urls', 'bad_dep_urls', 'bad_git_hash'])
24 40
25 # This is copied from depot_tools/gclient.py 41 # This is copied from depot_tools/gclient.py
26 DEPS_OS_CHOICES = { 42 DEPS_OS_CHOICES = {
27 "win32": "win", 43 "win32": "win",
28 "win": "win", 44 "win": "win",
29 "cygwin": "win", 45 "cygwin": "win",
30 "darwin": "mac", 46 "darwin": "mac",
31 "mac": "mac", 47 "mac": "mac",
32 "unix": "unix", 48 "unix": "unix",
33 "linux": "unix", 49 "linux": "unix",
34 "linux2": "unix", 50 "linux2": "unix",
35 "linux3": "unix", 51 "linux3": "unix",
36 "android": "android", 52 "android": "android",
37 } 53 }
38 54
55
39 def SplitScmUrl(url): 56 def SplitScmUrl(url):
40 """Given a repository, return a set containing the URL and the revision.""" 57 """Given a repository, return a set containing the URL and the revision."""
41 url_split = url.split('@') 58 url_split = url.split('@')
42 scm_url = url_split[0] 59 scm_url = url_split[0]
43 scm_rev = 'HEAD' 60 scm_rev = 'HEAD'
44 if len(url_split) == 2: 61 if len(url_split) == 2:
45 scm_rev = url_split[1] 62 scm_rev = url_split[1]
46 return (scm_url, scm_rev) 63 return (scm_url, scm_rev)
47 64
48 65
49 def SvnRevToGitHash(svn_rev, git_url, repos_path, workspace, dep_path, 66 def SvnRevToGitHash(
50 git_host, svn_branch_name=None, cache_dir=None): 67 svn_rev, git_url, repos_path, workspace, dep_path, git_host,
68 svn_branch_name=None, cache_dir=None, outbuf=None, shallow=None):
51 """Convert a SVN revision to a Git commit id.""" 69 """Convert a SVN revision to a Git commit id."""
52 git_repo = None 70 git_repo = None
53 if git_url.startswith(git_host): 71 if git_url.startswith(git_host):
54 git_repo = git_url.replace(git_host, '') 72 git_repo = git_url.replace(git_host, '')
55 else: 73 else:
56 raise Exception('Unknown git server %s, host %s' % (git_url, git_host)) 74 raise RuntimeError('Unknown git server %s, host %s' % (git_url, git_host))
57 if repos_path is None and workspace is None and cache_dir is None: 75 if repos_path is None and workspace is None and cache_dir is None:
58 # We're running without a repository directory (i.e. no -r option). 76 # We're running without a repository directory (i.e. no -r option).
59 # We cannot actually find the commit id, but this mode is useful 77 # We cannot actually find the commit id, but this mode is useful
60 # just for testing the URL mappings. Produce an output file that 78 # just for testing the URL mappings. Produce an output file that
61 # can't actually be used, but can be eyeballed for correct URLs. 79 # can't actually be used, but can be eyeballed for correct URLs.
62 return 'xxx-r%s' % svn_rev 80 return 'xxx-r%s' % svn_rev
63 if repos_path: 81 if repos_path:
64 mirror = True 82 mirror = True
65 git_repo_path = os.path.join(repos_path, git_repo) 83 git_repo_path = os.path.join(repos_path, git_repo)
66 if not os.path.exists(git_repo_path) or not os.listdir(git_repo_path): 84 if not os.path.exists(git_repo_path) or not os.listdir(git_repo_path):
67 git_tools.Clone(git_url, git_repo_path, mirror) 85 git_tools.Clone(git_url, git_repo_path, mirror, outbuf)
68 elif cache_dir: 86 elif cache_dir:
69 mirror = 'bare' 87 mirror = True
70 git_tools.Clone(git_url, None, mirror, cache_dir=cache_dir) 88 git_repo_path = git_tools.PopulateCache(git_url, shallow)
71 git_repo_path = git_tools.GetCacheRepoDir(git_url, cache_dir)
72 else: 89 else:
73 mirror = False 90 mirror = False
74 git_repo_path = os.path.join(workspace, dep_path) 91 git_repo_path = os.path.join(workspace, dep_path)
75 if (os.path.exists(git_repo_path) and 92 if (os.path.exists(git_repo_path) and
76 not os.path.exists(os.path.join(git_repo_path, '.git'))): 93 not os.path.exists(os.path.join(git_repo_path, '.git'))):
77 # shutil.rmtree is unreliable on windows 94 # shutil.rmtree is unreliable on windows
78 if sys.platform == 'win32': 95 if sys.platform == 'win32':
79 for _ in xrange(3): 96 for _ in xrange(3):
80 if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s', 97 if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s',
81 os.path.normcase(git_repo_path)]): 98 os.path.normcase(git_repo_path)]):
82 break 99 break
83 time.sleep(3) 100 time.sleep(3)
84 else: 101 else:
85 shutil.rmtree(git_repo_path) 102 shutil.rmtree(git_repo_path)
86 if not os.path.exists(git_repo_path): 103 if not os.path.exists(git_repo_path):
87 git_tools.Clone(git_url, git_repo_path, mirror) 104 git_tools.Clone(git_url, git_repo_path, mirror, outbuf)
88 105
89 if svn_branch_name: 106 if svn_branch_name:
90 # svn branches are mirrored with: 107 # svn branches are mirrored with:
91 # branches = branches/*:refs/remotes/branch-heads/* 108 # branches = branches/*:refs/remotes/branch-heads/*
92 if mirror: 109 if mirror:
93 refspec = 'refs/branch-heads/' + svn_branch_name 110 refspec = 'refs/branch-heads/' + svn_branch_name
94 else: 111 else:
95 refspec = 'refs/remotes/branch-heads/' + svn_branch_name 112 refspec = 'refs/remotes/branch-heads/' + svn_branch_name
96 else: 113 else:
97 if mirror: 114 if mirror:
98 refspec = 'refs/heads/master' 115 refspec = 'refs/heads/master'
99 else: 116 else:
100 refspec = 'refs/remotes/origin/master' 117 refspec = 'refs/remotes/origin/master'
101 118
102 # Work-around for: 119 # Work-around for:
103 # http://code.google.com/p/chromium/issues/detail?id=362222 120 # http://code.google.com/p/chromium/issues/detail?id=362222
104 if (git_url.startswith('https://chromium.googlesource.com/external/pefile') 121 if (git_url.startswith('https://chromium.googlesource.com/external/pefile')
105 and int(svn_rev) == 63): 122 and int(svn_rev) in (63, 141)):
106 return '1ceaa279daa62b71e3431e58f68be6a96dd1519a' 123 return '1ceaa279daa62b71e3431e58f68be6a96dd1519a'
107 124
108 try: 125 return git_tools.Search(git_repo_path, svn_rev, mirror, refspec, git_url)
109 return git_tools.Search(git_repo_path, svn_rev, mirror, refspec, git_url)
110 except Exception:
111 print >> sys.stderr, '%s <-> ERROR' % git_repo_path
112 raise
113 126
114 def ConvertDepsToGit(deps, options, deps_vars, svn_to_git_objs):
115 """Convert a 'deps' section in a DEPS file from SVN to Git."""
116 new_deps = {}
117 bad_git_urls = set([])
118 bad_dep_urls = []
119 bad_override = []
120 bad_git_hash = []
121 127
122 # Populate our deps list. 128 def MessageMain(message_q, threads):
123 deps_to_process = {} 129 while True:
124 for dep, dep_url in deps.iteritems(): 130 try:
125 if not dep_url: # dep is 'None' and emitted to exclude the dep 131 msg = message_q.get(True, 10)
126 new_deps[dep] = None 132 except Queue.Empty:
133 print >> sys.stderr, 'Still working on:'
134 for s in sorted([th.working_on for th in threads if th.working_on]):
135 print >> sys.stderr, ' %s' % s
127 continue 136 continue
137 if msg is Queue.Empty:
138 return
139 if msg:
140 print >> sys.stderr, msg
128 141
129 # Get the URL and the revision/hash for this dependency.
130 dep_url, dep_rev = SplitScmUrl(deps[dep])
131 142
132 path = dep 143 def ConvertDepMain(dep_q, message_q, options, results):
133 git_url = dep_url 144 cur_thread = threading.current_thread()
134 svn_branch = None 145 while True:
135 git_host = dep_url 146 try:
147 job = dep_q.get(False)
148 dep, git_url, dep_url, path, git_host, dep_rev, svn_branch = job
149 cur_thread.working_on = dep
150 except Queue.Empty:
151 cur_thread.working_on = None
152 return
136 153
137 if not dep_url.endswith('.git'): 154 outbuf = StringIO()
138 # Convert this SVN URL to a Git URL. 155 def _print(s):
139 for svn_git_converter in svn_to_git_objs: 156 for l in s.splitlines():
140 converted_data = svn_git_converter.SvnUrlToGitUrl(dep, dep_url) 157 outbuf.write('[%s] %s\n' % (dep, l))
141 if converted_data:
142 path, git_url, git_host = converted_data[:3]
143 if len(converted_data) > 3:
144 svn_branch = converted_data[3]
145 break
146 else:
147 # Make all match failures fatal to catch errors early. When a match is
148 # found, we break out of the loop so the exception is not thrown.
149 if options.no_fail_fast:
150 bad_dep_urls.append(dep_url)
151 continue
152 raise Exception('No match found for %s' % dep_url)
153 158
154 Job = collections.namedtuple('Job', ['git_url', 'dep_url', 'path',
155 'git_host', 'dep_rev', 'svn_branch'])
156 deps_to_process[dep] = Job(
157 git_url, dep_url, path, git_host, dep_rev, svn_branch)
158
159 # Lets pre-cache all of the git repos now if we have cache_dir turned on.
160 if options.cache_dir:
161 if not os.path.isdir(options.cache_dir):
162 os.makedirs(options.cache_dir)
163 pool = ThreadPool(processes=len(deps_to_process))
164 output_queue = Queue.Queue()
165 num_threads = 0
166 for git_url, _, _, _, _, _ in deps_to_process.itervalues():
167 print 'Populating cache for %s' % git_url
168 num_threads += 1
169 pool.apply_async(git_tools.Clone, (git_url, None, 'bare',
170 output_queue, options.cache_dir,
171 options.shallow))
172 pool.close()
173
174 # Stream stdout line by line.
175 sec_since = 0
176 while num_threads > 0:
177 try:
178 line = output_queue.get(block=True, timeout=1)
179 sec_since = 0
180 except Queue.Empty:
181 sec_since += 1
182 line = ('Main> Heartbeat ping. We are still alive!! '
183 'Seconds since last output: %d sec' % sec_since)
184 if line is None:
185 num_threads -= 1
186 else:
187 print line
188 pool.join()
189
190 for dep, items in deps_to_process.iteritems():
191 git_url, dep_url, path, git_host, dep_rev, svn_branch = items
192 if options.verify: 159 if options.verify:
193 delay = 0.5 160 delay = 0.5
194 success = False 161 success = False
195 for try_index in range(1, 6): 162 for try_index in range(1, 6):
196 print >> sys.stderr, 'checking %s (try #%d) ...' % (git_url, try_index), 163 _print('checking %s (try #%d) ...' % (git_url, try_index))
197 if git_tools.Ping(git_url, verbose=True): 164 if git_tools.Ping(git_url, verbose=True):
198 print >> sys.stderr, ' success' 165 _print(' success')
199 success = True 166 success = True
200 break 167 break
201 168 _print(' failure')
202 print >> sys.stderr, ' failure' 169 _print('sleeping for %.01f seconds ...' % delay)
203 print >> sys.stderr, 'sleeping for %.01f seconds ...' % delay
204 time.sleep(delay) 170 time.sleep(delay)
205 delay *= 2 171 delay *= 2
206 172
207 if not success: 173 if not success:
208 bad_git_urls.update([git_url]) 174 results.bad_git_urls.add(git_url)
209 175
210 # Get the Git hash based off the SVN rev. 176 # Get the Git hash based off the SVN rev.
211 git_hash = '' 177 git_hash = ''
212 if dep_rev != 'HEAD': 178 if dep_rev != 'HEAD':
213 # Pass-through the hash for Git repositories. Resolve the hash for 179 # Pass-through the hash for Git repositories. Resolve the hash for
214 # subversion repositories. 180 # subversion repositories.
215 if dep_url.endswith('.git'): 181 if dep_url.endswith('.git'):
216 git_hash = '@%s' % dep_rev 182 git_hash = '@%s' % dep_rev
217 else: 183 else:
218 try: 184 try:
219 git_hash = '@%s' % SvnRevToGitHash( 185 git_hash = '@%s' % SvnRevToGitHash(
220 dep_rev, git_url, options.repos, options.workspace, path, 186 dep_rev, git_url, options.repos, options.workspace, path,
221 git_host, svn_branch, options.cache_dir) 187 git_host, svn_branch, options.cache_dir)
222 except Exception as e: 188 except Exception as e:
223 if options.no_fail_fast: 189 if options.no_fail_fast:
224 bad_git_hash.append(e) 190 results.bad_git_hash.append(e)
225 continue 191 continue
226 raise 192 raise
227 193
228 # If this is webkit, we need to add the var for the hash. 194 # If this is webkit, we need to add the var for the hash.
229 if dep == 'src/third_party/WebKit' and dep_rev: 195 if dep == 'src/third_party/WebKit' and dep_rev:
230 deps_vars['webkit_rev'] = git_hash 196 results.deps_vars['webkit_rev'] = git_hash
231 git_hash = 'VAR_WEBKIT_REV' 197 git_hash = 'VAR_WEBKIT_REV'
232 198
233 # Hack to preserve the angle_revision variable in .DEPS.git. 199 # Hack to preserve the angle_revision variable in .DEPS.git.
234 # This will go away as soon as deps2git does. 200 # This will go away as soon as deps2git does.
235 if dep == 'src/third_party/angle' and git_hash: 201 if dep == 'src/third_party/angle' and git_hash:
236 # Cut the leading '@' so this variable has the same semantics in 202 # Cut the leading '@' so this variable has the same semantics in
237 # DEPS and .DEPS.git. 203 # DEPS and .DEPS.git.
238 deps_vars['angle_revision'] = git_hash[1:] 204 results.deps_vars['angle_revision'] = git_hash[1:]
239 git_hash = 'VAR_ANGLE_REVISION' 205 git_hash = 'VAR_ANGLE_REVISION'
240 206
241 # Add this Git dep to the new deps. 207 # Add this Git dep to the new deps.
242 new_deps[path] = '%s%s' % (git_url, git_hash) 208 results.new_deps[path] = '%s%s' % (git_url, git_hash)
243 209
244 return new_deps, bad_git_urls, bad_dep_urls, bad_override, bad_git_hash 210 message_q.put(outbuf.getvalue())
211
212
213 def ConvertDepsToGit(deps, options, deps_vars, svn_to_git_objs):
214 """Convert a 'deps' section in a DEPS file from SVN to Git."""
215 results = ConversionResults(
216 new_deps={},
217 deps_vars=deps_vars,
218 bad_git_urls=set([]),
219 bad_dep_urls=[],
220 bad_git_hash=[]
221 )
222
223 # Populate our deps list.
224 deps_to_process = Queue.Queue()
225 for dep, dep_url in deps.iteritems():
226 if not dep_url: # dep is 'None' and emitted to exclude the dep
227 results.new_deps[dep] = None
228 continue
229
230 # Get the URL and the revision/hash for this dependency.
231 dep_url, dep_rev = SplitScmUrl(deps[dep])
232
233 path = dep
234 git_url = dep_url
235 svn_branch = None
236 git_host = dep_url
237
238 if not dep_url.endswith('.git'):
239 # Convert this SVN URL to a Git URL.
240 for svn_git_converter in svn_to_git_objs:
241 converted_data = svn_git_converter.SvnUrlToGitUrl(dep, dep_url)
242 if converted_data:
243 path, git_url, git_host = converted_data[:3]
244 if len(converted_data) > 3:
245 svn_branch = converted_data[3]
246 break
247 else:
248 # Make all match failures fatal to catch errors early. When a match is
249 # found, we break out of the loop so the exception is not thrown.
250 if options.no_fail_fast:
251 results.bad_dep_urls.append(dep_url)
252 continue
253 raise RuntimeError('No match found for %s' % dep_url)
254
255 deps_to_process.put(
256 Job(dep, git_url, dep_url, path, git_host, dep_rev, svn_branch))
257
258 threads = []
259 message_q = Queue.Queue()
260 thread_args = (deps_to_process, message_q, options, results)
261 num_threads = options.num_threads or deps_to_process.qsize()
262 for _ in xrange(num_threads):
263 th = threading.Thread(target=ConvertDepMain, args=thread_args)
264 th.working_on = None
265 th.start()
266 threads.append(th)
267 message_th = threading.Thread(target=MessageMain, args=(message_q, threads))
268 message_th.start()
269
270 for th in threads:
271 th.join()
272 message_q.put(Queue.Empty)
273 message_th.join()
274
275 return results
245 276
246 277
247 def main(): 278 def main():
248 parser = optparse.OptionParser() 279 parser = optparse.OptionParser()
249 parser.add_option('-d', '--deps', default='DEPS', 280 parser.add_option('-d', '--deps', default='DEPS',
250 help='path to the DEPS file to convert') 281 help='path to the DEPS file to convert')
251 parser.add_option('-o', '--out', 282 parser.add_option('-o', '--out',
252 help='path to the converted DEPS file (default: stdout)') 283 help='path to the converted DEPS file (default: stdout)')
284 parser.add_option('-j', '--num-threads', type='int', default=4,
285 help='Maximum number of threads')
253 parser.add_option('-t', '--type', 286 parser.add_option('-t', '--type',
254 help='[DEPRECATED] type of DEPS file (public, etc)') 287 help='[DEPRECATED] type of DEPS file (public, etc)')
255 parser.add_option('-x', '--extra-rules', 288 parser.add_option('-x', '--extra-rules',
256 help='Path to file with additional conversion rules.') 289 help='Path to file with additional conversion rules.')
257 parser.add_option('-r', '--repos', 290 parser.add_option('-r', '--repos',
258 help='path to the directory holding all the Git repos') 291 help='path to the directory holding all the Git repos')
259 parser.add_option('-w', '--workspace', metavar='PATH', 292 parser.add_option('-w', '--workspace', metavar='PATH',
260 help='top level of a git-based gclient checkout') 293 help='top level of a git-based gclient checkout')
261 parser.add_option('-c', '--cache_dir', 294 parser.add_option('-c', '--cache_dir',
262 help='top level of a gclient git cache diretory.') 295 help='top level of a gclient git cache diretory.')
(...skipping 20 matching lines...) Expand all
283 'svn_to_git_%s.py' % options.type) 316 'svn_to_git_%s.py' % options.type)
284 if options.cache_dir and options.repos: 317 if options.cache_dir and options.repos:
285 parser.error('Can\'t specify both cache_dir and repos at the same time.') 318 parser.error('Can\'t specify both cache_dir and repos at the same time.')
286 if options.shallow and not options.cache_dir: 319 if options.shallow and not options.cache_dir:
287 parser.error('--shallow only supported with --cache_dir.') 320 parser.error('--shallow only supported with --cache_dir.')
288 321
289 if options.cache_dir: 322 if options.cache_dir:
290 options.cache_dir = os.path.abspath(options.cache_dir) 323 options.cache_dir = os.path.abspath(options.cache_dir)
291 324
292 if options.extra_rules and not os.path.exists(options.extra_rules): 325 if options.extra_rules and not os.path.exists(options.extra_rules):
293 raise Exception('Can\'t locate rules file "%s".' % options.extra_rules) 326 raise RuntimeError('Can\'t locate rules file "%s".' % options.extra_rules)
294 327
295 # Create a var containing the Git and Webkit URL, this will make it easy for 328 # Create a var containing the Git and Webkit URL, this will make it easy for
296 # people to use a mirror instead. 329 # people to use a mirror instead.
297 git_url = 'https://chromium.googlesource.com' 330 git_url = 'https://chromium.googlesource.com'
298 deps_vars = { 331 deps_vars = {
299 'git_url': git_url, 332 'git_url': git_url,
300 'webkit_url': git_url + '/chromium/blink.git', 333 'webkit_url': git_url + '/chromium/blink.git',
301 } 334 }
302 335
303 # Find and load svn_to_git_* modules that handle the URL mapping. 336 # Find and load svn_to_git_* modules that handle the URL mapping.
(...skipping 21 matching lines...) Expand all
325 print >> sys.stderr, 'Could not parse %s' % gclient_file 358 print >> sys.stderr, 'Could not parse %s' % gclient_file
326 raise 359 raise
327 target_os = gclient_dict.get('target_os', []) 360 target_os = gclient_dict.get('target_os', [])
328 if not target_os or not gclient_dict.get('target_os_only'): 361 if not target_os or not gclient_dict.get('target_os_only'):
329 target_os.append(DEPS_OS_CHOICES.get(sys.platform, 'unix')) 362 target_os.append(DEPS_OS_CHOICES.get(sys.platform, 'unix'))
330 if 'all' not in target_os: 363 if 'all' not in target_os:
331 deps_os = dict([(k, v) for k, v in deps_os.iteritems() if k in target_os]) 364 deps_os = dict([(k, v) for k, v in deps_os.iteritems() if k in target_os])
332 if not options.cache_dir and 'cache_dir' in gclient_dict: 365 if not options.cache_dir and 'cache_dir' in gclient_dict:
333 options.cache_dir = os.path.abspath(gclient_dict['cache_dir']) 366 options.cache_dir = os.path.abspath(gclient_dict['cache_dir'])
334 367
368 if options.cache_dir:
369 git_cache.Mirror.SetCachePath(options.cache_dir)
370 else:
371 try:
372 options.cache_dir = git_cache.Mirror.GetCachePath()
373 except RuntimeError:
374 pass
375
335 # Do general pre-processing of the DEPS data. 376 # Do general pre-processing of the DEPS data.
336 for svn_git_converter in svn_to_git_objs: 377 for svn_git_converter in svn_to_git_objs:
337 if hasattr(svn_git_converter, 'CleanDeps'): 378 if hasattr(svn_git_converter, 'CleanDeps'):
338 svn_git_converter.CleanDeps(deps, deps_os, include_rules, 379 svn_git_converter.CleanDeps(deps, deps_os, include_rules,
339 skip_child_includes, hooks) 380 skip_child_includes, hooks)
340 381
341 # Convert the DEPS file to Git. 382 # Convert the DEPS file to Git.
342 deps, baddeps, badmaps, badvars, badhashes = ConvertDepsToGit( 383 results = ConvertDepsToGit(
343 deps, options, deps_vars, svn_to_git_objs) 384 deps, options, deps_vars, svn_to_git_objs)
344 for os_dep in deps_os: 385 for os_dep in deps_os:
345 result = ConvertDepsToGit(deps_os[os_dep], options, deps_vars, 386 os_results = ConvertDepsToGit(deps_os[os_dep], options, deps_vars,
346 svn_to_git_objs) 387 svn_to_git_objs)
347 deps_os[os_dep] = result[0] 388 deps_os[os_dep] = os_results.new_deps
348 baddeps = baddeps.union(result[1]) 389 results.bad_git_urls.update(os_results.bad_git_urls)
349 badmaps.extend(result[2]) 390 results.bad_dep_urls.extend(os_results.bad_dep_urls)
350 badvars.extend(result[3]) 391 results.bad_git_hash.extend(os_results.bad_git_hash)
351 badhashes.extend(result[4])
352 392
353 if options.json: 393 if options.json:
354 with open(options.json, 'w') as f: 394 with open(options.json, 'w') as f:
355 json.dump(list(baddeps), f, sort_keys=True, indent=2) 395 json.dump(list(results.bad_git_urls), f, sort_keys=True, indent=2)
356 396
357 if baddeps: 397 if results.bad_git_urls:
358 print >> sys.stderr, ('\nUnable to resolve the following repositories. ' 398 print >> sys.stderr, ('\nUnable to resolve the following repositories. '
359 'Please make sure\nthat any svn URLs have a git mirror associated with ' 399 'Please make sure\nthat any svn URLs have a git mirror associated with '
360 'them.\nTo see the exact error, run `git ls-remote [repository]` where' 400 'them.\nTo see the exact error, run `git ls-remote [repository]` where'
361 '\n[repository] is the URL ending in .git (strip off the @revision\n' 401 '\n[repository] is the URL ending in .git (strip off the @revision\n'
362 'number.) For more information, visit http://code.google.com\n' 402 'number.) For more information, visit http://code.google.com\n'
363 '/p/chromium/wiki/UsingGit#Adding_new_repositories_to_DEPS.\n') 403 '/p/chromium/wiki/UsingGit#Adding_new_repositories_to_DEPS.\n')
364 for dep in baddeps: 404 for dep in results.bad_git_urls:
365 print >> sys.stderr, ' ' + dep 405 print >> sys.stderr, ' ' + dep
366 if badmaps: 406 if results.bad_dep_urls:
367 print >> sys.stderr, '\nNo mappings found for the following urls:\n' 407 print >> sys.stderr, '\nNo mappings found for the following urls:\n'
368 for bad in badmaps: 408 for bad in results.bad_dep_urls:
369 print >> sys.stderr, ' ' + bad 409 print >> sys.stderr, ' ' + bad
370 if badvars: 410 if results.bad_git_hash:
371 print >> sys.stderr, '\nMissing DEPS variables for overrides:\n'
372 for bad in badvars:
373 print >> sys.stderr, ' ' + bad
374 if badhashes:
375 print >> sys.stderr, '\nsvn rev to git hash failures:\n' 411 print >> sys.stderr, '\nsvn rev to git hash failures:\n'
376 for bad in badhashes: 412 for bad in results.bad_git_hash:
377 print >> sys.stderr, ' ' + str(bad) 413 print >> sys.stderr, ' ' + str(bad)
378 414
379 if baddeps or badmaps or badvars or badhashes: 415 if (results.bad_git_urls or results.bad_dep_urls or results.bad_git_hash):
380 return 2 416 return 2
381 417
382 if options.verify: 418 if options.verify:
383 print >> sys.stderr, ('\nAll referenced repositories were successfully ' 419 print >> sys.stderr, ('\nAll referenced repositories were successfully '
384 'resolved.') 420 'resolved.')
385 return 0 421 return 0
386 422
387 # Write the DEPS file to disk. 423 # Write the DEPS file to disk.
388 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, 424 deps_utils.WriteDeps(options.out, deps_vars, results.new_deps, deps_os,
389 skip_child_includes, hooks) 425 include_rules, skip_child_includes, hooks)
390 return 0 426 return 0
391 427
392 428
393 if '__main__' == __name__: 429 if '__main__' == __name__:
394 sys.exit(main()) 430 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | git_tools.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698