1#!/usr/bin/env python3 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# for py2/py3 compatibility 7from __future__ import print_function 8 9import os 10import pipes 11import shutil 12import stat 13import subprocess 14import sys 15 16DEPOT_TOOLS_URL = \ 17 "https://chromium.googlesource.com/chromium/tools/depot_tools.git" 18 19def EnsureDepotTools(v8_path, fetch_if_not_exist): 20 def _Get(v8_path): 21 depot_tools = os.path.join(v8_path, "_depot_tools") 22 try: 23 gclient_path = os.path.join(depot_tools, "gclient.py") 24 if os.path.isfile(gclient_path): 25 return depot_tools 26 except: 27 pass 28 if fetch_if_not_exist: 29 print("Checking out depot_tools.") 30 # shell=True needed on Windows to resolve git.bat. 31 subprocess.check_call("git clone {} {}".format( 32 pipes.quote(DEPOT_TOOLS_URL), 33 pipes.quote(depot_tools)), shell=True) 34 # Using check_output to hide warning messages. 35 subprocess.check_output( 36 [sys.executable, gclient_path, "metrics", "--opt-out"], 37 cwd=depot_tools) 38 return depot_tools 39 return None 40 depot_tools = _Get(v8_path) 41 assert depot_tools is not None 42 print("Using depot tools in %s" % depot_tools) 43 return depot_tools 44 45def UninitGit(v8_path): 46 print("Uninitializing temporary git repository") 47 target = os.path.join(v8_path, ".git") 48 if os.path.isdir(target): 49 print(">> Cleaning up %s" % target) 50 def OnRmError(func, path, exec_info): 51 # This might happen on Windows 52 os.chmod(path, stat.S_IWRITE) 53 os.unlink(path) 54 shutil.rmtree(target, onerror=OnRmError) 55