| 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 | |
| 17 GIT_SYNC_DEPS_PATH: file to get the dependency list from; if unset, | 14 GIT_SYNC_DEPS_PATH: file to get the dependency list from; if unset, |
| 18 will use the file ../DEPS relative to this script's directory. | 15 will use the file ../DEPS relative to this script's directory. |
| 19 | 16 |
| 20 GIT_SYNC_DEPS_QUIET: if set to non-empty string, suppress messages. | 17 GIT_SYNC_DEPS_QUIET: if set to non-empty string, suppress messages. |
| 21 | 18 |
| 22 Git Config: | 19 Git Config: |
| 23 To disable syncing of a single repository: | 20 To disable syncing of a single repository: |
| 24 cd path/to/repository | 21 cd path/to/repository |
| 25 git config sync-deps.disable true | 22 git config sync-deps.disable true |
| 26 | 23 |
| 27 To re-enable sync: | 24 To re-enable sync: |
| 28 cd path/to/repository | 25 cd path/to/repository |
| 29 git config --unset sync-deps.disable | 26 git config --unset sync-deps.disable |
| 30 """ | 27 """ |
| 31 | 28 |
| 32 | 29 |
| 33 import os | 30 import os |
| 34 import subprocess | 31 import subprocess |
| 35 import sys | 32 import sys |
| 36 import threading | 33 import threading |
| 37 | 34 |
| 38 from git_utils import git_executable | 35 import fix_pythonpath |
| 36 from common.py.utils.git_utils import GIT |
| 39 | 37 |
| 40 | 38 |
| 41 DEFAULT_DEPS_PATH = os.path.normpath( | 39 DEFAULT_DEPS_PATH = os.path.normpath( |
| 42 os.path.join(os.path.dirname(__file__), os.pardir, 'DEPS')) | 40 os.path.join(os.path.dirname(__file__), os.pardir, 'DEPS')) |
| 43 | 41 |
| 44 | 42 |
| 45 def usage(deps_file_path = None): | 43 def usage(deps_file_path = None): |
| 46 sys.stderr.write( | 44 sys.stderr.write( |
| 47 'Usage: run to grab dependencies, with optional platform support:\n') | 45 'Usage: run to grab dependencies, with optional platform support:\n') |
| 48 sys.stderr.write(' python %s' % __file__) | 46 sys.stderr.write(' python %s' % __file__) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 139 |
| 142 Args: | 140 Args: |
| 143 deps_file_path (string) Path to the DEPS file. | 141 deps_file_path (string) Path to the DEPS file. |
| 144 | 142 |
| 145 deps_os_list (list of strings) Can be empty list. List of | 143 deps_os_list (list of strings) Can be empty list. List of |
| 146 strings that should each be a key in the deps_os | 144 strings that should each be a key in the deps_os |
| 147 dictionary in the DEPS file. | 145 dictionary in the DEPS file. |
| 148 | 146 |
| 149 Raises DepsError exception and git Exceptions. | 147 Raises DepsError exception and git Exceptions. |
| 150 """ | 148 """ |
| 151 git = git_executable() | |
| 152 assert git | |
| 153 | |
| 154 deps_file_directory = os.path.dirname(deps_file_path) | 149 deps_file_directory = os.path.dirname(deps_file_path) |
| 155 deps = parse_file_to_dict(deps_file_path) | 150 deps = parse_file_to_dict(deps_file_path) |
| 156 dependencies = deps['deps'].copy() | 151 dependencies = deps['deps'].copy() |
| 157 for deps_os in deps_os_list: | 152 for deps_os in deps_os_list: |
| 158 # Add OS-specific dependencies | 153 # Add OS-specific dependencies |
| 159 if deps_os not in deps['deps_os']: | 154 if deps_os not in deps['deps_os']: |
| 160 raise DepsError( | 155 raise DepsError( |
| 161 'Argument "%s" not found within deps_os keys %r' % | 156 'Argument "%s" not found within deps_os keys %r' % |
| 162 (deps_os, deps['deps_os'].keys())) | 157 (deps_os, deps['deps_os'].keys())) |
| 163 for dep in deps['deps_os'][deps_os]: | 158 for dep in deps['deps_os'][deps_os]: |
| 164 dependencies[dep] = deps['deps_os'][deps_os][dep] | 159 dependencies[dep] = deps['deps_os'][deps_os][dep] |
| 165 list_of_arg_lists = [] | 160 list_of_arg_lists = [] |
| 166 for directory in dependencies: | 161 for directory in dependencies: |
| 167 if '@' in dependencies[directory]: | 162 if '@' in dependencies[directory]: |
| 168 repo, checkoutable = dependencies[directory].split('@', 1) | 163 repo, checkoutable = dependencies[directory].split('@', 1) |
| 169 else: | 164 else: |
| 170 repo, checkoutable = dependencies[directory], 'origin/master' | 165 repo, checkoutable = dependencies[directory], 'origin/master' |
| 171 | 166 |
| 172 relative_directory = os.path.join(deps_file_directory, directory) | 167 relative_directory = os.path.join(deps_file_directory, directory) |
| 173 | 168 |
| 174 list_of_arg_lists.append( | 169 list_of_arg_lists.append( |
| 175 (git, repo, checkoutable, relative_directory, verbose)) | 170 (GIT, repo, checkoutable, relative_directory, verbose)) |
| 176 | 171 |
| 177 multithread(git_checkout_to_directory, list_of_arg_lists) | 172 multithread(git_checkout_to_directory, list_of_arg_lists) |
| 178 | 173 |
| 179 | 174 |
| 180 def multithread(function, list_of_arg_lists): | 175 def multithread(function, list_of_arg_lists): |
| 181 # for args in list_of_arg_lists: | 176 # for args in list_of_arg_lists: |
| 182 # function(*args) | 177 # function(*args) |
| 183 # return | 178 # return |
| 184 threads = [] | 179 threads = [] |
| 185 for args in list_of_arg_lists: | 180 for args in list_of_arg_lists: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 try: | 191 try: |
| 197 git_sync_deps(deps_file_path, argv, verbose) | 192 git_sync_deps(deps_file_path, argv, verbose) |
| 198 return 0 | 193 return 0 |
| 199 except DepsError: | 194 except DepsError: |
| 200 usage(deps_file_path) | 195 usage(deps_file_path) |
| 201 return 1 | 196 return 1 |
| 202 | 197 |
| 203 | 198 |
| 204 if __name__ == '__main__': | 199 if __name__ == '__main__': |
| 205 exit(main(sys.argv[1:])) | 200 exit(main(sys.argv[1:])) |
| OLD | NEW |