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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
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 '' | 65 return 0 |
66 return subprocess.check_output(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',) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 gclient_spec = 'solutions = [\n%s\n]\n' % '\n'.join(soln_strings) | 126 gclient_spec = 'solutions = [\n%s\n]\n' % '\n'.join(soln_strings) |
127 extra_keys = ['target_os', 'target_os_only'] | 127 extra_keys = ['target_os', 'target_os_only'] |
128 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])) |
129 for key in extra_keys if key in self.spec) | 129 for key in extra_keys if key in self.spec) |
130 return gclient_spec | 130 return gclient_spec |
131 | 131 |
132 def init(self): | 132 def init(self): |
133 # Configure and do the gclient checkout. | 133 # Configure and do the gclient checkout. |
134 self.run_gclient('config', '--spec', self._format_spec()) | 134 self.run_gclient('config', '--spec', self._format_spec()) |
135 sync_cmd = ['sync'] | 135 sync_cmd = ['sync'] |
136 if self.options.nohooks or self.spec.get('fetch_hooks'): | 136 if self.options.nohooks: |
137 sync_cmd.append('--nohooks') | 137 sync_cmd.append('--nohooks') |
138 if self.options.no_history: | 138 if self.options.no_history: |
139 sync_cmd.append('--no-history') | 139 sync_cmd.append('--no-history') |
140 if self.spec.get('with_branch_heads', False): | 140 if self.spec.get('with_branch_heads', False): |
141 sync_cmd.append('--with_branch_heads') | 141 sync_cmd.append('--with_branch_heads') |
142 self.run_gclient(*sync_cmd) | 142 self.run_gclient(*sync_cmd) |
143 | 143 |
144 for cmd in self.spec.get('fetch_hooks', []): | |
145 self.run(cmd) | |
146 if self.spec.get('fetch_hooks') and not self.options.nohooks: | |
147 self.run_gclient('runhooks') | |
148 | |
149 # Configure git. | 144 # Configure git. |
150 wd = os.path.join(self.base, self.root) | 145 wd = os.path.join(self.base, self.root) |
151 if self.options.dry_run: | 146 if self.options.dry_run: |
152 print 'cd %s' % wd | 147 print 'cd %s' % wd |
153 self.run_git( | 148 self.run_git( |
154 'submodule', 'foreach', | 149 'submodule', 'foreach', |
155 'git config -f $toplevel/.git/config submodule.$name.ignore all', | 150 'git config -f $toplevel/.git/config submodule.$name.ignore all', |
156 cwd=wd) | 151 cwd=wd) |
157 self.run_git( | 152 self.run_git( |
158 'config', '--add', 'remote.origin.fetch', | 153 'config', '--add', 'remote.origin.fetch', |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 spec, root = run_recipe_fetch(recipe, props) | 336 spec, root = run_recipe_fetch(recipe, props) |
342 return run(options, spec, root) | 337 return run(options, spec, root) |
343 | 338 |
344 | 339 |
345 if __name__ == '__main__': | 340 if __name__ == '__main__': |
346 try: | 341 try: |
347 sys.exit(main()) | 342 sys.exit(main()) |
348 except KeyboardInterrupt: | 343 except KeyboardInterrupt: |
349 sys.stderr.write('interrupted\n') | 344 sys.stderr.write('interrupted\n') |
350 sys.exit(1) | 345 sys.exit(1) |
OLD | NEW |