Commit 09027e6c authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Node integration: Split build_gn.py into two steps (generate vs build)

Makes builds go faster by not having to re-run "gn gen" unnecessarily

Also adds a bunch of flags that configure uses.
  --max-load
  --max-jobs
  --extra-gn-args
  --depot-tools
  --bundled-win-toolchain

NOTRY=true
NOTREECHECKS=true

Change-Id: I6555623468d2b11d188ca29563586f5ea9b4dda9
Reviewed-on: https://chromium-review.googlesource.com/1016582
Commit-Queue: agrieve <agrieve@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52761}
parent dd69a17a
...@@ -25,15 +25,20 @@ import sys ...@@ -25,15 +25,20 @@ import sys
import node_common import node_common
GN_ARGS = [ GN_ARGS = [
"v8_monolithic = true", "v8_monolithic=true",
"is_component_build = false", "is_component_build=false",
"v8_use_external_startup_data = false", "v8_use_external_startup_data=false",
"use_custom_libcxx = false", "use_custom_libcxx=false",
"use_sysroot = false",
] ]
BUILD_TARGET = "v8_monolith" BUILD_TARGET = "v8_monolith"
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.')
def FindGn(options): def FindGn(options):
if options.host_os == "linux": if options.host_os == "linux":
os_path = "linux64" os_path = "linux64"
...@@ -46,57 +51,85 @@ def FindGn(options): ...@@ -46,57 +51,85 @@ def FindGn(options):
return os.path.join(options.v8_path, "buildtools", os_path, "gn") return os.path.join(options.v8_path, "buildtools", os_path, "gn")
def GenerateBuildFiles(options): def GenerateBuildFiles(options):
print "Setting GN args."
gn = FindGn(options) gn = FindGn(options)
gn_args = [] gn_args = list(GN_ARGS)
gn_args.extend(GN_ARGS) target_os = FindTargetOs(options.flag)
if target_os != "win":
gn_args.append("use_sysroot=false")
for flag in options.flag: for flag in options.flag:
flag = flag.replace("=1", "=true") flag = flag.replace("=1", "=true")
flag = flag.replace("=0", "=false") flag = flag.replace("=0", "=false")
flag = flag.replace("target_cpu=ia32", "target_cpu=\"x86\"") flag = flag.replace("target_cpu=ia32", "target_cpu=\"x86\"")
gn_args.append(flag) gn_args.append(flag)
if options.mode == "Debug": if options.mode == "Debug":
gn_args.append("is_debug = true") gn_args.append("is_debug=true")
else: else:
gn_args.append("is_debug = false") gn_args.append("is_debug=false")
flattened_args = ' '.join(gn_args)
if options.extra_gn_args:
flattened_args += ' ' + options.extra_gn_args
if not os.path.isdir(options.build_path): args = [gn, "gen", options.build_path, "-q", "--args=" + flattened_args]
os.makedirs(options.build_path) subprocess.check_call(args)
with open(os.path.join(options.build_path, "args.gn"), "w") as args_file:
args_file.write("\n".join(gn_args))
subprocess.check_call([gn, "gen", "-C", options.build_path],
cwd=options.v8_path)
def Build(options): def Build(options):
print "Building."
depot_tools = node_common.EnsureDepotTools(options.v8_path, False) depot_tools = node_common.EnsureDepotTools(options.v8_path, False)
ninja = os.path.join(depot_tools, "ninja") ninja = os.path.join(depot_tools, "ninja")
subprocess.check_call([ninja, "-v", "-C", options.build_path, BUILD_TARGET], if sys.platform == 'win32':
cwd=options.v8_path) # 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)
def ParseOptions(args): def ParseOptions(args):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Build %s with GN" % BUILD_TARGET) description="Build %s with GN" % BUILD_TARGET)
parser.add_argument("--mode", help="Build mode (Release/Debug)") parser.add_argument("--mode", help="Build mode (Release/Debug)")
parser.add_argument("--v8_path", help="Path to V8") parser.add_argument("--v8_path", help="Path to V8", required=True)
parser.add_argument("--build_path", help="Path to build result") parser.add_argument("--build_path", help="Path to build result",
required=True)
parser.add_argument("--flag", help="Translate GYP flag to GN", parser.add_argument("--flag", help="Translate GYP flag to GN",
action="append") action="append")
parser.add_argument("--host_os", help="Current operating system") parser.add_argument("--host_os", help="Current operating system")
parser.add_argument("--bundled-win-toolchain",
help="Value for DEPOT_TOOLS_WIN_TOOLCHAIN")
parser.add_argument("--depot-tools", help="Absolute path to depot_tools")
parser.add_argument("--extra-gn-args", help="Additional GN args")
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")
options = parser.parse_args(args) options = parser.parse_args(args)
assert options.host_os options.build_path = os.path.abspath(options.build_path)
assert options.mode == "Debug" or options.mode == "Release"
assert options.v8_path if not options.build:
options.v8_path = os.path.abspath(options.v8_path) assert options.host_os
assert os.path.isdir(options.v8_path) assert options.mode == "Debug" or options.mode == "Release"
options.v8_path = os.path.abspath(options.v8_path)
assert os.path.isdir(options.v8_path)
assert options.build_path
options.build_path = os.path.abspath(options.build_path)
return options return options
if __name__ == "__main__": if __name__ == "__main__":
options = ParseOptions(sys.argv[1:]) options = ParseOptions(sys.argv[1:])
GenerateBuildFiles(options) # Build can result in running gn gen, so need to set environment variables
Build(options) # for build as well as generate.
os.environ['DEPOT_TOOLS_WIN_TOOLCHAIN'] = options.bundled_win_toolchain
os.environ['PATH'] += os.path.pathsep + options.depot_tools
if not options.build:
GenerateBuildFiles(options)
else:
Build(options)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment