2017-12-18 09:19:46 +00:00
|
|
|
#!/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 build libv8_monolith.a as dependency for Node.js
|
|
|
|
Required dependencies can be fetched with fetch_deps.py.
|
|
|
|
|
|
|
|
Usage: build_gn.py <Debug/Release> <v8-path> <build-path> [<build-flags>]...
|
|
|
|
|
|
|
|
Build flags are passed either as "strings" or numeric value. True/false
|
|
|
|
are represented as 1/0. E.g.
|
|
|
|
|
|
|
|
v8_promise_internal_field_count=2
|
|
|
|
target_cpu="x64"
|
|
|
|
v8_enable_disassembler=0
|
|
|
|
"""
|
|
|
|
|
2018-01-18 09:31:00 +00:00
|
|
|
import argparse
|
2017-12-18 09:19:46 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import node_common
|
|
|
|
|
|
|
|
GN_ARGS = [
|
2018-04-24 13:42:29 +00:00
|
|
|
"v8_monolithic=true",
|
|
|
|
"is_component_build=false",
|
|
|
|
"v8_use_external_startup_data=false",
|
|
|
|
"use_custom_libcxx=false",
|
2017-12-18 09:19:46 +00:00
|
|
|
]
|
|
|
|
|
2018-01-18 09:31:00 +00:00
|
|
|
BUILD_TARGET = "v8_monolith"
|
|
|
|
|
2018-04-24 13:42:29 +00:00
|
|
|
def FindTargetOs(flags):
|
|
|
|
for flag in flags:
|
|
|
|
if flag.startswith("target_os="):
|
|
|
|
return flag[len("target_os="):].strip('"')
|
|
|
|
raise Exception('No target_os was set.')
|
|
|
|
|
2018-01-18 09:31:00 +00:00
|
|
|
def FindGn(options):
|
|
|
|
if options.host_os == "linux":
|
|
|
|
os_path = "linux64"
|
|
|
|
elif options.host_os == "mac":
|
|
|
|
os_path = "mac"
|
|
|
|
elif options.host_os == "win":
|
|
|
|
os_path = "win"
|
|
|
|
else:
|
|
|
|
raise "Operating system not supported by GN"
|
|
|
|
return os.path.join(options.v8_path, "buildtools", os_path, "gn")
|
2017-12-18 09:19:46 +00:00
|
|
|
|
2018-01-18 09:31:00 +00:00
|
|
|
def GenerateBuildFiles(options):
|
|
|
|
gn = FindGn(options)
|
2018-04-24 13:42:29 +00:00
|
|
|
gn_args = list(GN_ARGS)
|
|
|
|
target_os = FindTargetOs(options.flag)
|
|
|
|
if target_os != "win":
|
|
|
|
gn_args.append("use_sysroot=false")
|
|
|
|
|
2018-01-18 09:31:00 +00:00
|
|
|
for flag in options.flag:
|
2017-12-18 09:19:46 +00:00
|
|
|
flag = flag.replace("=1", "=true")
|
|
|
|
flag = flag.replace("=0", "=false")
|
|
|
|
flag = flag.replace("target_cpu=ia32", "target_cpu=\"x86\"")
|
2018-01-18 09:31:00 +00:00
|
|
|
gn_args.append(flag)
|
2018-04-17 16:42:54 +00:00
|
|
|
if options.mode == "Debug":
|
2018-04-24 13:42:29 +00:00
|
|
|
gn_args.append("is_debug=true")
|
2018-01-18 09:31:00 +00:00
|
|
|
else:
|
2018-04-24 13:42:29 +00:00
|
|
|
gn_args.append("is_debug=false")
|
|
|
|
|
|
|
|
flattened_args = ' '.join(gn_args)
|
2019-02-04 16:13:14 +00:00
|
|
|
if options.extra_gn_args:
|
|
|
|
flattened_args += ' ' + options.extra_gn_args
|
2018-01-18 09:31:00 +00:00
|
|
|
|
2018-04-24 13:42:29 +00:00
|
|
|
args = [gn, "gen", options.build_path, "-q", "--args=" + flattened_args]
|
|
|
|
subprocess.check_call(args)
|
2018-01-18 09:31:00 +00:00
|
|
|
|
|
|
|
def Build(options):
|
|
|
|
depot_tools = node_common.EnsureDepotTools(options.v8_path, False)
|
|
|
|
ninja = os.path.join(depot_tools, "ninja")
|
2018-04-24 13:42:29 +00:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
# Required because there is an extension-less file called "ninja".
|
|
|
|
ninja += ".exe"
|
|
|
|
args = [ninja, "-C", options.build_path, BUILD_TARGET]
|
|
|
|
if options.max_load:
|
|
|
|
args += ["-l" + options.max_load]
|
|
|
|
if options.max_jobs:
|
|
|
|
args += ["-j" + options.max_jobs]
|
|
|
|
else:
|
|
|
|
with open(os.path.join(options.build_path, "args.gn")) as f:
|
|
|
|
if "use_goma = true" in f.read():
|
|
|
|
args += ["-j500"]
|
|
|
|
subprocess.check_call(args)
|
2018-01-18 09:31:00 +00:00
|
|
|
|
|
|
|
def ParseOptions(args):
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Build %s with GN" % BUILD_TARGET)
|
|
|
|
parser.add_argument("--mode", help="Build mode (Release/Debug)")
|
2018-04-24 13:42:29 +00:00
|
|
|
parser.add_argument("--v8_path", help="Path to V8", required=True)
|
|
|
|
parser.add_argument("--build_path", help="Path to build result",
|
|
|
|
required=True)
|
2018-01-18 09:31:00 +00:00
|
|
|
parser.add_argument("--flag", help="Translate GYP flag to GN",
|
|
|
|
action="append")
|
|
|
|
parser.add_argument("--host_os", help="Current operating system")
|
2018-04-24 13:42:29 +00:00
|
|
|
parser.add_argument("--bundled-win-toolchain",
|
|
|
|
help="Value for DEPOT_TOOLS_WIN_TOOLCHAIN")
|
2018-04-25 14:08:07 +00:00
|
|
|
parser.add_argument("--bundled-win-toolchain-root",
|
|
|
|
help="Value for DEPOT_TOOLS_WIN_TOOLCHAIN_ROOT")
|
2018-04-24 13:42:29 +00:00
|
|
|
parser.add_argument("--depot-tools", help="Absolute path to depot_tools")
|
2019-02-04 16:13:14 +00:00
|
|
|
parser.add_argument("--extra-gn-args", help="Additional GN args")
|
2018-04-24 13:42:29 +00:00
|
|
|
parser.add_argument("--build", help="Run ninja as opposed to gn gen.",
|
|
|
|
action="store_true")
|
|
|
|
parser.add_argument("--max-jobs", help="ninja's -j parameter")
|
|
|
|
parser.add_argument("--max-load", help="ninja's -l parameter")
|
2018-01-18 09:31:00 +00:00
|
|
|
options = parser.parse_args(args)
|
2017-12-18 09:19:46 +00:00
|
|
|
|
2018-04-24 13:42:29 +00:00
|
|
|
options.build_path = os.path.abspath(options.build_path)
|
2017-12-18 09:19:46 +00:00
|
|
|
|
2018-04-24 13:42:29 +00:00
|
|
|
if not options.build:
|
|
|
|
assert options.host_os
|
|
|
|
assert options.mode == "Debug" or options.mode == "Release"
|
|
|
|
|
|
|
|
options.v8_path = os.path.abspath(options.v8_path)
|
|
|
|
assert os.path.isdir(options.v8_path)
|
2017-12-18 09:19:46 +00:00
|
|
|
|
2018-01-18 09:31:00 +00:00
|
|
|
return options
|
2017-12-18 09:19:46 +00:00
|
|
|
|
2018-04-24 13:42:29 +00:00
|
|
|
|
2017-12-18 09:19:46 +00:00
|
|
|
if __name__ == "__main__":
|
2018-01-18 09:31:00 +00:00
|
|
|
options = ParseOptions(sys.argv[1:])
|
2018-04-24 13:42:29 +00:00
|
|
|
# Build can result in running gn gen, so need to set environment variables
|
|
|
|
# for build as well as generate.
|
2018-04-25 14:08:07 +00:00
|
|
|
if options.bundled_win_toolchain:
|
|
|
|
os.environ['DEPOT_TOOLS_WIN_TOOLCHAIN'] = options.bundled_win_toolchain
|
|
|
|
if options.bundled_win_toolchain_root:
|
|
|
|
os.environ['DEPOT_TOOLS_WIN_TOOLCHAIN_ROOT'] = (
|
|
|
|
options.bundled_win_toolchain_root)
|
|
|
|
if options.depot_tools:
|
|
|
|
os.environ['PATH'] = (
|
|
|
|
options.depot_tools + os.path.pathsep + os.environ['PATH'])
|
2018-04-24 13:42:29 +00:00
|
|
|
if not options.build:
|
|
|
|
GenerateBuildFiles(options)
|
|
|
|
else:
|
|
|
|
Build(options)
|