OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2014 Google Inc. | 2 # Copyright 2014 Google Inc. |
3 # | 3 # |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 | 7 |
8 """Parse a DEPS file and git checkout all of the dependencies. | 8 """Parse a DEPS file and git checkout all of the dependencies. |
9 | 9 |
10 Args: | 10 Args: |
11 An optional list of deps_os values. | 11 An optional list of deps_os values. |
12 | 12 |
13 Environment Variables: | 13 Environment Variables: |
| 14 GIT_EXECUTABLE: path to "git" binary; if unset, will look for one of |
| 15 ['git', 'git.exe', 'git.bat'] in your default path. |
| 16 |
14 GIT_SYNC_DEPS_PATH: file to get the dependency list from; if unset, | 17 GIT_SYNC_DEPS_PATH: file to get the dependency list from; if unset, |
15 will use the file ../DEPS relative to this script's directory. | 18 will use the file ../DEPS relative to this script's directory. |
16 | 19 |
17 GIT_SYNC_DEPS_QUIET: if set to non-empty string, suppress messages. | 20 GIT_SYNC_DEPS_QUIET: if set to non-empty string, suppress messages. |
18 | 21 |
19 Git Config: | 22 Git Config: |
20 To disable syncing of a single repository: | 23 To disable syncing of a single repository: |
21 cd path/to/repository | 24 cd path/to/repository |
22 git config sync-deps.disable true | 25 git config sync-deps.disable true |
23 | 26 |
24 To re-enable sync: | 27 To re-enable sync: |
25 cd path/to/repository | 28 cd path/to/repository |
26 git config --unset sync-deps.disable | 29 git config --unset sync-deps.disable |
27 """ | 30 """ |
28 | 31 |
29 | 32 |
30 import os | 33 import os |
31 import subprocess | 34 import subprocess |
32 import sys | 35 import sys |
33 import threading | 36 import threading |
34 | 37 |
35 import fix_pythonpath | 38 |
36 from common.py.utils.git_utils import GIT | 39 def git_executable(): |
| 40 """Find the git executable. |
| 41 |
| 42 Returns: |
| 43 A string suitable for passing to subprocess functions, or None. |
| 44 """ |
| 45 envgit = os.environ.get('GIT_EXECUTABLE') |
| 46 searchlist = ['git', 'git.exe', 'git.bat'] |
| 47 if envgit: |
| 48 searchlist.insert(0, envgit) |
| 49 with open(os.devnull, 'w') as devnull: |
| 50 for git in searchlist: |
| 51 try: |
| 52 subprocess.call([git, '--version'], stdout=devnull) |
| 53 except (OSError,): |
| 54 continue |
| 55 return git |
| 56 return None |
37 | 57 |
38 | 58 |
39 DEFAULT_DEPS_PATH = os.path.normpath( | 59 DEFAULT_DEPS_PATH = os.path.normpath( |
40 os.path.join(os.path.dirname(__file__), os.pardir, 'DEPS')) | 60 os.path.join(os.path.dirname(__file__), os.pardir, 'DEPS')) |
41 | 61 |
42 | 62 |
43 def usage(deps_file_path = None): | 63 def usage(deps_file_path = None): |
44 sys.stderr.write( | 64 sys.stderr.write( |
45 'Usage: run to grab dependencies, with optional platform support:\n') | 65 'Usage: run to grab dependencies, with optional platform support:\n') |
46 sys.stderr.write(' python %s' % __file__) | 66 sys.stderr.write(' python %s' % __file__) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 159 |
140 Args: | 160 Args: |
141 deps_file_path (string) Path to the DEPS file. | 161 deps_file_path (string) Path to the DEPS file. |
142 | 162 |
143 deps_os_list (list of strings) Can be empty list. List of | 163 deps_os_list (list of strings) Can be empty list. List of |
144 strings that should each be a key in the deps_os | 164 strings that should each be a key in the deps_os |
145 dictionary in the DEPS file. | 165 dictionary in the DEPS file. |
146 | 166 |
147 Raises DepsError exception and git Exceptions. | 167 Raises DepsError exception and git Exceptions. |
148 """ | 168 """ |
| 169 git = git_executable() |
| 170 assert git |
| 171 |
149 deps_file_directory = os.path.dirname(deps_file_path) | 172 deps_file_directory = os.path.dirname(deps_file_path) |
150 deps = parse_file_to_dict(deps_file_path) | 173 deps = parse_file_to_dict(deps_file_path) |
151 dependencies = deps['deps'].copy() | 174 dependencies = deps['deps'].copy() |
152 for deps_os in deps_os_list: | 175 for deps_os in deps_os_list: |
153 # Add OS-specific dependencies | 176 # Add OS-specific dependencies |
154 if deps_os not in deps['deps_os']: | 177 if deps_os not in deps['deps_os']: |
155 raise DepsError( | 178 raise DepsError( |
156 'Argument "%s" not found within deps_os keys %r' % | 179 'Argument "%s" not found within deps_os keys %r' % |
157 (deps_os, deps['deps_os'].keys())) | 180 (deps_os, deps['deps_os'].keys())) |
158 for dep in deps['deps_os'][deps_os]: | 181 for dep in deps['deps_os'][deps_os]: |
159 dependencies[dep] = deps['deps_os'][deps_os][dep] | 182 dependencies[dep] = deps['deps_os'][deps_os][dep] |
160 list_of_arg_lists = [] | 183 list_of_arg_lists = [] |
161 for directory in dependencies: | 184 for directory in dependencies: |
162 if '@' in dependencies[directory]: | 185 if '@' in dependencies[directory]: |
163 repo, checkoutable = dependencies[directory].split('@', 1) | 186 repo, checkoutable = dependencies[directory].split('@', 1) |
164 else: | 187 else: |
165 repo, checkoutable = dependencies[directory], 'origin/master' | 188 repo, checkoutable = dependencies[directory], 'origin/master' |
166 | 189 |
167 relative_directory = os.path.join(deps_file_directory, directory) | 190 relative_directory = os.path.join(deps_file_directory, directory) |
168 | 191 |
169 list_of_arg_lists.append( | 192 list_of_arg_lists.append( |
170 (GIT, repo, checkoutable, relative_directory, verbose)) | 193 (git, repo, checkoutable, relative_directory, verbose)) |
171 | 194 |
172 multithread(git_checkout_to_directory, list_of_arg_lists) | 195 multithread(git_checkout_to_directory, list_of_arg_lists) |
173 | 196 |
174 | 197 |
175 def multithread(function, list_of_arg_lists): | 198 def multithread(function, list_of_arg_lists): |
176 # for args in list_of_arg_lists: | 199 # for args in list_of_arg_lists: |
177 # function(*args) | 200 # function(*args) |
178 # return | 201 # return |
179 threads = [] | 202 threads = [] |
180 for args in list_of_arg_lists: | 203 for args in list_of_arg_lists: |
(...skipping 10 matching lines...) Expand all Loading... |
191 try: | 214 try: |
192 git_sync_deps(deps_file_path, argv, verbose) | 215 git_sync_deps(deps_file_path, argv, verbose) |
193 return 0 | 216 return 0 |
194 except DepsError: | 217 except DepsError: |
195 usage(deps_file_path) | 218 usage(deps_file_path) |
196 return 1 | 219 return 1 |
197 | 220 |
198 | 221 |
199 if __name__ == '__main__': | 222 if __name__ == '__main__': |
200 exit(main(sys.argv[1:])) | 223 exit(main(sys.argv[1:])) |
OLD | NEW |