1bf215546Sopenharmony_ciPatch based from diff with skia repository from commit 2bf215546Sopenharmony_ci013397884c73959dc07cb0a26ee742b1cdfbda8a 3bf215546Sopenharmony_ci 4bf215546Sopenharmony_ciAdds support for Python3, but removes the constraint of only SHA based refs in 5bf215546Sopenharmony_ciDEPS 6bf215546Sopenharmony_cidiff --git a/tools/git-sync-deps b/tools/git-sync-deps 7bf215546Sopenharmony_ciindex c7379c0b5c..f63d4d9ccf 100755 8bf215546Sopenharmony_ci--- a/tools/git-sync-deps 9bf215546Sopenharmony_ci+++ b/tools/git-sync-deps 10bf215546Sopenharmony_ci@@ -43,7 +43,7 @@ def git_executable(): 11bf215546Sopenharmony_ci A string suitable for passing to subprocess functions, or None. 12bf215546Sopenharmony_ci """ 13bf215546Sopenharmony_ci envgit = os.environ.get('GIT_EXECUTABLE') 14bf215546Sopenharmony_ci- searchlist = ['git'] 15bf215546Sopenharmony_ci+ searchlist = ['git', 'git.bat'] 16bf215546Sopenharmony_ci if envgit: 17bf215546Sopenharmony_ci searchlist.insert(0, envgit) 18bf215546Sopenharmony_ci with open(os.devnull, 'w') as devnull: 19bf215546Sopenharmony_ci@@ -94,21 +94,25 @@ def is_git_toplevel(git, directory): 20bf215546Sopenharmony_ci try: 21bf215546Sopenharmony_ci toplevel = subprocess.check_output( 22bf215546Sopenharmony_ci [git, 'rev-parse', '--show-toplevel'], cwd=directory).strip() 23bf215546Sopenharmony_ci- return os.path.realpath(directory) == os.path.realpath(toplevel) 24bf215546Sopenharmony_ci+ return os.path.realpath(directory) == os.path.realpath(toplevel.decode()) 25bf215546Sopenharmony_ci except subprocess.CalledProcessError: 26bf215546Sopenharmony_ci return False 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci-def status(directory, checkoutable): 30bf215546Sopenharmony_ci- def truncate(s, length): 31bf215546Sopenharmony_ci+def status(directory, commithash, change): 32bf215546Sopenharmony_ci+ def truncate_beginning(s, length): 33bf215546Sopenharmony_ci+ return s if len(s) <= length else '...' + s[-(length-3):] 34bf215546Sopenharmony_ci+ def truncate_end(s, length): 35bf215546Sopenharmony_ci return s if len(s) <= length else s[:(length - 3)] + '...' 36bf215546Sopenharmony_ci+ 37bf215546Sopenharmony_ci dlen = 36 38bf215546Sopenharmony_ci- directory = truncate(directory, dlen) 39bf215546Sopenharmony_ci- checkoutable = truncate(checkoutable, 40) 40bf215546Sopenharmony_ci- sys.stdout.write('%-*s @ %s\n' % (dlen, directory, checkoutable)) 41bf215546Sopenharmony_ci+ directory = truncate_beginning(directory, dlen) 42bf215546Sopenharmony_ci+ commithash = truncate_end(commithash, 40) 43bf215546Sopenharmony_ci+ symbol = '>' if change else '@' 44bf215546Sopenharmony_ci+ sys.stdout.write('%-*s %s %s\n' % (dlen, directory, symbol, commithash)) 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci-def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 48bf215546Sopenharmony_ci+def git_checkout_to_directory(git, repo, commithash, directory, verbose): 49bf215546Sopenharmony_ci """Checkout (and clone if needed) a Git repository. 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci Args: 52bf215546Sopenharmony_ci@@ -117,8 +121,7 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 53bf215546Sopenharmony_ci repo (string) the location of the repository, suitable 54bf215546Sopenharmony_ci for passing to `git clone`. 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci- checkoutable (string) a tag, branch, or commit, suitable for 57bf215546Sopenharmony_ci- passing to `git checkout` 58bf215546Sopenharmony_ci+ commithash (string) a commit, suitable for passing to `git checkout` 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci directory (string) the path into which the repository 61bf215546Sopenharmony_ci should be checked out. 62bf215546Sopenharmony_ci@@ -129,7 +132,12 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 63bf215546Sopenharmony_ci """ 64bf215546Sopenharmony_ci if not os.path.isdir(directory): 65bf215546Sopenharmony_ci subprocess.check_call( 66bf215546Sopenharmony_ci- [git, 'clone', '--quiet', repo, directory]) 67bf215546Sopenharmony_ci+ [git, 'clone', '--quiet', '--no-checkout', repo, directory]) 68bf215546Sopenharmony_ci+ subprocess.check_call([git, 'checkout', '--quiet', commithash], 69bf215546Sopenharmony_ci+ cwd=directory) 70bf215546Sopenharmony_ci+ if verbose: 71bf215546Sopenharmony_ci+ status(directory, commithash, True) 72bf215546Sopenharmony_ci+ return 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci if not is_git_toplevel(git, directory): 75bf215546Sopenharmony_ci # if the directory exists, but isn't a git repo, you will modify 76bf215546Sopenharmony_ci@@ -145,11 +153,11 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 77bf215546Sopenharmony_ci with open(os.devnull, 'w') as devnull: 78bf215546Sopenharmony_ci # If this fails, we will fetch before trying again. Don't spam user 79bf215546Sopenharmony_ci # with error infomation. 80bf215546Sopenharmony_ci- if 0 == subprocess.call([git, 'checkout', '--quiet', checkoutable], 81bf215546Sopenharmony_ci+ if 0 == subprocess.call([git, 'checkout', '--quiet', commithash], 82bf215546Sopenharmony_ci cwd=directory, stderr=devnull): 83bf215546Sopenharmony_ci # if this succeeds, skip slow `git fetch`. 84bf215546Sopenharmony_ci if verbose: 85bf215546Sopenharmony_ci- status(directory, checkoutable) # Success. 86bf215546Sopenharmony_ci+ status(directory, commithash, False) # Success. 87bf215546Sopenharmony_ci return 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci # If the repo has changed, always force use of the correct repo. 90bf215546Sopenharmony_ci@@ -159,18 +167,24 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci subprocess.check_call([git, 'fetch', '--quiet'], cwd=directory) 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci- subprocess.check_call([git, 'checkout', '--quiet', checkoutable], cwd=directory) 95bf215546Sopenharmony_ci+ subprocess.check_call([git, 'checkout', '--quiet', commithash], cwd=directory) 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci if verbose: 98bf215546Sopenharmony_ci- status(directory, checkoutable) # Success. 99bf215546Sopenharmony_ci+ status(directory, commithash, True) # Success. 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci def parse_file_to_dict(path): 103bf215546Sopenharmony_ci dictionary = {} 104bf215546Sopenharmony_ci- execfile(path, dictionary) 105bf215546Sopenharmony_ci+ with open(path) as f: 106bf215546Sopenharmony_ci+ exec('def Var(x): return vars[x]\n' + f.read(), dictionary) 107bf215546Sopenharmony_ci return dictionary 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci+def is_sha1_sum(s): 111bf215546Sopenharmony_ci+ """SHA1 sums are 160 bits, encoded as lowercase hexadecimal.""" 112bf215546Sopenharmony_ci+ return len(s) == 40 and all(c in '0123456789abcdef' for c in s) 113bf215546Sopenharmony_ci+ 114bf215546Sopenharmony_ci+ 115bf215546Sopenharmony_ci def git_sync_deps(deps_file_path, command_line_os_requests, verbose): 116bf215546Sopenharmony_ci """Grab dependencies, with optional platform support. 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ci@@ -204,19 +218,19 @@ def git_sync_deps(deps_file_path, command_line_os_requests, verbose): 119bf215546Sopenharmony_ci raise Exception('%r is parent of %r' % (other_dir, directory)) 120bf215546Sopenharmony_ci list_of_arg_lists = [] 121bf215546Sopenharmony_ci for directory in sorted(dependencies): 122bf215546Sopenharmony_ci- if not isinstance(dependencies[directory], basestring): 123bf215546Sopenharmony_ci+ if not isinstance(dependencies[directory], str): 124bf215546Sopenharmony_ci if verbose: 125bf215546Sopenharmony_ci- print 'Skipping "%s".' % directory 126bf215546Sopenharmony_ci+ sys.stdout.write( 'Skipping "%s".\n' % directory) 127bf215546Sopenharmony_ci continue 128bf215546Sopenharmony_ci if '@' in dependencies[directory]: 129bf215546Sopenharmony_ci- repo, checkoutable = dependencies[directory].split('@', 1) 130bf215546Sopenharmony_ci+ repo, commithash = dependencies[directory].split('@', 1) 131bf215546Sopenharmony_ci else: 132bf215546Sopenharmony_ci- raise Exception("please specify commit or tag") 133bf215546Sopenharmony_ci+ raise Exception("please specify commit") 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci relative_directory = os.path.join(deps_file_directory, directory) 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci list_of_arg_lists.append( 138bf215546Sopenharmony_ci- (git, repo, checkoutable, relative_directory, verbose)) 139bf215546Sopenharmony_ci+ (git, repo, commithash, relative_directory, verbose)) 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ci multithread(git_checkout_to_directory, list_of_arg_lists) 142bf215546Sopenharmony_ci 143