1 #!/usr/bin/env python 2 # Copyright 2017 the V8 project authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 import os 7 import pipes 8 import shutil 9 import stat 10 import subprocess 11 import sys 12 13 DEPOT_TOOLS_URL = \ 14 "https://chromium.googlesource.com/chromium/tools/depot_tools.git" 15 16 def EnsureDepotTools(v8_path, fetch_if_not_exist): 17 def _Get(v8_path): 18 depot_tools = os.path.join(v8_path, "_depot_tools") 19 try: 20 gclient_path = os.path.join(depot_tools, "gclient.py") 21 if os.path.isfile(gclient_path): 22 return depot_tools 23 except: 24 pass 25 if fetch_if_not_exist: 26 print "Checking out depot_tools." 27 # shell=True needed on Windows to resolve git.bat. 28 subprocess.check_call("git clone {} {}".format( 29 pipes.quote(DEPOT_TOOLS_URL), 30 pipes.quote(depot_tools)), shell=True) 31 # Using check_output to hide warning messages. 32 subprocess.check_output( 33 [sys.executable, gclient_path, "metrics", "--opt-out"], 34 cwd=depot_tools) 35 return depot_tools 36 return None 37 depot_tools = _Get(v8_path) 38 assert depot_tools is not None 39 print "Using depot tools in %s" % depot_tools 40 return depot_tools 41 42 def UninitGit(v8_path): 43 print "Uninitializing temporary git repository" 44 target = os.path.join(v8_path, ".git") 45 if os.path.isdir(target): 46 print ">> Cleaning up %s" % target 47 def OnRmError(func, path, exec_info): 48 # This might happen on Windows 49 os.chmod(path, stat.S_IWRITE) 50 os.unlink(path) 51 shutil.rmtree(target, onerror=OnRmError) 52