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 ...]] |
11 | 11 |
12 This script is a wrapper around various version control and repository | 12 This script is a wrapper around various version control and repository |
13 checkout commands. It requires a |recipe| name, fetches data from that | 13 checkout commands. It requires a |recipe| name, fetches data from that |
14 recipe in depot_tools/recipes, and then performs all necessary inits, | 14 recipe in depot_tools/recipes, and then performs all necessary inits, |
15 checkouts, pulls, fetches, etc. | 15 checkouts, pulls, fetches, etc. |
16 | 16 |
17 Optional arguments may be passed on the command line in key-value pairs. | 17 Optional arguments may be passed on the command line in key-value pairs. |
18 These parameters will be passed through to the recipe's main method. | 18 These parameters will be passed through to the recipe's main method. |
19 """ | 19 """ |
20 | 20 |
21 import json | 21 import json |
22 import os | 22 import os |
23 import subprocess | 23 import subprocess |
24 import sys | 24 import sys |
25 import pipes | 25 import pipes |
26 | 26 |
| 27 from distutils import spawn |
| 28 |
27 | 29 |
28 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) | 30 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) |
29 | 31 |
30 | 32 |
31 ################################################# | 33 ################################################# |
32 # Checkout class definitions. | 34 # Checkout class definitions. |
33 ################################################# | 35 ################################################# |
34 class Checkout(object): | 36 class Checkout(object): |
35 """Base class for implementing different types of checkouts. | 37 """Base class for implementing different types of checkouts. |
36 | 38 |
(...skipping 12 matching lines...) Expand all Loading... |
49 | 51 |
50 def exists(self): | 52 def exists(self): |
51 pass | 53 pass |
52 | 54 |
53 def init(self): | 55 def init(self): |
54 pass | 56 pass |
55 | 57 |
56 def sync(self): | 58 def sync(self): |
57 pass | 59 pass |
58 | 60 |
| 61 def run(self, cmd, **kwargs): |
| 62 print 'Running: %s' % (' '.join(pipes.quote(x) for x in cmd)) |
| 63 if self.dryrun: |
| 64 return 0 |
| 65 return subprocess.check_call(cmd, **kwargs) |
| 66 |
59 | 67 |
60 class GclientCheckout(Checkout): | 68 class GclientCheckout(Checkout): |
61 | 69 |
62 def run_gclient(self, *cmd, **kwargs): | 70 def run_gclient(self, *cmd, **kwargs): |
63 print 'Running: gclient %s' % ' '.join(pipes.quote(x) for x in cmd) | 71 if not spawn.find_executable('gclient'): |
64 if not self.dryrun: | 72 cmd_prefix = (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) |
65 return subprocess.check_call( | 73 else: |
66 (sys.executable, os.path.join(SCRIPT_PATH, 'gclient.py')) + cmd, | 74 cmd_prefix = ('gclient',) |
67 **kwargs) | 75 return self.run(cmd_prefix + cmd, **kwargs) |
68 | 76 |
69 | 77 |
70 class GitCheckout(Checkout): | 78 class GitCheckout(Checkout): |
71 | 79 |
72 def run_git(self, *cmd, **kwargs): | 80 def run_git(self, *cmd, **kwargs): |
73 print 'Running: git %s' % ' '.join(pipes.quote(x) for x in cmd) | 81 if sys.platform == 'win32' and not spawn.find_executable('git'): |
74 if not self.dryrun: | 82 git_path = os.path.join(SCRIPT_PATH, 'git-1.8.0_bin', 'bin', 'git.exe') |
75 return subprocess.check_call(('git',) + cmd, **kwargs) | 83 else: |
| 84 git_path = 'git' |
| 85 return self.run((git_path,) + cmd, **kwargs) |
76 | 86 |
77 | 87 |
78 class SvnCheckout(Checkout): | 88 class SvnCheckout(Checkout): |
79 | 89 |
80 def run_svn(self, *cmd, **kwargs): | 90 def run_svn(self, *cmd, **kwargs): |
81 print 'Running: svn %s' % ' '.join(pipes.quote(x) for x in cmd) | 91 if sys.platform == 'win32' and not spawn.find_executable('svn'): |
82 if not self.dryrun: | 92 svn_path = os.path.join(SCRIPT_PATH, 'svn_bin', 'svn.exe') |
83 return subprocess.check_call(('svn',) + cmd, **kwargs) | 93 else: |
| 94 svn_path = 'svn' |
| 95 return self.run((svn_path,) + cmd, **kwargs) |
84 | 96 |
85 | 97 |
86 class GclientGitCheckout(GclientCheckout, GitCheckout): | 98 class GclientGitCheckout(GclientCheckout, GitCheckout): |
87 | 99 |
88 def __init__(self, dryrun, spec, root): | 100 def __init__(self, dryrun, spec, root): |
89 super(GclientGitCheckout, self).__init__(dryrun, spec, root) | 101 super(GclientGitCheckout, self).__init__(dryrun, spec, root) |
90 assert 'solutions' in self.spec | 102 assert 'solutions' in self.spec |
91 keys = ['solutions', 'target_os', 'target_os_only'] | 103 keys = ['solutions', 'target_os', 'target_os_only'] |
92 gclient_spec = '\n'.join('%s = %s' % (key, self.spec[key]) | 104 gclient_spec = '\n'.join('%s = %s' % (key, self.spec[key]) |
93 for key in self.spec if key in keys) | 105 for key in self.spec if key in keys) |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 266 |
255 | 267 |
256 def main(): | 268 def main(): |
257 dryrun, recipe, props = handle_args(sys.argv) | 269 dryrun, recipe, props = handle_args(sys.argv) |
258 spec, root = run_recipe_fetch(recipe, props) | 270 spec, root = run_recipe_fetch(recipe, props) |
259 return run(dryrun, spec, root) | 271 return run(dryrun, spec, root) |
260 | 272 |
261 | 273 |
262 if __name__ == '__main__': | 274 if __name__ == '__main__': |
263 sys.exit(main()) | 275 sys.exit(main()) |
OLD | NEW |