From c1b24990277daa996db5ce84bf1a20d3dadd3751 Mon Sep 17 00:00:00 2001 From: machenbach Date: Tue, 14 Jun 2016 03:07:22 -0700 Subject: [PATCH] [gn] Improve sharing common configuration This moves common configs used by all v8 targets into common templates. This also fixes using v8_optimized_debug correctly in executables and components. BUG=chromium:474921 NOTRY=true Review-Url: https://codereview.chromium.org/2054803003 Cr-Commit-Position: refs/heads/master@{#36956} --- BUILD.gn | 66 +++++++---------------------------------- gni/v8.gni | 56 ++++++++++++++++++++++++++++++++++ test/cctest/BUILD.gn | 8 ++--- test/unittests/BUILD.gn | 8 ++--- 4 files changed, 70 insertions(+), 68 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 40c5d8dd21..84f2d64a5f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -51,9 +51,6 @@ declare_args() { # Sets -dOBJECT_PRINT. v8_object_print = false - # Turns on compiler optimizations in V8 in Debug build. - v8_optimized_debug = true - # With post mortem support enabled, metadata is embedded into libv8 that # describes various parameters of the VM for use by debuggers. See # tools/gen-postmortem-metadata.py for details. @@ -302,33 +299,6 @@ config("toolchain") { } } -############################################################################### -# Templates -# - -template("v8_source_set") { - source_set(target_name) { - forward_variables_from(invoker, "*", [ "configs" ]) - configs += invoker.configs - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ "//build/config/compiler:no_chromium_code" ] - configs += [ - ":features", - ":toolchain", - ] - - # TODO(machenbach): This config doesn't affect executables and components. - # It should be moved to a common place. - if (is_debug && !v8_optimized_debug) { - configs -= [ "//build/config/compiler:default_optimization" ] - configs += [ "//build/config/compiler:no_optimize" ] - } else { - configs -= [ "//build/config/compiler:default_optimization" ] - configs += [ "//build/config/compiler:optimize_max" ] - } - } -} - ############################################################################### # Actions # @@ -2042,19 +2012,15 @@ v8_source_set("simple_fuzzer") { # if (current_toolchain == v8_snapshot_toolchain) { - executable("mksnapshot") { + v8_executable("mksnapshot") { visibility = [ ":*" ] # Only targets in this file can depend on this. sources = [ "src/snapshot/mksnapshot.cc", ] - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ "//build/config/compiler:no_chromium_code" ] - configs += [ + configs = [ ":internal_config", - ":features", - ":toolchain", ] deps = [ @@ -2101,7 +2067,7 @@ group("gn_all") { } if (is_component_build) { - component("v8") { + v8_component("v8") { sources = [ "src/v8dll-main.cc", ] @@ -2111,12 +2077,8 @@ if (is_component_build) { ":v8_maybe_snapshot", ] - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ "//build/config/compiler:no_chromium_code" ] - configs += [ + configs = [ ":internal_config", - ":features", - ":toolchain", ] public_configs = [ ":external_config" ] @@ -2131,21 +2093,17 @@ if (is_component_build) { } } -executable("d8") { +v8_executable("d8") { sources = [ "src/d8.cc", "src/d8.h", ] - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ "//build/config/compiler:no_chromium_code" ] - configs += [ + configs = [ # Note: don't use :internal_config here because this target will get # the :external_config applied to it by virtue of depending on :v8, and # you can't have both applied to the same target. ":internal_config_base", - ":features", - ":toolchain", ] deps = [ @@ -2181,20 +2139,16 @@ v8_isolate_run("d8") { } if (want_v8_shell) { - executable("v8_shell") { + v8_executable("v8_shell") { sources = [ "samples/shell.cc", ] - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ "//build/config/compiler:no_chromium_code" ] - configs += [ + configs = [ # Note: don't use :internal_config here because this target will get # the :external_config applied to it by virtue of depending on :v8, and # you can't have both applied to the same target. ":internal_config_base", - ":features", - ":toolchain", ] deps = [ @@ -2213,14 +2167,14 @@ if (want_v8_shell) { template("v8_fuzzer") { name = target_name forward_variables_from(invoker, "*") - executable("v8_simple_" + name) { + v8_executable("v8_simple_" + name) { deps = [ ":" + name, ":simple_fuzzer", "//build/win:default_exe_manifest", ] - configs += [ ":external_config" ] + configs = [ ":external_config" ] } } diff --git a/gni/v8.gni b/gni/v8.gni index 91c8d64287..ec943a8fd4 100644 --- a/gni/v8.gni +++ b/gni/v8.gni @@ -5,6 +5,9 @@ import("//build/config/sanitizers/sanitizers.gni") declare_args() { + # Turns on compiler optimizations in V8 in Debug build. + v8_optimized_debug = true + # Enable the snapshot feature, for fast context creation. # http://v8project.blogspot.com/2015/09/custom-startup-snapshots.html v8_use_snapshot = true @@ -28,3 +31,56 @@ if (v8_target_arch == "") { v8_target_arch = target_cpu } } + +############################################################################### +# Templates +# + +# Points to // in v8 stand-alone or to //v8/ in chromium. We need absolute +# paths for all configs in templates as they are shared in different +# subdirectories. +path_prefix = get_path_info("../", "abspath") + +# Common configs to remove or add in all v8 targets. +remove_configs = [ "//build/config/compiler:chromium_code" ] +add_configs = [ + "//build/config/compiler:no_chromium_code", + path_prefix + ":features", + path_prefix + ":toolchain", +] + +if (is_debug && !v8_optimized_debug) { + remove_configs += [ "//build/config/compiler:default_optimization" ] + add_configs += [ "//build/config/compiler:no_optimize" ] +} else { + remove_configs += [ "//build/config/compiler:default_optimization" ] + add_configs += [ "//build/config/compiler:optimize_max" ] +} + +# All templates should be kept in sync. +template("v8_source_set") { + source_set(target_name) { + forward_variables_from(invoker, "*", [ "configs" ]) + configs += invoker.configs + configs -= remove_configs + configs += add_configs + } +} + +template("v8_executable") { + executable(target_name) { + forward_variables_from(invoker, "*", [ "configs" ]) + configs += invoker.configs + configs -= remove_configs + configs += add_configs + } +} + +template("v8_component") { + component(target_name) { + forward_variables_from(invoker, "*", [ "configs" ]) + configs += invoker.configs + configs -= remove_configs + configs += add_configs + } +} diff --git a/test/cctest/BUILD.gn b/test/cctest/BUILD.gn index 24f200285f..49ba235223 100644 --- a/test/cctest/BUILD.gn +++ b/test/cctest/BUILD.gn @@ -6,7 +6,7 @@ import("../../gni/v8.gni") -executable("cctest") { +v8_executable("cctest") { testonly = true sources = [ @@ -283,13 +283,9 @@ executable("cctest") { # }, } - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ "//build/config/compiler:no_chromium_code" ] - configs += [ + configs = [ "../..:external_config", "../..:internal_config_base", - "../..:features", - "../..:toolchain", ] # TODO(machenbach): Translate from gyp. diff --git a/test/unittests/BUILD.gn b/test/unittests/BUILD.gn index 124eacb39e..83be6bfcca 100644 --- a/test/unittests/BUILD.gn +++ b/test/unittests/BUILD.gn @@ -6,7 +6,7 @@ import("../../gni/v8.gni") -executable("unittests") { +v8_executable("unittests") { testonly = true sources = [ @@ -136,13 +136,9 @@ executable("unittests") { sources += [ "compiler/s390/instruction-selector-s390-unittest.cc" ] } - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ "//build/config/compiler:no_chromium_code" ] - configs += [ + configs = [ "../..:external_config", "../..:internal_config_base", - "../..:features", - "../..:toolchain", ] # TODO(machenbach): Translate from gyp.