2017-12-18 09:19:46 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2017 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2019-02-19 08:28:26 +00:00
|
|
|
# for py2/py3 compatibility
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-12-18 09:19:46 +00:00
|
|
|
import os
|
2018-04-19 13:42:55 +00:00
|
|
|
import pipes
|
2017-12-18 09:19:46 +00:00
|
|
|
import shutil
|
|
|
|
import stat
|
|
|
|
import subprocess
|
2018-07-25 13:16:21 +00:00
|
|
|
import sys
|
2017-12-18 09:19:46 +00:00
|
|
|
|
|
|
|
DEPOT_TOOLS_URL = \
|
|
|
|
"https://chromium.googlesource.com/chromium/tools/depot_tools.git"
|
|
|
|
|
|
|
|
def EnsureDepotTools(v8_path, fetch_if_not_exist):
|
|
|
|
def _Get(v8_path):
|
|
|
|
depot_tools = os.path.join(v8_path, "_depot_tools")
|
|
|
|
try:
|
2018-04-05 14:03:46 +00:00
|
|
|
gclient_path = os.path.join(depot_tools, "gclient.py")
|
|
|
|
if os.path.isfile(gclient_path):
|
2017-12-18 09:19:46 +00:00
|
|
|
return depot_tools
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if fetch_if_not_exist:
|
2019-02-19 08:28:26 +00:00
|
|
|
print("Checking out depot_tools.")
|
2018-04-19 13:42:55 +00:00
|
|
|
# shell=True needed on Windows to resolve git.bat.
|
|
|
|
subprocess.check_call("git clone {} {}".format(
|
|
|
|
pipes.quote(DEPOT_TOOLS_URL),
|
|
|
|
pipes.quote(depot_tools)), shell=True)
|
2018-07-19 06:43:00 +00:00
|
|
|
# Using check_output to hide warning messages.
|
|
|
|
subprocess.check_output(
|
|
|
|
[sys.executable, gclient_path, "metrics", "--opt-out"],
|
|
|
|
cwd=depot_tools)
|
2017-12-18 09:19:46 +00:00
|
|
|
return depot_tools
|
|
|
|
return None
|
|
|
|
depot_tools = _Get(v8_path)
|
|
|
|
assert depot_tools is not None
|
2019-02-19 08:28:26 +00:00
|
|
|
print("Using depot tools in %s" % depot_tools)
|
2017-12-18 09:19:46 +00:00
|
|
|
return depot_tools
|
|
|
|
|
|
|
|
def UninitGit(v8_path):
|
2019-02-19 08:28:26 +00:00
|
|
|
print("Uninitializing temporary git repository")
|
2017-12-18 09:19:46 +00:00
|
|
|
target = os.path.join(v8_path, ".git")
|
|
|
|
if os.path.isdir(target):
|
2019-02-19 08:28:26 +00:00
|
|
|
print(">> Cleaning up %s" % target)
|
2017-12-18 09:19:46 +00:00
|
|
|
def OnRmError(func, path, exec_info):
|
|
|
|
# This might happen on Windows
|
|
|
|
os.chmod(path, stat.S_IWRITE)
|
|
|
|
os.unlink(path)
|
|
|
|
shutil.rmtree(target, onerror=OnRmError)
|