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

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

Powered by Google App Engine
This is Rietveld 408576698