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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 def exists(self): | 108 def exists(self): |
109 return os.path.exists(os.path.join(os.getcwd(), self.root)) | 109 return os.path.exists(os.path.join(os.getcwd(), self.root)) |
110 | 110 |
111 def init(self): | 111 def init(self): |
112 # Configure and do the gclient checkout. | 112 # Configure and do the gclient checkout. |
113 self.run_gclient('config', '--spec', self.spec['gclient_spec']) | 113 self.run_gclient('config', '--spec', self.spec['gclient_spec']) |
114 sync_cmd = ['sync'] | 114 sync_cmd = ['sync'] |
115 if self.options.nohooks: | 115 if self.options.nohooks: |
116 sync_cmd.append('--nohooks') | 116 sync_cmd.append('--nohooks') |
| 117 if self.options.no_history: |
| 118 sync_cmd.append('--no-history') |
117 if self.spec.get('with_branch_heads', False): | 119 if self.spec.get('with_branch_heads', False): |
118 sync_cmd.append('--with_branch_heads') | 120 sync_cmd.append('--with_branch_heads') |
119 self.run_gclient(*sync_cmd) | 121 self.run_gclient(*sync_cmd) |
120 | 122 |
121 # Configure git. | 123 # Configure git. |
122 wd = os.path.join(self.base, self.root) | 124 wd = os.path.join(self.base, self.root) |
123 if self.options.dry_run: | 125 if self.options.dry_run: |
124 print 'cd %s' % wd | 126 print 'cd %s' % wd |
125 self.run_git( | 127 self.run_git( |
126 'submodule', 'foreach', | 128 'submodule', 'foreach', |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 usage: %s [options] <recipe> [--property=value [--property2=value2 ...]] | 202 usage: %s [options] <recipe> [--property=value [--property2=value2 ...]] |
201 | 203 |
202 This script can be used to download the Chromium sources. See | 204 This script can be used to download the Chromium sources. See |
203 http://www.chromium.org/developers/how-tos/get-the-code | 205 http://www.chromium.org/developers/how-tos/get-the-code |
204 for full usage instructions. | 206 for full usage instructions. |
205 | 207 |
206 Valid options: | 208 Valid options: |
207 -h, --help, help Print this message. | 209 -h, --help, help Print this message. |
208 --nohooks Don't run hooks after checkout. | 210 --nohooks Don't run hooks after checkout. |
209 -n, --dry-run Don't run commands, only print them. | 211 -n, --dry-run Don't run commands, only print them. |
| 212 --no-history Perform shallow clones, don't fetch the full git history. |
210 """ % os.path.basename(sys.argv[0])) | 213 """ % os.path.basename(sys.argv[0])) |
211 sys.exit(bool(msg)) | 214 sys.exit(bool(msg)) |
212 | 215 |
213 | 216 |
214 def handle_args(argv): | 217 def handle_args(argv): |
215 """Gets the recipe name from the command line arguments.""" | 218 """Gets the recipe name from the command line arguments.""" |
216 if len(argv) <= 1: | 219 if len(argv) <= 1: |
217 usage('Must specify a recipe.') | 220 usage('Must specify a recipe.') |
218 if argv[1] in ('-h', '--help', 'help'): | 221 if argv[1] in ('-h', '--help', 'help'): |
219 usage() | 222 usage() |
220 | 223 |
221 dry_run = False | 224 dry_run = False |
222 nohooks = False | 225 nohooks = False |
| 226 no_history = False |
223 while len(argv) >= 2: | 227 while len(argv) >= 2: |
224 arg = argv[1] | 228 arg = argv[1] |
225 if not arg.startswith('-'): | 229 if not arg.startswith('-'): |
226 break | 230 break |
227 argv.pop(1) | 231 argv.pop(1) |
228 if arg in ('-n', '--dry-run'): | 232 if arg in ('-n', '--dry-run'): |
229 dry_run = True | 233 dry_run = True |
230 elif arg == '--nohooks': | 234 elif arg == '--nohooks': |
231 nohooks = True | 235 nohooks = True |
| 236 elif arg == '--no-history': |
| 237 no_history = True |
232 else: | 238 else: |
233 usage('Invalid option %s.' % arg) | 239 usage('Invalid option %s.' % arg) |
234 | 240 |
235 def looks_like_arg(arg): | 241 def looks_like_arg(arg): |
236 return arg.startswith('--') and arg.count('=') == 1 | 242 return arg.startswith('--') and arg.count('=') == 1 |
237 | 243 |
238 bad_parms = [x for x in argv[2:] if not looks_like_arg(x)] | 244 bad_parms = [x for x in argv[2:] if not looks_like_arg(x)] |
239 if bad_parms: | 245 if bad_parms: |
240 usage('Got bad arguments %s' % bad_parms) | 246 usage('Got bad arguments %s' % bad_parms) |
241 | 247 |
242 recipe = argv[1] | 248 recipe = argv[1] |
243 props = argv[2:] | 249 props = argv[2:] |
244 return optparse.Values({'dry_run':dry_run, 'nohooks':nohooks }), recipe, props | 250 return ( |
| 251 optparse.Values( |
| 252 {'dry_run':dry_run, 'nohooks':nohooks, 'no_history': no_history }), |
| 253 recipe, |
| 254 props) |
245 | 255 |
246 | 256 |
247 def run_recipe_fetch(recipe, props, aliased=False): | 257 def run_recipe_fetch(recipe, props, aliased=False): |
248 """Invoke a recipe's fetch method with the passed-through args | 258 """Invoke a recipe's fetch method with the passed-through args |
249 and return its json output as a python object.""" | 259 and return its json output as a python object.""" |
250 recipe_path = os.path.abspath(os.path.join(SCRIPT_PATH, 'recipes', recipe)) | 260 recipe_path = os.path.abspath(os.path.join(SCRIPT_PATH, 'recipes', recipe)) |
251 if not os.path.exists(recipe_path + '.py'): | 261 if not os.path.exists(recipe_path + '.py'): |
252 print "Could not find a recipe for %s" % recipe | 262 print "Could not find a recipe for %s" % recipe |
253 sys.exit(1) | 263 sys.exit(1) |
254 | 264 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 303 |
294 | 304 |
295 def main(): | 305 def main(): |
296 options, recipe, props = handle_args(sys.argv) | 306 options, recipe, props = handle_args(sys.argv) |
297 spec, root = run_recipe_fetch(recipe, props) | 307 spec, root = run_recipe_fetch(recipe, props) |
298 return run(options, spec, root) | 308 return run(options, spec, root) |
299 | 309 |
300 | 310 |
301 if __name__ == '__main__': | 311 if __name__ == '__main__': |
302 sys.exit(main()) | 312 sys.exit(main()) |
OLD | NEW |