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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 | 77 |
78 class SvnCheckout(Checkout): | 78 class SvnCheckout(Checkout): |
79 | 79 |
80 def run_svn(self, *cmd, **kwargs): | 80 def run_svn(self, *cmd, **kwargs): |
81 print 'Running: svn %s' % ' '.join(pipes.quote(x) for x in cmd) | 81 print 'Running: svn %s' % ' '.join(pipes.quote(x) for x in cmd) |
82 if not self.dryrun: | 82 if not self.dryrun: |
83 return subprocess.check_call(('svn',) + cmd, **kwargs) | 83 return subprocess.check_call(('svn',) + cmd, **kwargs) |
84 | 84 |
85 | 85 |
86 class GclientGitSvnCheckout(GclientCheckout, GitCheckout, SvnCheckout): | 86 class GclientGitCheckout(GclientCheckout, GitCheckout): |
87 | 87 |
88 def __init__(self, dryrun, spec, root): | 88 def __init__(self, dryrun, spec, root): |
89 super(GclientGitSvnCheckout, self).__init__(dryrun, spec, root) | 89 super(GclientGitCheckout, self).__init__(dryrun, spec, root) |
90 assert 'solutions' in self.spec | 90 assert 'solutions' in self.spec |
91 keys = ['solutions', 'target_os', 'target_os_only'] | 91 keys = ['solutions', 'target_os', 'target_os_only'] |
92 gclient_spec = '\n'.join('%s = %s' % (key, self.spec[key]) | 92 gclient_spec = '\n'.join('%s = %s' % (key, self.spec[key]) |
93 for key in self.spec if key in keys) | 93 for key in self.spec if key in keys) |
94 self.spec['gclient_spec'] = gclient_spec | 94 self.spec['gclient_spec'] = gclient_spec |
95 assert 'svn_url' in self.spec | |
96 assert 'svn_branch' in self.spec | |
97 assert 'svn_ref' in self.spec | |
98 | 95 |
99 def exists(self): | 96 def exists(self): |
100 return os.path.exists(os.path.join(os.getcwd(), self.root)) | 97 return os.path.exists(os.path.join(os.getcwd(), self.root)) |
101 | 98 |
102 def init(self): | 99 def init(self): |
103 # Ensure we are authenticated with subversion for all submodules. | |
104 git_svn_dirs = json.loads(self.spec.get('submodule_git_svn_spec', '{}')) | |
105 git_svn_dirs.update({self.root: self.spec}) | |
106 for _, svn_spec in git_svn_dirs.iteritems(): | |
107 try: | |
108 self.run_svn('ls', '--non-interactive', svn_spec['svn_url']) | |
109 except subprocess.CalledProcessError: | |
110 print 'Please run `svn ls %s`' % svn_spec['svn_url'] | |
111 return 1 | |
112 | |
113 # TODO(dpranke): Work around issues w/ delta compression on big repos. | 100 # TODO(dpranke): Work around issues w/ delta compression on big repos. |
114 self.run_git('config', '--global', 'core.deltaBaseCacheLimit', '1G') | 101 self.run_git('config', '--global', 'core.deltaBaseCacheLimit', '1G') |
115 | 102 |
116 # Configure and do the gclient checkout. | 103 # Configure and do the gclient checkout. |
117 self.run_gclient('config', '--spec', self.spec['gclient_spec']) | 104 self.run_gclient('config', '--spec', self.spec['gclient_spec']) |
118 self.run_gclient('sync') | 105 self.run_gclient('sync') |
119 | 106 |
120 # Configure git. | 107 # Configure git. |
121 wd = os.path.join(self.base, self.root) | 108 wd = os.path.join(self.base, self.root) |
122 if self.dryrun: | 109 if self.dryrun: |
123 print 'cd %s' % wd | 110 print 'cd %s' % wd |
124 self.run_git( | 111 self.run_git( |
125 'submodule', 'foreach', | 112 'submodule', 'foreach', |
126 'git config -f $toplevel/.git/config submodule.$name.ignore all', | 113 'git config -f $toplevel/.git/config submodule.$name.ignore all', |
127 cwd=wd) | 114 cwd=wd) |
128 self.run_git('config', 'diff.ignoreSubmodules', 'all', cwd=wd) | 115 self.run_git('config', 'diff.ignoreSubmodules', 'all', cwd=wd) |
129 | 116 |
| 117 |
| 118 class GclientGitSvnCheckout(GclientGitCheckout, SvnCheckout): |
| 119 |
| 120 def __init__(self, dryrun, spec, root): |
| 121 super(GclientGitSvnCheckout, self).__init__(dryrun, spec, root) |
| 122 assert 'svn_url' in self.spec |
| 123 assert 'svn_branch' in self.spec |
| 124 assert 'svn_ref' in self.spec |
| 125 |
| 126 def init(self): |
| 127 # Ensure we are authenticated with subversion for all submodules. |
| 128 git_svn_dirs = json.loads(self.spec.get('submodule_git_svn_spec', '{}')) |
| 129 git_svn_dirs.update({self.root: self.spec}) |
| 130 for _, svn_spec in git_svn_dirs.iteritems(): |
| 131 try: |
| 132 self.run_svn('ls', '--non-interactive', svn_spec['svn_url']) |
| 133 except subprocess.CalledProcessError: |
| 134 print 'Please run `svn ls %s`' % svn_spec['svn_url'] |
| 135 return 1 |
| 136 |
| 137 super(GclientGitSvnCheckout, self).init() |
| 138 |
130 # Configure git-svn. | 139 # Configure git-svn. |
131 for path, svn_spec in git_svn_dirs.iteritems(): | 140 for path, svn_spec in git_svn_dirs.iteritems(): |
132 real_path = os.path.join(*path.split('/')) | 141 real_path = os.path.join(*path.split('/')) |
133 if real_path != self.root: | 142 if real_path != self.root: |
134 real_path = os.path.join(self.root, real_path) | 143 real_path = os.path.join(self.root, real_path) |
135 wd = os.path.join(self.base, real_path) | 144 wd = os.path.join(self.base, real_path) |
136 if self.dryrun: | 145 if self.dryrun: |
137 print 'cd %s' % wd | 146 print 'cd %s' % wd |
138 self.run_git('svn', 'init', '--prefix=origin/', '-T', | 147 self.run_git('svn', 'init', '--prefix=origin/', '-T', |
139 svn_spec['svn_branch'], svn_spec['svn_url'], cwd=wd) | 148 svn_spec['svn_branch'], svn_spec['svn_url'], cwd=wd) |
140 self.run_git('config', '--replace', 'svn-remote.svn.fetch', | 149 self.run_git('config', '--replace', 'svn-remote.svn.fetch', |
141 svn_spec['svn_branch'] + ':refs/remotes/origin/' + | 150 svn_spec['svn_branch'] + ':refs/remotes/origin/' + |
142 svn_spec['svn_ref'], cwd=wd) | 151 svn_spec['svn_ref'], cwd=wd) |
143 self.run_git('svn', 'fetch', cwd=wd) | 152 self.run_git('svn', 'fetch', cwd=wd) |
144 | 153 |
145 | 154 |
146 | 155 |
147 CHECKOUT_TYPE_MAP = { | 156 CHECKOUT_TYPE_MAP = { |
148 'gclient': GclientCheckout, | 157 'gclient': GclientCheckout, |
| 158 'gclient_git': GclientGitCheckout, |
149 'gclient_git_svn': GclientGitSvnCheckout, | 159 'gclient_git_svn': GclientGitSvnCheckout, |
150 'git': GitCheckout, | 160 'git': GitCheckout, |
151 } | 161 } |
152 | 162 |
153 | 163 |
154 def CheckoutFactory(type_name, dryrun, spec, root): | 164 def CheckoutFactory(type_name, dryrun, spec, root): |
155 """Factory to build Checkout class instances.""" | 165 """Factory to build Checkout class instances.""" |
156 class_ = CHECKOUT_TYPE_MAP.get(type_name) | 166 class_ = CHECKOUT_TYPE_MAP.get(type_name) |
157 if not class_: | 167 if not class_: |
158 raise KeyError('unrecognized checkout type: %s' % type_name) | 168 raise KeyError('unrecognized checkout type: %s' % type_name) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 254 |
245 | 255 |
246 def main(): | 256 def main(): |
247 dryrun, recipe, props = handle_args(sys.argv) | 257 dryrun, recipe, props = handle_args(sys.argv) |
248 spec, root = run_recipe_fetch(recipe, props) | 258 spec, root = run_recipe_fetch(recipe, props) |
249 return run(dryrun, spec, root) | 259 return run(dryrun, spec, root) |
250 | 260 |
251 | 261 |
252 if __name__ == '__main__': | 262 if __name__ == '__main__': |
253 sys.exit(main()) | 263 sys.exit(main()) |
OLD | NEW |