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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 pass | 53 pass |
54 | 54 |
55 def init(self): | 55 def init(self): |
56 pass | 56 pass |
57 | 57 |
58 def sync(self): | 58 def sync(self): |
59 pass | 59 pass |
60 | 60 |
61 def run(self, cmd, **kwargs): | 61 def run(self, cmd, **kwargs): |
62 print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd)) | 62 print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd)) |
63 if self.options.dryrun: | 63 if self.options.dry_run: |
64 return 0 | 64 return 0 |
65 return subprocess.check_call(cmd, **kwargs) | 65 return subprocess.check_call(cmd, **kwargs) |
66 | 66 |
67 | 67 |
68 class GclientCheckout(Checkout): | 68 class GclientCheckout(Checkout): |
69 | 69 |
70 def run_gclient(self, *cmd, **kwargs): | 70 def run_gclient(self, *cmd, **kwargs): |
71 if not spawn.find_executable('gclient'): | 71 if not spawn.find_executable('gclient'): |
72 cmd_prefix = (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) | 72 cmd_prefix = (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) |
73 else: | 73 else: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 | 114 |
115 # Configure and do the gclient checkout. | 115 # Configure and do the gclient checkout. |
116 self.run_gclient('config', '--spec', self.spec['gclient_spec']) | 116 self.run_gclient('config', '--spec', self.spec['gclient_spec']) |
117 if self.options.nohooks: | 117 if self.options.nohooks: |
118 self.run_gclient('sync', '--nohooks') | 118 self.run_gclient('sync', '--nohooks') |
119 else: | 119 else: |
120 self.run_gclient('sync') | 120 self.run_gclient('sync') |
121 | 121 |
122 # Configure git. | 122 # Configure git. |
123 wd = os.path.join(self.base, self.root) | 123 wd = os.path.join(self.base, self.root) |
124 if self.options.dryrun: | 124 if self.options.dry_run: |
125 print 'cd %s' % wd | 125 print 'cd %s' % wd |
126 self.run_git( | 126 self.run_git( |
127 'submodule', 'foreach', | 127 'submodule', 'foreach', |
128 'git config -f $toplevel/.git/config submodule.$name.ignore all', | 128 'git config -f $toplevel/.git/config submodule.$name.ignore all', |
129 cwd=wd) | 129 cwd=wd) |
130 self.run_git('config', 'diff.ignoreSubmodules', 'all', cwd=wd) | 130 self.run_git('config', 'diff.ignoreSubmodules', 'all', cwd=wd) |
131 | 131 |
132 | 132 |
133 class GclientGitSvnCheckout(GclientGitCheckout, SvnCheckout): | 133 class GclientGitSvnCheckout(GclientGitCheckout, SvnCheckout): |
134 | 134 |
(...skipping 15 matching lines...) Expand all Loading... | |
150 return 1 | 150 return 1 |
151 | 151 |
152 super(GclientGitSvnCheckout, self).init() | 152 super(GclientGitSvnCheckout, self).init() |
153 | 153 |
154 # Configure git-svn. | 154 # Configure git-svn. |
155 for path, svn_spec in git_svn_dirs.iteritems(): | 155 for path, svn_spec in git_svn_dirs.iteritems(): |
156 real_path = os.path.join(*path.split('/')) | 156 real_path = os.path.join(*path.split('/')) |
157 if real_path != self.root: | 157 if real_path != self.root: |
158 real_path = os.path.join(self.root, real_path) | 158 real_path = os.path.join(self.root, real_path) |
159 wd = os.path.join(self.base, real_path) | 159 wd = os.path.join(self.base, real_path) |
160 if self.options.dryrun: | 160 if self.options.dry_run: |
161 print 'cd %s' % wd | 161 print 'cd %s' % wd |
162 self.run_git('svn', 'init', '--prefix=origin/', '-T', | 162 self.run_git('svn', 'init', '--prefix=origin/', '-T', |
163 svn_spec['svn_branch'], svn_spec['svn_url'], cwd=wd) | 163 svn_spec['svn_branch'], svn_spec['svn_url'], cwd=wd) |
164 self.run_git('config', '--replace', 'svn-remote.svn.fetch', | 164 self.run_git('config', '--replace', 'svn-remote.svn.fetch', |
165 svn_spec['svn_branch'] + ':refs/remotes/origin/' + | 165 svn_spec['svn_branch'] + ':refs/remotes/origin/' + |
166 svn_spec['svn_ref'], cwd=wd) | 166 svn_spec['svn_ref'], cwd=wd) |
167 self.run_git('svn', 'fetch', cwd=wd) | 167 self.run_git('svn', 'fetch', cwd=wd) |
168 | 168 |
169 | 169 |
170 | 170 |
(...skipping 25 matching lines...) Expand all Loading... | |
196 """ | 196 """ |
197 usage: %s [options] <recipe> [--property=value [--property2=value2 ...]] | 197 usage: %s [options] <recipe> [--property=value [--property2=value2 ...]] |
198 | 198 |
199 This script can be used to download the Chromium sources. See | 199 This script can be used to download the Chromium sources. See |
200 http://www.chromium.org/developers/how-tos/get-the-code | 200 http://www.chromium.org/developers/how-tos/get-the-code |
201 for full usage instructions. | 201 for full usage instructions. |
202 | 202 |
203 Valid options: | 203 Valid options: |
204 -h, --help, help Print this message. | 204 -h, --help, help Print this message. |
205 --nohooks Don't run hooks after checkout. | 205 --nohooks Don't run hooks after checkout. |
206 -n, --dryrun Don't run commands, only print them. | 206 -n, --dry-run Don't run commands, only print them. |
207 """ % os.path.basename(sys.argv[0])) | 207 """ % os.path.basename(sys.argv[0])) |
208 sys.exit(bool(msg)) | 208 sys.exit(bool(msg)) |
209 | 209 |
210 | 210 |
211 def handle_args(argv): | 211 def handle_args(argv): |
212 """Gets the recipe name from the command line arguments.""" | 212 """Gets the recipe name from the command line arguments.""" |
213 if len(argv) <= 1: | 213 if len(argv) <= 1: |
214 usage('Must specify a recipe.') | 214 usage('Must specify a recipe.') |
215 if argv[1] in ('-h', '--help', 'help'): | 215 if argv[1] in ('-h', '--help', 'help'): |
216 usage() | 216 usage() |
217 | 217 |
218 dryrun = False | 218 dry_run = False |
219 nohooks = False | 219 nohooks = False |
220 while len(argv) >= 2: | 220 while len(argv) >= 2: |
221 arg = argv[1] | 221 arg = argv[1] |
222 if not arg.startswith('-'): | 222 if not arg.startswith('-'): |
223 break | 223 break |
224 argv.pop(1) | 224 argv.pop(1) |
225 if arg in ('-n', '--dry-run'): | 225 if arg in ('-n', '--dry-run'): |
226 dryrun = True | 226 dry_run = True |
227 elif arg == '--nohooks': | 227 elif arg == '--nohooks': |
228 nohooks = True | 228 nohooks = True |
229 else: | 229 else: |
230 usage('Invalid option %s.' % arg) | 230 usage('Invalid option %s.' % arg) |
231 | 231 |
232 def looks_like_arg(arg): | 232 def looks_like_arg(arg): |
233 return arg.startswith('--') and arg.count('=') == 1 | 233 return arg.startswith('--') and arg.count('=') == 1 |
234 | 234 |
235 bad_parms = [x for x in argv[2:] if not looks_like_arg(x)] | 235 bad_parms = [x for x in argv[2:] if not looks_like_arg(x)] |
236 if bad_parms: | 236 if bad_parms: |
237 usage('Got bad arguments %s' % bad_parms) | 237 usage('Got bad arguments %s' % bad_parms) |
238 | 238 |
239 recipe = argv[1] | 239 recipe = argv[1] |
240 props = argv[2:] | 240 props = argv[2:] |
241 return optparse.Values({'dryrun':dryrun, 'nohooks':nohooks }), recipe, props | 241 return optparse.Values({'dry_run':dry_run, 'nohooks':nohooks }), recipe, props |
wtc
2014/02/12 06:00:08
I am not sure about this change. I assume the sing
Dirk Pranke
2014/02/12 21:08:04
Yup, that's the right change. LGTM, thanks!
| |
242 | 242 |
243 | 243 |
244 def run_recipe_fetch(recipe, props, aliased=False): | 244 def run_recipe_fetch(recipe, props, aliased=False): |
245 """Invoke a recipe's fetch method with the passed-through args | 245 """Invoke a recipe's fetch method with the passed-through args |
246 and return its json output as a python object.""" | 246 and return its json output as a python object.""" |
247 recipe_path = os.path.abspath(os.path.join(SCRIPT_PATH, 'recipes', recipe)) | 247 recipe_path = os.path.abspath(os.path.join(SCRIPT_PATH, 'recipes', recipe)) |
248 if not os.path.exists(recipe_path + '.py'): | 248 if not os.path.exists(recipe_path + '.py'): |
249 print "Could not find a recipe for %s" % recipe | 249 print "Could not find a recipe for %s" % recipe |
250 sys.exit(1) | 250 sys.exit(1) |
251 | 251 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 | 290 |
291 | 291 |
292 def main(): | 292 def main(): |
293 options, recipe, props = handle_args(sys.argv) | 293 options, recipe, props = handle_args(sys.argv) |
294 spec, root = run_recipe_fetch(recipe, props) | 294 spec, root = run_recipe_fetch(recipe, props) |
295 return run(options, spec, root) | 295 return run(options, spec, root) |
296 | 296 |
297 | 297 |
298 if __name__ == '__main__': | 298 if __name__ == '__main__': |
299 sys.exit(main()) | 299 sys.exit(main()) |
OLD | NEW |