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