Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: take ownership of deps/v8/tools/node #39222

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ tools/*/*.i.tmp
/deps/uv/.github/
/deps/uv/docs/code/
/deps/uv/docs/src/guide/
# Ignore dependencies fetched by deps/v8/tools/node/fetch_deps.py
# Ignore dependencies fetched by tools/v8/fetch_deps.py
/deps/.cipd

# === Rules for Windows vcbuild.bat ===
Expand Down
2 changes: 1 addition & 1 deletion tools/make-v8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ V8_BUILD_OPTIONS=$2

cd deps/v8 || exit
find . -type d -name .git -print0 | xargs -0 rm -rf
tools/node/fetch_deps.py .
../../tools/v8/fetch_deps.py .

ARCH="`arch`"
if [ "$ARCH" = "s390x" ] || [ "$ARCH" = "ppc64le" ]; then
Expand Down
101 changes: 101 additions & 0 deletions tools/v8/fetch_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/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.

"""
Use this script to fetch all dependencies for V8 to run build_gn.py.

Usage: fetch_deps.py <v8-path>
"""

# for py2/py3 compatibility
from __future__ import print_function

import os
import subprocess
import sys

import node_common

GCLIENT_SOLUTION = [
{ "name" : "v8",
"url" : "https://chromium.googlesource.com/v8/v8.git",
"deps_file" : "DEPS",
"managed" : False,
"custom_deps" : {
# These deps are already part of Node.js.
"v8/base/trace_event/common" : None,
"v8/third_party/googletest/src" : None,
# These deps are unnecessary for building.
"v8/test/benchmarks/data" : None,
"v8/testing/gmock" : None,
"v8/test/mozilla/data" : None,
"v8/test/test262/data" : None,
"v8/test/test262/harness" : None,
"v8/third_party/android_ndk" : None,
"v8/third_party/android_sdk" : None,
"v8/third_party/catapult" : None,
"v8/third_party/colorama/src" : None,
"v8/third_party/fuchsia-sdk" : None,
"v8/third_party/instrumented_libraries" : None,
"v8/tools/luci-go" : None,
"v8/tools/swarming_client" : None,
"v8/third_party/qemu-linux-x64" : None,
},
},
]

def EnsureGit(v8_path):
def git(args):
# shell=True needed on Windows to resolve git.bat.
return subprocess.check_output(
"git " + args, cwd=v8_path, shell=True).strip()

expected_git_dir = os.path.join(v8_path, ".git")
actual_git_dir = git("rev-parse --absolute-git-dir")
if expected_git_dir == actual_git_dir:
print("V8 is tracked stand-alone by git.")
return False
print("Initializing temporary git repository in v8.")
git("init")
git("config user.name \"Ada Lovelace\"")
git("config user.email ada@lovela.ce")
git("commit --allow-empty -m init")
return True

def FetchDeps(v8_path):
# Verify path.
v8_path = os.path.abspath(v8_path)
assert os.path.isdir(v8_path)

# Check out depot_tools if necessary.
depot_tools = node_common.EnsureDepotTools(v8_path, True)

temporary_git = EnsureGit(v8_path)
try:
print("Fetching dependencies.")
env = os.environ.copy()
# gclient needs to have depot_tools in the PATH.
env["PATH"] = depot_tools + os.pathsep + env["PATH"]
gclient = os.path.join(depot_tools, "gclient.py")
spec = "solutions = %s" % GCLIENT_SOLUTION
subprocess.check_call([sys.executable, gclient, "sync", "--spec", spec],
cwd=os.path.join(v8_path, os.path.pardir),
env=env)
except:
raise
finally:
if temporary_git:
node_common.UninitGit(v8_path)
# Clean up .gclient_entries file.
gclient_entries = os.path.normpath(
os.path.join(v8_path, os.pardir, ".gclient_entries"))
if os.path.isfile(gclient_entries):
os.remove(gclient_entries)

return depot_tools


if __name__ == "__main__":
FetchDeps(sys.argv[1])
54 changes: 54 additions & 0 deletions tools/v8/node_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/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.

# for py2/py3 compatibility
from __future__ import print_function

import os
import pipes
import shutil
import stat
import subprocess
import sys

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:
gclient_path = os.path.join(depot_tools, "gclient.py")
if os.path.isfile(gclient_path):
return depot_tools
except:
pass
if fetch_if_not_exist:
print("Checking out depot_tools.")
# 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)
# Using check_output to hide warning messages.
subprocess.check_output(
[sys.executable, gclient_path, "metrics", "--opt-out"],
cwd=depot_tools)
return depot_tools
return None
depot_tools = _Get(v8_path)
assert depot_tools is not None
print("Using depot tools in %s" % depot_tools)
return depot_tools

def UninitGit(v8_path):
print("Uninitializing temporary git repository")
target = os.path.join(v8_path, ".git")
if os.path.isdir(target):
print(">> Cleaning up %s" % target)
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)