OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """ | 6 """ |
7 Tool to perform checkouts in one easy command line! | 7 Tool to perform checkouts in one easy command line! |
8 | 8 |
9 Usage: | 9 Usage: |
10 fetch <recipe> [--property=value [--property2=value2 ...]] | 10 fetch <recipe> [--property=value [--property2=value2 ...]] |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 def init(self): | 56 def init(self): |
57 pass | 57 pass |
58 | 58 |
59 def sync(self): | 59 def sync(self): |
60 pass | 60 pass |
61 | 61 |
62 def run(self, cmd, **kwargs): | 62 def run(self, cmd, **kwargs): |
63 print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd)) | 63 print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd)) |
64 if self.options.dry_run: | 64 if self.options.dry_run: |
65 return 0 | 65 return 0 |
66 return subprocess.check_call(cmd, **kwargs) | 66 return subprocess.check_output(cmd, **kwargs) |
67 | 67 |
68 | 68 |
69 class GclientCheckout(Checkout): | 69 class GclientCheckout(Checkout): |
70 | 70 |
71 def run_gclient(self, *cmd, **kwargs): | 71 def run_gclient(self, *cmd, **kwargs): |
72 if not spawn.find_executable('gclient'): | 72 if not spawn.find_executable('gclient'): |
73 cmd_prefix = (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) | 73 cmd_prefix = (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) |
74 else: | 74 else: |
75 cmd_prefix = ('gclient',) | 75 cmd_prefix = ('gclient',) |
76 return self.run(cmd_prefix + cmd, **kwargs) | 76 return self.run(cmd_prefix + cmd, **kwargs) |
77 | 77 |
| 78 def exists(self): |
| 79 try: |
| 80 gclient_root = self.run_gclient('root').strip() |
| 81 return (os.path.exists(os.path.join(gclient_root, '.gclient')) or |
| 82 os.path.exists(os.path.join(os.getcwd(), self.root))) |
| 83 except subprocess.CalledProcessError: |
| 84 pass |
| 85 return os.path.exists(os.path.join(os.getcwd(), self.root)) |
| 86 |
78 | 87 |
79 class GitCheckout(Checkout): | 88 class GitCheckout(Checkout): |
80 | 89 |
81 def run_git(self, *cmd, **kwargs): | 90 def run_git(self, *cmd, **kwargs): |
82 if sys.platform == 'win32' and not spawn.find_executable('git'): | 91 if sys.platform == 'win32' and not spawn.find_executable('git'): |
83 git_path = os.path.join(SCRIPT_PATH, 'git.bat') | 92 git_path = os.path.join(SCRIPT_PATH, 'git.bat') |
84 else: | 93 else: |
85 git_path = 'git' | 94 git_path = 'git' |
86 return self.run((git_path,) + cmd, **kwargs) | 95 return self.run((git_path,) + cmd, **kwargs) |
87 | 96 |
(...skipping 25 matching lines...) Expand all Loading... |
113 for soln in self.spec['solutions']: | 122 for soln in self.spec['solutions']: |
114 soln_string= '\n'.join(' "%s": %s,' % (key, _format_literal(value)) | 123 soln_string= '\n'.join(' "%s": %s,' % (key, _format_literal(value)) |
115 for key, value in soln.iteritems()) | 124 for key, value in soln.iteritems()) |
116 soln_strings.append(' {\n%s\n },' % soln_string) | 125 soln_strings.append(' {\n%s\n },' % soln_string) |
117 gclient_spec = 'solutions = [\n%s\n]\n' % '\n'.join(soln_strings) | 126 gclient_spec = 'solutions = [\n%s\n]\n' % '\n'.join(soln_strings) |
118 extra_keys = ['target_os', 'target_os_only'] | 127 extra_keys = ['target_os', 'target_os_only'] |
119 gclient_spec += ''.join('%s = %s\n' % (key, _format_literal(self.spec[key])) | 128 gclient_spec += ''.join('%s = %s\n' % (key, _format_literal(self.spec[key])) |
120 for key in extra_keys if key in self.spec) | 129 for key in extra_keys if key in self.spec) |
121 return gclient_spec | 130 return gclient_spec |
122 | 131 |
123 def exists(self): | |
124 return os.path.exists(os.path.join(os.getcwd(), self.root)) | |
125 | |
126 def init(self): | 132 def init(self): |
127 # Configure and do the gclient checkout. | 133 # Configure and do the gclient checkout. |
128 self.run_gclient('config', '--spec', self._format_spec()) | 134 self.run_gclient('config', '--spec', self._format_spec()) |
129 sync_cmd = ['sync'] | 135 sync_cmd = ['sync'] |
130 if self.options.nohooks: | 136 if self.options.nohooks: |
131 sync_cmd.append('--nohooks') | 137 sync_cmd.append('--nohooks') |
132 if self.options.no_history: | 138 if self.options.no_history: |
133 sync_cmd.append('--no-history') | 139 sync_cmd.append('--no-history') |
134 if self.spec.get('with_branch_heads', False): | 140 if self.spec.get('with_branch_heads', False): |
135 sync_cmd.append('--with_branch_heads') | 141 sync_cmd.append('--with_branch_heads') |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 root: The directory into which the repo expects to be checkout out. | 314 root: The directory into which the repo expects to be checkout out. |
309 """ | 315 """ |
310 assert 'type' in spec | 316 assert 'type' in spec |
311 checkout_type = spec['type'] | 317 checkout_type = spec['type'] |
312 checkout_spec = spec['%s_spec' % checkout_type] | 318 checkout_spec = spec['%s_spec' % checkout_type] |
313 try: | 319 try: |
314 checkout = CheckoutFactory(checkout_type, options, checkout_spec, root) | 320 checkout = CheckoutFactory(checkout_type, options, checkout_spec, root) |
315 except KeyError: | 321 except KeyError: |
316 return 1 | 322 return 1 |
317 if checkout.exists(): | 323 if checkout.exists(): |
318 print 'You appear to already have a checkout. "fetch" is used only' | 324 print 'Your current directory appears to already contain, or be part of, ' |
319 print 'to get new checkouts. Use "gclient sync" to update the checkout.' | 325 print 'a checkout. "fetch" is used only to get new checkouts. Use ' |
| 326 print '"gclient sync" to update existing checkouts.' |
320 print | 327 print |
321 print 'Fetch also does not yet deal with partial checkouts, so if fetch' | 328 print 'Fetch also does not yet deal with partial checkouts, so if fetch' |
322 print 'failed, delete the checkout and start over (crbug.com/230691).' | 329 print 'failed, delete the checkout and start over (crbug.com/230691).' |
323 return 1 | 330 return 1 |
324 return checkout.init() | 331 return checkout.init() |
325 | 332 |
326 | 333 |
327 def main(): | 334 def main(): |
328 options, recipe, props = handle_args(sys.argv) | 335 options, recipe, props = handle_args(sys.argv) |
329 spec, root = run_recipe_fetch(recipe, props) | 336 spec, root = run_recipe_fetch(recipe, props) |
330 return run(options, spec, root) | 337 return run(options, spec, root) |
331 | 338 |
332 | 339 |
333 if __name__ == '__main__': | 340 if __name__ == '__main__': |
334 try: | 341 try: |
335 sys.exit(main()) | 342 sys.exit(main()) |
336 except KeyboardInterrupt: | 343 except KeyboardInterrupt: |
337 sys.stderr.write('interrupted\n') | 344 sys.stderr.write('interrupted\n') |
338 sys.exit(1) | 345 sys.exit(1) |
OLD | NEW |