1*03ce13f7SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*03ce13f7SAndroid Build Coastguard Worker# Copyright 2014 Google Inc. 3*03ce13f7SAndroid Build Coastguard Worker# 4*03ce13f7SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without 5*03ce13f7SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are 6*03ce13f7SAndroid Build Coastguard Worker# met: 7*03ce13f7SAndroid Build Coastguard Worker# 8*03ce13f7SAndroid Build Coastguard Worker# * Redistributions of source code must retain the above copyright 9*03ce13f7SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer. 10*03ce13f7SAndroid Build Coastguard Worker# * Redistributions in binary form must reproduce the above 11*03ce13f7SAndroid Build Coastguard Worker# copyright notice, this list of conditions and the following disclaimer 12*03ce13f7SAndroid Build Coastguard Worker# in the documentation and/or other materials provided with the 13*03ce13f7SAndroid Build Coastguard Worker# distribution. 14*03ce13f7SAndroid Build Coastguard Worker# * Neither the name of Google Inc. nor the names of its 15*03ce13f7SAndroid Build Coastguard Worker# contributors may be used to endorse or promote products derived from 16*03ce13f7SAndroid Build Coastguard Worker# this software without specific prior written permission. 17*03ce13f7SAndroid Build Coastguard Worker# 18*03ce13f7SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19*03ce13f7SAndroid Build Coastguard Worker# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20*03ce13f7SAndroid Build Coastguard Worker# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21*03ce13f7SAndroid Build Coastguard Worker# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22*03ce13f7SAndroid Build Coastguard Worker# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23*03ce13f7SAndroid Build Coastguard Worker# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24*03ce13f7SAndroid Build Coastguard Worker# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25*03ce13f7SAndroid Build Coastguard Worker# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26*03ce13f7SAndroid Build Coastguard Worker# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27*03ce13f7SAndroid Build Coastguard Worker# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28*03ce13f7SAndroid Build Coastguard Worker# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29*03ce13f7SAndroid Build Coastguard Worker 30*03ce13f7SAndroid Build Coastguard Worker"""Parse a DEPS file and git checkout all of the dependencies. 31*03ce13f7SAndroid Build Coastguard Worker""" 32*03ce13f7SAndroid Build Coastguard Worker 33*03ce13f7SAndroid Build Coastguard WorkerEXTRA_HELP = """ 34*03ce13f7SAndroid Build Coastguard WorkerEnvironment Variables: 35*03ce13f7SAndroid Build Coastguard Worker GIT_EXECUTABLE: path to "git" binary; if unset, will look for one of 36*03ce13f7SAndroid Build Coastguard Worker ['git', 'git.exe', 'git.bat'] in your default path. 37*03ce13f7SAndroid Build Coastguard Worker 38*03ce13f7SAndroid Build Coastguard Worker GIT_SYNC_DEPS_PATH: file to get the dependency list from; if unset, 39*03ce13f7SAndroid Build Coastguard Worker will use the file ../DEPS relative to this script's directory. 40*03ce13f7SAndroid Build Coastguard Worker 41*03ce13f7SAndroid Build Coastguard Worker GIT_SYNC_DEPS_QUIET: if set to non-empty string, suppress messages. 42*03ce13f7SAndroid Build Coastguard Worker 43*03ce13f7SAndroid Build Coastguard WorkerGit Config: 44*03ce13f7SAndroid Build Coastguard Worker To disable syncing of a single repository: 45*03ce13f7SAndroid Build Coastguard Worker cd path/to/repository 46*03ce13f7SAndroid Build Coastguard Worker git config sync-deps.disable true 47*03ce13f7SAndroid Build Coastguard Worker 48*03ce13f7SAndroid Build Coastguard Worker To re-enable sync: 49*03ce13f7SAndroid Build Coastguard Worker cd path/to/repository 50*03ce13f7SAndroid Build Coastguard Worker git config --unset sync-deps.disable 51*03ce13f7SAndroid Build Coastguard Worker""" 52*03ce13f7SAndroid Build Coastguard Worker 53*03ce13f7SAndroid Build Coastguard Worker 54*03ce13f7SAndroid Build Coastguard Workerimport argparse 55*03ce13f7SAndroid Build Coastguard Workerimport os 56*03ce13f7SAndroid Build Coastguard Workerimport re 57*03ce13f7SAndroid Build Coastguard Workerimport subprocess 58*03ce13f7SAndroid Build Coastguard Workerimport sys 59*03ce13f7SAndroid Build Coastguard Workerimport threading 60*03ce13f7SAndroid Build Coastguard Workerfrom builtins import bytes 61*03ce13f7SAndroid Build Coastguard Worker 62*03ce13f7SAndroid Build Coastguard Workerdef git_executable(): 63*03ce13f7SAndroid Build Coastguard Worker """Find the git executable. 64*03ce13f7SAndroid Build Coastguard Worker 65*03ce13f7SAndroid Build Coastguard Worker Returns: 66*03ce13f7SAndroid Build Coastguard Worker A triple: 67*03ce13f7SAndroid Build Coastguard Worker A string suitable for passing to subprocess functions, or None. 68*03ce13f7SAndroid Build Coastguard Worker The major version number 69*03ce13f7SAndroid Build Coastguard Worker The minor version number 70*03ce13f7SAndroid Build Coastguard Worker """ 71*03ce13f7SAndroid Build Coastguard Worker envgit = os.environ.get('GIT_EXECUTABLE') 72*03ce13f7SAndroid Build Coastguard Worker searchlist = ['git', 'git.exe', 'git.bat'] 73*03ce13f7SAndroid Build Coastguard Worker if envgit: 74*03ce13f7SAndroid Build Coastguard Worker searchlist.insert(0, envgit) 75*03ce13f7SAndroid Build Coastguard Worker with open(os.devnull, 'w') as devnull: 76*03ce13f7SAndroid Build Coastguard Worker for git in searchlist: 77*03ce13f7SAndroid Build Coastguard Worker major=None 78*03ce13f7SAndroid Build Coastguard Worker minor=None 79*03ce13f7SAndroid Build Coastguard Worker try: 80*03ce13f7SAndroid Build Coastguard Worker version_info = subprocess.check_output([git, '--version']).decode('utf-8') 81*03ce13f7SAndroid Build Coastguard Worker match = re.search("^git version (\d+)\.(\d+)",version_info) 82*03ce13f7SAndroid Build Coastguard Worker print("Using {}".format(version_info)) 83*03ce13f7SAndroid Build Coastguard Worker if match: 84*03ce13f7SAndroid Build Coastguard Worker major = int(match.group(1)) 85*03ce13f7SAndroid Build Coastguard Worker minor = int(match.group(2)) 86*03ce13f7SAndroid Build Coastguard Worker else: 87*03ce13f7SAndroid Build Coastguard Worker continue 88*03ce13f7SAndroid Build Coastguard Worker except (OSError,): 89*03ce13f7SAndroid Build Coastguard Worker continue 90*03ce13f7SAndroid Build Coastguard Worker return (git,major,minor) 91*03ce13f7SAndroid Build Coastguard Worker return (None,0,0) 92*03ce13f7SAndroid Build Coastguard Worker 93*03ce13f7SAndroid Build Coastguard Worker 94*03ce13f7SAndroid Build Coastguard WorkerDEFAULT_DEPS_PATH = os.path.normpath( 95*03ce13f7SAndroid Build Coastguard Worker os.path.join(os.path.dirname(__file__), os.pardir, 'DEPS')) 96*03ce13f7SAndroid Build Coastguard Worker 97*03ce13f7SAndroid Build Coastguard Workerdef get_deps_os_str(deps_file): 98*03ce13f7SAndroid Build Coastguard Worker parsed_deps = parse_file_to_dict(deps_file) 99*03ce13f7SAndroid Build Coastguard Worker parts = [] 100*03ce13f7SAndroid Build Coastguard Worker if 'deps_os' in parsed_deps: 101*03ce13f7SAndroid Build Coastguard Worker for deps_os in parsed_deps['deps_os']: 102*03ce13f7SAndroid Build Coastguard Worker parts.append(' [{}]]'.format(deps_os)) 103*03ce13f7SAndroid Build Coastguard Worker return "\n".join(parts) 104*03ce13f7SAndroid Build Coastguard Worker 105*03ce13f7SAndroid Build Coastguard Workerdef looks_like_raw_commit(commit): 106*03ce13f7SAndroid Build Coastguard Worker return re.match('^[a-f0-9]{40}$', commit) is not None 107*03ce13f7SAndroid Build Coastguard Worker 108*03ce13f7SAndroid Build Coastguard Workerdef git_repository_sync_is_disabled(git, directory): 109*03ce13f7SAndroid Build Coastguard Worker try: 110*03ce13f7SAndroid Build Coastguard Worker disable = subprocess.check_output( 111*03ce13f7SAndroid Build Coastguard Worker [git, 'config', 'sync-deps.disable'], cwd=directory) 112*03ce13f7SAndroid Build Coastguard Worker return disable.lower().strip() in ['true', '1', 'yes', 'on'] 113*03ce13f7SAndroid Build Coastguard Worker except subprocess.CalledProcessError: 114*03ce13f7SAndroid Build Coastguard Worker return False 115*03ce13f7SAndroid Build Coastguard Worker 116*03ce13f7SAndroid Build Coastguard Worker 117*03ce13f7SAndroid Build Coastguard Workerdef is_git_toplevel(git, directory): 118*03ce13f7SAndroid Build Coastguard Worker """Return true iff the directory is the top level of a Git repository. 119*03ce13f7SAndroid Build Coastguard Worker 120*03ce13f7SAndroid Build Coastguard Worker Args: 121*03ce13f7SAndroid Build Coastguard Worker git (string) the git executable 122*03ce13f7SAndroid Build Coastguard Worker 123*03ce13f7SAndroid Build Coastguard Worker directory (string) the path into which the repository 124*03ce13f7SAndroid Build Coastguard Worker is expected to be checked out. 125*03ce13f7SAndroid Build Coastguard Worker """ 126*03ce13f7SAndroid Build Coastguard Worker try: 127*03ce13f7SAndroid Build Coastguard Worker toplevel = subprocess.check_output( 128*03ce13f7SAndroid Build Coastguard Worker [git, 'rev-parse', '--show-toplevel'], cwd=directory).strip() 129*03ce13f7SAndroid Build Coastguard Worker return os.path.realpath(bytes(directory, 'utf8')) == os.path.realpath(toplevel) 130*03ce13f7SAndroid Build Coastguard Worker except subprocess.CalledProcessError: 131*03ce13f7SAndroid Build Coastguard Worker return False 132*03ce13f7SAndroid Build Coastguard Worker 133*03ce13f7SAndroid Build Coastguard Worker 134*03ce13f7SAndroid Build Coastguard Workerdef status(directory, checkoutable): 135*03ce13f7SAndroid Build Coastguard Worker def truncate(s, length): 136*03ce13f7SAndroid Build Coastguard Worker return s if len(s) <= length else '...' + s[-(length - 3):] 137*03ce13f7SAndroid Build Coastguard Worker dlen = 36 138*03ce13f7SAndroid Build Coastguard Worker directory = truncate(directory, dlen) 139*03ce13f7SAndroid Build Coastguard Worker checkoutable = truncate(checkoutable, 40) 140*03ce13f7SAndroid Build Coastguard Worker sys.stdout.write('%-*s @ %s\n' % (dlen, directory, checkoutable)) 141*03ce13f7SAndroid Build Coastguard Worker 142*03ce13f7SAndroid Build Coastguard Worker 143*03ce13f7SAndroid Build Coastguard Workerdef git_checkout_to_directory(git, repo, checkoutable, directory, verbose, treeless): 144*03ce13f7SAndroid Build Coastguard Worker """Checkout (and clone if needed) a Git repository. 145*03ce13f7SAndroid Build Coastguard Worker 146*03ce13f7SAndroid Build Coastguard Worker Args: 147*03ce13f7SAndroid Build Coastguard Worker git (string) the git executable 148*03ce13f7SAndroid Build Coastguard Worker 149*03ce13f7SAndroid Build Coastguard Worker repo (string) the location of the repository, suitable 150*03ce13f7SAndroid Build Coastguard Worker for passing to `git clone`. 151*03ce13f7SAndroid Build Coastguard Worker 152*03ce13f7SAndroid Build Coastguard Worker checkoutable (string) a tag, branch, or commit, suitable for 153*03ce13f7SAndroid Build Coastguard Worker passing to `git checkout` 154*03ce13f7SAndroid Build Coastguard Worker 155*03ce13f7SAndroid Build Coastguard Worker directory (string) the path into which the repository 156*03ce13f7SAndroid Build Coastguard Worker should be checked out. 157*03ce13f7SAndroid Build Coastguard Worker 158*03ce13f7SAndroid Build Coastguard Worker verbose (boolean): emit status info to stdout 159*03ce13f7SAndroid Build Coastguard Worker 160*03ce13f7SAndroid Build Coastguard Worker treeless (boolean): when true, clone without any trees. 161*03ce13f7SAndroid Build Coastguard Worker 162*03ce13f7SAndroid Build Coastguard Worker Raises an exception if any calls to git fail. 163*03ce13f7SAndroid Build Coastguard Worker """ 164*03ce13f7SAndroid Build Coastguard Worker if not os.path.isdir(directory): 165*03ce13f7SAndroid Build Coastguard Worker # Use blobless or treeless checkouts for faster downloads. 166*03ce13f7SAndroid Build Coastguard Worker # This defers some work to checkout time. 167*03ce13f7SAndroid Build Coastguard Worker # https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/ 168*03ce13f7SAndroid Build Coastguard Worker filter = ['--filter=tree:0'] if treeless else ['--filter=blob:none'] 169*03ce13f7SAndroid Build Coastguard Worker # If the thing to check out looks like a tag (and not like a commit), 170*03ce13f7SAndroid Build Coastguard Worker # then limit the checkout to that branch. 171*03ce13f7SAndroid Build Coastguard Worker branch = [] if looks_like_raw_commit(checkoutable) else ['--branch={}'.format(checkoutable)] 172*03ce13f7SAndroid Build Coastguard Worker subprocess.check_call( 173*03ce13f7SAndroid Build Coastguard Worker [git, 'clone', '--quiet', '--single-branch'] + filter + branch + [repo, directory]) 174*03ce13f7SAndroid Build Coastguard Worker 175*03ce13f7SAndroid Build Coastguard Worker if not is_git_toplevel(git, directory): 176*03ce13f7SAndroid Build Coastguard Worker # if the directory exists, but isn't a git repo, you will modify 177*03ce13f7SAndroid Build Coastguard Worker # the parent repostory, which isn't what you want. 178*03ce13f7SAndroid Build Coastguard Worker sys.stdout.write('%s\n IS NOT TOP-LEVEL GIT DIRECTORY.\n' % directory) 179*03ce13f7SAndroid Build Coastguard Worker return 180*03ce13f7SAndroid Build Coastguard Worker 181*03ce13f7SAndroid Build Coastguard Worker # Check to see if this repo is disabled. Quick return. 182*03ce13f7SAndroid Build Coastguard Worker if git_repository_sync_is_disabled(git, directory): 183*03ce13f7SAndroid Build Coastguard Worker sys.stdout.write('%s\n SYNC IS DISABLED.\n' % directory) 184*03ce13f7SAndroid Build Coastguard Worker return 185*03ce13f7SAndroid Build Coastguard Worker 186*03ce13f7SAndroid Build Coastguard Worker with open(os.devnull, 'w') as devnull: 187*03ce13f7SAndroid Build Coastguard Worker # If this fails, we will fetch before trying again. Don't spam user 188*03ce13f7SAndroid Build Coastguard Worker # with error information. 189*03ce13f7SAndroid Build Coastguard Worker if 0 == subprocess.call([git, 'checkout', '--quiet', checkoutable], 190*03ce13f7SAndroid Build Coastguard Worker cwd=directory, stderr=devnull): 191*03ce13f7SAndroid Build Coastguard Worker # if this succeeds, skip slow `git fetch`. 192*03ce13f7SAndroid Build Coastguard Worker if verbose: 193*03ce13f7SAndroid Build Coastguard Worker status(directory, checkoutable) # Success. 194*03ce13f7SAndroid Build Coastguard Worker return 195*03ce13f7SAndroid Build Coastguard Worker 196*03ce13f7SAndroid Build Coastguard Worker # If the repo has changed, always force use of the correct repo. 197*03ce13f7SAndroid Build Coastguard Worker # If origin already points to repo, this is a quick no-op. 198*03ce13f7SAndroid Build Coastguard Worker subprocess.check_call( 199*03ce13f7SAndroid Build Coastguard Worker [git, 'remote', 'set-url', 'origin', repo], cwd=directory) 200*03ce13f7SAndroid Build Coastguard Worker 201*03ce13f7SAndroid Build Coastguard Worker subprocess.check_call([git, 'fetch', '--quiet'], cwd=directory) 202*03ce13f7SAndroid Build Coastguard Worker 203*03ce13f7SAndroid Build Coastguard Worker subprocess.check_call([git, 'checkout', '--quiet', checkoutable], cwd=directory) 204*03ce13f7SAndroid Build Coastguard Worker 205*03ce13f7SAndroid Build Coastguard Worker if verbose: 206*03ce13f7SAndroid Build Coastguard Worker status(directory, checkoutable) # Success. 207*03ce13f7SAndroid Build Coastguard Worker 208*03ce13f7SAndroid Build Coastguard Worker 209*03ce13f7SAndroid Build Coastguard Workerdef parse_file_to_dict(path): 210*03ce13f7SAndroid Build Coastguard Worker dictionary = {} 211*03ce13f7SAndroid Build Coastguard Worker contents = open(path).read() 212*03ce13f7SAndroid Build Coastguard Worker # Need to convert Var() to vars[], so that the DEPS is actually Python. Var() 213*03ce13f7SAndroid Build Coastguard Worker # comes from Autoroller using gclient which has a slightly different DEPS 214*03ce13f7SAndroid Build Coastguard Worker # format. 215*03ce13f7SAndroid Build Coastguard Worker contents = re.sub(r"Var\((.*?)\)", r"vars[\1]", contents) 216*03ce13f7SAndroid Build Coastguard Worker exec(contents, dictionary) 217*03ce13f7SAndroid Build Coastguard Worker return dictionary 218*03ce13f7SAndroid Build Coastguard Worker 219*03ce13f7SAndroid Build Coastguard Worker 220*03ce13f7SAndroid Build Coastguard Workerdef git_sync_deps(deps_file_path, command_line_os_requests, verbose, treeless): 221*03ce13f7SAndroid Build Coastguard Worker """Grab dependencies, with optional platform support. 222*03ce13f7SAndroid Build Coastguard Worker 223*03ce13f7SAndroid Build Coastguard Worker Args: 224*03ce13f7SAndroid Build Coastguard Worker deps_file_path (string) Path to the DEPS file. 225*03ce13f7SAndroid Build Coastguard Worker 226*03ce13f7SAndroid Build Coastguard Worker command_line_os_requests (list of strings) Can be empty list. 227*03ce13f7SAndroid Build Coastguard Worker List of strings that should each be a key in the deps_os 228*03ce13f7SAndroid Build Coastguard Worker dictionary in the DEPS file. 229*03ce13f7SAndroid Build Coastguard Worker 230*03ce13f7SAndroid Build Coastguard Worker verbose (boolean): emit status info to stdout 231*03ce13f7SAndroid Build Coastguard Worker 232*03ce13f7SAndroid Build Coastguard Worker treeless (boolean): when true, clone as treeless instead of blobless 233*03ce13f7SAndroid Build Coastguard Worker 234*03ce13f7SAndroid Build Coastguard Worker Raises git Exceptions. 235*03ce13f7SAndroid Build Coastguard Worker """ 236*03ce13f7SAndroid Build Coastguard Worker (git,git_major,git_minor) = git_executable() 237*03ce13f7SAndroid Build Coastguard Worker assert git 238*03ce13f7SAndroid Build Coastguard Worker 239*03ce13f7SAndroid Build Coastguard Worker # --filter=tree:0 is available in git 2.20 and later 240*03ce13f7SAndroid Build Coastguard Worker if (git_major,git_minor) < (2,20): 241*03ce13f7SAndroid Build Coastguard Worker print("disabling --treeless: git is older than v2.20") 242*03ce13f7SAndroid Build Coastguard Worker treeless = False 243*03ce13f7SAndroid Build Coastguard Worker 244*03ce13f7SAndroid Build Coastguard Worker deps_file_directory = os.path.dirname(deps_file_path) 245*03ce13f7SAndroid Build Coastguard Worker deps_file = parse_file_to_dict(deps_file_path) 246*03ce13f7SAndroid Build Coastguard Worker dependencies = deps_file['deps'].copy() 247*03ce13f7SAndroid Build Coastguard Worker os_specific_dependencies = deps_file.get('deps_os', dict()) 248*03ce13f7SAndroid Build Coastguard Worker if 'all' in command_line_os_requests: 249*03ce13f7SAndroid Build Coastguard Worker for value in list(os_specific_dependencies.values()): 250*03ce13f7SAndroid Build Coastguard Worker dependencies.update(value) 251*03ce13f7SAndroid Build Coastguard Worker else: 252*03ce13f7SAndroid Build Coastguard Worker for os_name in command_line_os_requests: 253*03ce13f7SAndroid Build Coastguard Worker # Add OS-specific dependencies 254*03ce13f7SAndroid Build Coastguard Worker if os_name in os_specific_dependencies: 255*03ce13f7SAndroid Build Coastguard Worker dependencies.update(os_specific_dependencies[os_name]) 256*03ce13f7SAndroid Build Coastguard Worker for directory in dependencies: 257*03ce13f7SAndroid Build Coastguard Worker for other_dir in dependencies: 258*03ce13f7SAndroid Build Coastguard Worker if directory.startswith(other_dir + '/'): 259*03ce13f7SAndroid Build Coastguard Worker raise Exception('%r is parent of %r' % (other_dir, directory)) 260*03ce13f7SAndroid Build Coastguard Worker list_of_arg_lists = [] 261*03ce13f7SAndroid Build Coastguard Worker for directory in sorted(dependencies): 262*03ce13f7SAndroid Build Coastguard Worker if '@' in dependencies[directory]: 263*03ce13f7SAndroid Build Coastguard Worker repo, checkoutable = dependencies[directory].split('@', 1) 264*03ce13f7SAndroid Build Coastguard Worker else: 265*03ce13f7SAndroid Build Coastguard Worker raise Exception("please specify commit or tag") 266*03ce13f7SAndroid Build Coastguard Worker 267*03ce13f7SAndroid Build Coastguard Worker relative_directory = os.path.join(deps_file_directory, directory) 268*03ce13f7SAndroid Build Coastguard Worker 269*03ce13f7SAndroid Build Coastguard Worker list_of_arg_lists.append( 270*03ce13f7SAndroid Build Coastguard Worker (git, repo, checkoutable, relative_directory, verbose, treeless)) 271*03ce13f7SAndroid Build Coastguard Worker 272*03ce13f7SAndroid Build Coastguard Worker multithread(git_checkout_to_directory, list_of_arg_lists) 273*03ce13f7SAndroid Build Coastguard Worker 274*03ce13f7SAndroid Build Coastguard Worker for directory in deps_file.get('recursedeps', []): 275*03ce13f7SAndroid Build Coastguard Worker recursive_path = os.path.join(deps_file_directory, directory, 'DEPS') 276*03ce13f7SAndroid Build Coastguard Worker git_sync_deps(recursive_path, command_line_os_requests, verbose) 277*03ce13f7SAndroid Build Coastguard Worker 278*03ce13f7SAndroid Build Coastguard Worker 279*03ce13f7SAndroid Build Coastguard Workerdef multithread(function, list_of_arg_lists): 280*03ce13f7SAndroid Build Coastguard Worker # for args in list_of_arg_lists: 281*03ce13f7SAndroid Build Coastguard Worker # function(*args) 282*03ce13f7SAndroid Build Coastguard Worker # return 283*03ce13f7SAndroid Build Coastguard Worker threads = [] 284*03ce13f7SAndroid Build Coastguard Worker for args in list_of_arg_lists: 285*03ce13f7SAndroid Build Coastguard Worker thread = threading.Thread(None, function, None, args) 286*03ce13f7SAndroid Build Coastguard Worker thread.start() 287*03ce13f7SAndroid Build Coastguard Worker threads.append(thread) 288*03ce13f7SAndroid Build Coastguard Worker for thread in threads: 289*03ce13f7SAndroid Build Coastguard Worker thread.join() 290*03ce13f7SAndroid Build Coastguard Worker 291*03ce13f7SAndroid Build Coastguard Worker 292*03ce13f7SAndroid Build Coastguard Workerdef main(argv): 293*03ce13f7SAndroid Build Coastguard Worker argparser = argparse.ArgumentParser( 294*03ce13f7SAndroid Build Coastguard Worker prog = "git-sync-deps", 295*03ce13f7SAndroid Build Coastguard Worker description = "Checkout git-based dependencies as specified by the DEPS file", 296*03ce13f7SAndroid Build Coastguard Worker add_help=False # Because we want to print deps_os with -h option 297*03ce13f7SAndroid Build Coastguard Worker ) 298*03ce13f7SAndroid Build Coastguard Worker argparser.add_argument("--help", "-h", 299*03ce13f7SAndroid Build Coastguard Worker action='store_true', 300*03ce13f7SAndroid Build Coastguard Worker help="show this help message and exit") 301*03ce13f7SAndroid Build Coastguard Worker argparser.add_argument("--deps", 302*03ce13f7SAndroid Build Coastguard Worker default = os.environ.get('GIT_SYNC_DEPS_PATH', DEFAULT_DEPS_PATH), 303*03ce13f7SAndroid Build Coastguard Worker help="location of the the DEPS file") 304*03ce13f7SAndroid Build Coastguard Worker argparser.add_argument("--verbose", 305*03ce13f7SAndroid Build Coastguard Worker default=not bool(os.environ.get('GIT_SYNC_DEPS_QUIET', False)), 306*03ce13f7SAndroid Build Coastguard Worker action='store_true', 307*03ce13f7SAndroid Build Coastguard Worker help="be verbose: print status messages") 308*03ce13f7SAndroid Build Coastguard Worker argparser.add_argument("--treeless", 309*03ce13f7SAndroid Build Coastguard Worker default=False, 310*03ce13f7SAndroid Build Coastguard Worker action='store_true', 311*03ce13f7SAndroid Build Coastguard Worker help=""" 312*03ce13f7SAndroid Build Coastguard Worker Clone repos without trees (--filter=tree:0). 313*03ce13f7SAndroid Build Coastguard Worker This is the fastest option for a build machine, 314*03ce13f7SAndroid Build Coastguard Worker when you only need a single commit. 315*03ce13f7SAndroid Build Coastguard Worker Defers getting objects until checking out a commit. 316*03ce13f7SAndroid Build Coastguard Worker 317*03ce13f7SAndroid Build Coastguard Worker The default is to clone with trees but without blobs. 318*03ce13f7SAndroid Build Coastguard Worker 319*03ce13f7SAndroid Build Coastguard Worker Only takes effect if using git 2.20 or later. 320*03ce13f7SAndroid Build Coastguard Worker 321*03ce13f7SAndroid Build Coastguard Worker See https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/ 322*03ce13f7SAndroid Build Coastguard Worker """) 323*03ce13f7SAndroid Build Coastguard Worker argparser.add_argument("os_requests",nargs="*", 324*03ce13f7SAndroid Build Coastguard Worker help="OS requests, as keys in the deps_os dictionariy in the DEPS file") 325*03ce13f7SAndroid Build Coastguard Worker 326*03ce13f7SAndroid Build Coastguard Worker args = argparser.parse_args() 327*03ce13f7SAndroid Build Coastguard Worker if args.help: 328*03ce13f7SAndroid Build Coastguard Worker print(argparser.format_help()) 329*03ce13f7SAndroid Build Coastguard Worker print(EXTRA_HELP) 330*03ce13f7SAndroid Build Coastguard Worker print(get_deps_os_str(args.deps)) 331*03ce13f7SAndroid Build Coastguard Worker return 0 332*03ce13f7SAndroid Build Coastguard Worker 333*03ce13f7SAndroid Build Coastguard Worker git_sync_deps(args.deps, args.os_requests, args.verbose, args.treeless) 334*03ce13f7SAndroid Build Coastguard Worker return 0 335*03ce13f7SAndroid Build Coastguard Worker 336*03ce13f7SAndroid Build Coastguard Worker 337*03ce13f7SAndroid Build Coastguard Workerif __name__ == '__main__': 338*03ce13f7SAndroid Build Coastguard Worker exit(main(sys.argv[1:])) 339