|
| 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 | +""" |
| 7 | +Use this script to fetch all dependencies for V8 to run build_gn.py. |
| 8 | +
|
| 9 | +Usage: fetch_deps.py <v8-path> |
| 10 | +""" |
| 11 | + |
| 12 | +# for py2/py3 compatibility |
| 13 | +from __future__ import print_function |
| 14 | + |
| 15 | +import os |
| 16 | +import subprocess |
| 17 | +import sys |
| 18 | + |
| 19 | +import node_common |
| 20 | + |
| 21 | +GCLIENT_SOLUTION = [ |
| 22 | + { "name" : "v8", |
| 23 | + "url" : "https://chromium.googlesource.com/v8/v8.git", |
| 24 | + "deps_file" : "DEPS", |
| 25 | + "managed" : False, |
| 26 | + "custom_deps" : { |
| 27 | + # These deps are already part of Node.js. |
| 28 | + "v8/base/trace_event/common" : None, |
| 29 | + "v8/third_party/googletest/src" : None, |
| 30 | + # These deps are unnecessary for building. |
| 31 | + "v8/test/benchmarks/data" : None, |
| 32 | + "v8/testing/gmock" : None, |
| 33 | + "v8/test/mozilla/data" : None, |
| 34 | + "v8/test/test262/data" : None, |
| 35 | + "v8/test/test262/harness" : None, |
| 36 | + "v8/third_party/android_ndk" : None, |
| 37 | + "v8/third_party/android_sdk" : None, |
| 38 | + "v8/third_party/catapult" : None, |
| 39 | + "v8/third_party/colorama/src" : None, |
| 40 | + "v8/third_party/fuchsia-sdk" : None, |
| 41 | + "v8/third_party/instrumented_libraries" : None, |
| 42 | + "v8/tools/luci-go" : None, |
| 43 | + "v8/tools/swarming_client" : None, |
| 44 | + "v8/third_party/qemu-linux-x64" : None, |
| 45 | + }, |
| 46 | + }, |
| 47 | +] |
| 48 | + |
| 49 | +def EnsureGit(v8_path): |
| 50 | + def git(args): |
| 51 | + # shell=True needed on Windows to resolve git.bat. |
| 52 | + return subprocess.check_output( |
| 53 | + "git " + args, cwd=v8_path, shell=True).strip() |
| 54 | + |
| 55 | + expected_git_dir = os.path.join(v8_path, ".git") |
| 56 | + actual_git_dir = git("rev-parse --absolute-git-dir") |
| 57 | + if expected_git_dir == actual_git_dir: |
| 58 | + print("V8 is tracked stand-alone by git.") |
| 59 | + return False |
| 60 | + print("Initializing temporary git repository in v8.") |
| 61 | + git("init") |
| 62 | + git("config user.name \"Ada Lovelace\"") |
| 63 | + git( "config user.email [email protected]") |
| 64 | + git("commit --allow-empty -m init") |
| 65 | + return True |
| 66 | + |
| 67 | +def FetchDeps(v8_path): |
| 68 | + # Verify path. |
| 69 | + v8_path = os.path.abspath(v8_path) |
| 70 | + assert os.path.isdir(v8_path) |
| 71 | + |
| 72 | + # Check out depot_tools if necessary. |
| 73 | + depot_tools = node_common.EnsureDepotTools(v8_path, True) |
| 74 | + |
| 75 | + temporary_git = EnsureGit(v8_path) |
| 76 | + try: |
| 77 | + print("Fetching dependencies.") |
| 78 | + env = os.environ.copy() |
| 79 | + # gclient needs to have depot_tools in the PATH. |
| 80 | + env["PATH"] = depot_tools + os.pathsep + env["PATH"] |
| 81 | + gclient = os.path.join(depot_tools, "gclient.py") |
| 82 | + spec = "solutions = %s" % GCLIENT_SOLUTION |
| 83 | + subprocess.check_call([sys.executable, gclient, "sync", "--spec", spec], |
| 84 | + cwd=os.path.join(v8_path, os.path.pardir), |
| 85 | + env=env) |
| 86 | + except: |
| 87 | + raise |
| 88 | + finally: |
| 89 | + if temporary_git: |
| 90 | + node_common.UninitGit(v8_path) |
| 91 | + # Clean up .gclient_entries file. |
| 92 | + gclient_entries = os.path.normpath( |
| 93 | + os.path.join(v8_path, os.pardir, ".gclient_entries")) |
| 94 | + if os.path.isfile(gclient_entries): |
| 95 | + os.remove(gclient_entries) |
| 96 | + |
| 97 | + return depot_tools |
| 98 | + |
| 99 | + |
| 100 | +if __name__ == "__main__": |
| 101 | + FetchDeps(sys.argv[1]) |
0 commit comments