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