11cb0ef41Sopenharmony_ci#!/usr/bin/env python3 21cb0ef41Sopenharmony_ci# Copyright 2017 the V8 project authors. All rights reserved. 31cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 41cb0ef41Sopenharmony_ci# found in the LICENSE file. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci""" 71cb0ef41Sopenharmony_ciUse this script to fetch all dependencies for V8 to run build_gn.py. 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciUsage: fetch_deps.py <v8-path> 101cb0ef41Sopenharmony_ci""" 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci# for py2/py3 compatibility 131cb0ef41Sopenharmony_cifrom __future__ import print_function 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciimport os 161cb0ef41Sopenharmony_ciimport subprocess 171cb0ef41Sopenharmony_ciimport sys 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciimport node_common 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciGCLIENT_SOLUTION = [ 221cb0ef41Sopenharmony_ci { "name" : "v8", 231cb0ef41Sopenharmony_ci "url" : "https://chromium.googlesource.com/v8/v8.git", 241cb0ef41Sopenharmony_ci "deps_file" : "DEPS", 251cb0ef41Sopenharmony_ci "managed" : False, 261cb0ef41Sopenharmony_ci "custom_deps" : { 271cb0ef41Sopenharmony_ci # These deps are already part of Node.js. 281cb0ef41Sopenharmony_ci "v8/base/trace_event/common" : None, 291cb0ef41Sopenharmony_ci # These deps are unnecessary for building. 301cb0ef41Sopenharmony_ci "v8/test/benchmarks/data" : None, 311cb0ef41Sopenharmony_ci "v8/testing/gmock" : None, 321cb0ef41Sopenharmony_ci "v8/test/mozilla/data" : None, 331cb0ef41Sopenharmony_ci "v8/test/test262/data" : None, 341cb0ef41Sopenharmony_ci "v8/test/test262/harness" : None, 351cb0ef41Sopenharmony_ci "v8/third_party/android_ndk" : None, 361cb0ef41Sopenharmony_ci "v8/third_party/android_sdk" : None, 371cb0ef41Sopenharmony_ci "v8/third_party/catapult" : None, 381cb0ef41Sopenharmony_ci "v8/third_party/colorama/src" : None, 391cb0ef41Sopenharmony_ci "v8/third_party/fuchsia-sdk" : None, 401cb0ef41Sopenharmony_ci "v8/third_party/instrumented_libraries" : None, 411cb0ef41Sopenharmony_ci "v8/tools/luci-go" : None, 421cb0ef41Sopenharmony_ci "v8/tools/swarming_client" : None, 431cb0ef41Sopenharmony_ci "v8/third_party/qemu-linux-x64" : None, 441cb0ef41Sopenharmony_ci }, 451cb0ef41Sopenharmony_ci }, 461cb0ef41Sopenharmony_ci] 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_cidef EnsureGit(v8_path): 491cb0ef41Sopenharmony_ci def git(args): 501cb0ef41Sopenharmony_ci # shell=True needed on Windows to resolve git.bat. 511cb0ef41Sopenharmony_ci return subprocess.check_output( 521cb0ef41Sopenharmony_ci "git " + args, cwd=v8_path, shell=True).strip() 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci expected_git_dir = os.path.join(v8_path, ".git") 551cb0ef41Sopenharmony_ci actual_git_dir = git("rev-parse --absolute-git-dir") 561cb0ef41Sopenharmony_ci if expected_git_dir == actual_git_dir: 571cb0ef41Sopenharmony_ci print("V8 is tracked stand-alone by git.") 581cb0ef41Sopenharmony_ci return False 591cb0ef41Sopenharmony_ci print("Initializing temporary git repository in v8.") 601cb0ef41Sopenharmony_ci git("init") 611cb0ef41Sopenharmony_ci git("config user.name \"Ada Lovelace\"") 621cb0ef41Sopenharmony_ci git("config user.email ada@lovela.ce") 631cb0ef41Sopenharmony_ci git("commit --allow-empty -m init") 641cb0ef41Sopenharmony_ci return True 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_cidef FetchDeps(v8_path): 671cb0ef41Sopenharmony_ci # Verify path. 681cb0ef41Sopenharmony_ci v8_path = os.path.abspath(v8_path) 691cb0ef41Sopenharmony_ci assert os.path.isdir(v8_path) 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci # Check out depot_tools if necessary. 721cb0ef41Sopenharmony_ci depot_tools = node_common.EnsureDepotTools(v8_path, True) 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci temporary_git = EnsureGit(v8_path) 751cb0ef41Sopenharmony_ci try: 761cb0ef41Sopenharmony_ci print("Fetching dependencies.") 771cb0ef41Sopenharmony_ci env = os.environ.copy() 781cb0ef41Sopenharmony_ci # gclient needs to have depot_tools in the PATH. 791cb0ef41Sopenharmony_ci env["PATH"] = depot_tools + os.pathsep + env["PATH"] 801cb0ef41Sopenharmony_ci gclient = os.path.join(depot_tools, "gclient.py") 811cb0ef41Sopenharmony_ci spec = "solutions = %s" % GCLIENT_SOLUTION 821cb0ef41Sopenharmony_ci subprocess.check_call([sys.executable, gclient, "sync", "--spec", spec], 831cb0ef41Sopenharmony_ci cwd=os.path.join(v8_path, os.path.pardir), 841cb0ef41Sopenharmony_ci env=env) 851cb0ef41Sopenharmony_ci except: 861cb0ef41Sopenharmony_ci raise 871cb0ef41Sopenharmony_ci finally: 881cb0ef41Sopenharmony_ci if temporary_git: 891cb0ef41Sopenharmony_ci node_common.UninitGit(v8_path) 901cb0ef41Sopenharmony_ci # Clean up .gclient_entries file. 911cb0ef41Sopenharmony_ci gclient_entries = os.path.normpath( 921cb0ef41Sopenharmony_ci os.path.join(v8_path, os.pardir, ".gclient_entries")) 931cb0ef41Sopenharmony_ci if os.path.isfile(gclient_entries): 941cb0ef41Sopenharmony_ci os.remove(gclient_entries) 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci return depot_tools 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ciif __name__ == "__main__": 1001cb0ef41Sopenharmony_ci FetchDeps(sys.argv[1]) 101