v8/tools/node/build_gn.py
Yang Guo 952cfd58fd [node] scripts to fetch deps and build monolithic .a for node.
Once this CL lands and is included in Node.js, we can
- run `tools/node/fetch_deps.py <v8_path>` to fetch necessary deps.
- run `tools/node/build_gn.py <build mode> <v8_path> <out_dir>` to build.
- use new v8_monolith target in v8.gyp to call build_gn.py.

R=machenbach@chromium.org

Bug: v8:6105
Change-Id: I482bfddb40f77df62394a913335bd43627cc0c43
Reviewed-on: https://chromium-review.googlesource.com/792944
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50152}
2017-12-18 09:57:28 +00:00

83 lines
2.5 KiB
Python
Executable File

#!/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
"""
import os
import subprocess
import sys
import node_common
GN_ARGS = [
"v8_monolithic = true",
"is_component_build = false",
"v8_use_external_startup_data = false",
"use_custom_libcxx = false",
"use_sysroot = false",
]
BUILD_SUBDIR = "gn"
# TODO: make this cross-platform.
GN_SUBDIR = ["buildtools", "linux64", "gn"]
def Build(v8_path, build_path, depot_tools, is_debug, build_flags):
print "Setting GN args."
lines = []
lines.extend(GN_ARGS)
for flag in build_flags:
flag = flag.replace("=1", "=true")
flag = flag.replace("=0", "=false")
flag = flag.replace("target_cpu=ia32", "target_cpu=\"x86\"")
lines.append(flag)
lines.append("is_debug = %s" % ("true" if is_debug else "false"))
with open(os.path.join(build_path, "args.gn"), "w") as args_file:
args_file.write("\n".join(lines))
gn = os.path.join(v8_path, *GN_SUBDIR)
subprocess.check_call([gn, "gen", "-C", build_path], cwd=v8_path)
ninja = os.path.join(depot_tools, "ninja")
print "Building."
subprocess.check_call([ninja, "-v", "-C", build_path, "v8_monolith"],
cwd=v8_path)
def Main(v8_path, build_path, is_debug, build_flags):
# Verify paths.
v8_path = os.path.abspath(v8_path)
assert os.path.isdir(v8_path)
build_path = os.path.abspath(build_path)
build_path = os.path.join(build_path, BUILD_SUBDIR)
if not os.path.isdir(build_path):
os.makedirs(build_path)
# Check that we have depot tools.
depot_tools = node_common.EnsureDepotTools(v8_path, False)
# Build with GN.
Build(v8_path, build_path, depot_tools, is_debug, build_flags)
if __name__ == "__main__":
# TODO: use argparse to parse arguments.
build_mode = sys.argv[1]
v8_path = sys.argv[2]
build_path = sys.argv[3]
assert build_mode == "Debug" or build_mode == "Release"
is_debug = build_mode == "Debug"
# TODO: introduce "--" flag for pass-through flags.
build_flags = sys.argv[4:]
Main(v8_path, build_path, is_debug, build_flags)