diff options
author | Brett Wilson <brettw@chromium.org> | 2014-08-28 16:35:28 -0700 |
---|---|---|
committer | Brett Wilson <brettw@chromium.org> | 2014-08-28 23:36:31 +0000 |
commit | 60a5bf4a8a5d1a2dad8e7a67f81e72756e886266 (patch) | |
tree | e9d6987dbe7e321e6aead28fa4565b2e256c5ec4 | |
parent | 9ec7198631c65b058993de4ff23c7e8c04aec9d8 (diff) | |
download | chromium_src-60a5bf4a8a5d1a2dad8e7a67f81e72756e886266.zip chromium_src-60a5bf4a8a5d1a2dad8e7a67f81e72756e886266.tar.gz chromium_src-60a5bf4a8a5d1a2dad8e7a67f81e72756e886266.tar.bz2 |
Remove built-in component and test targets from GN.
Previously "component" was a built-in function that forwarded to source_set, static_library, or shared_library depending on the value of component_mode. And test was a built-in function that forwarded to executable.
These can be expressed as templates instead. This patch removes the built-in versions and implements the templates in the master build config file.
Forwarding all of the variables for these is somewhat tedious, but I still prefer not to add a new concept for this, since it will be rarely used and less clear what is happening.
With the updated BUILDCONFIG.gn file, the build will work with both the old and new GN version (the built-in version of component and test take precedence). When the new GN binary is pushed, we can remove the references to component_mode.
BUG=
R=hclam@chromium.org
Review URL: https://codereview.chromium.org/516703005
Cr-Commit-Position: refs/heads/master@{#292500}
-rw-r--r-- | build/config/BUILDCONFIG.gn | 174 | ||||
-rw-r--r-- | tools/gn/functions.cc | 2 | ||||
-rw-r--r-- | tools/gn/functions.h | 18 | ||||
-rw-r--r-- | tools/gn/functions_target.cc | 90 | ||||
-rw-r--r-- | tools/gn/variables.cc | 20 | ||||
-rw-r--r-- | tools/gn/variables.h | 4 |
6 files changed, 149 insertions, 159 deletions
diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 42745e7..191babb 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -283,12 +283,6 @@ set_sources_assignment_filter(sources_assignment_filter) # BUILD OPTIONS # ============================================================================= -if (is_component_build) { - component_mode = "shared_library" -} else { - component_mode = "source_set" -} - # These Sanitizers all imply using the Clang compiler. On Windows they either # don't work or work differently. if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) { @@ -390,39 +384,58 @@ if (is_win) { ] } +# Executable defaults (applies to executables and tests). +_executable_configs = _native_compiler_configs + [ + "//build/config:default_libs", +] +if (is_win) { + _executable_configs += _windows_linker_configs +} else if (is_mac) { + _executable_configs += [ + "//build/config/mac:mac_dynamic_flags", + "//build/config/mac:mac_executable_flags" ] +} else if (is_linux || is_android) { + _executable_configs += [ "//build/config/gcc:executable_ldconfig" ] +} set_defaults("executable") { - configs = _native_compiler_configs + [ - "//build/config:default_libs", - ] - if (is_win) { - configs += _windows_linker_configs - } else if (is_mac) { - configs += [ - "//build/config/mac:mac_dynamic_flags", - "//build/config/mac:mac_executable_flags" ] - } else if (is_linux || is_android) { - configs += [ "//build/config/gcc:executable_ldconfig" ] - } + configs = _executable_configs +} +set_defaults("test") { + configs = _executable_configs } +# Static library defaults. set_defaults("static_library") { configs = _native_compiler_configs } +# Shared library defaults (also for components in component mode). +_shared_library_configs = _native_compiler_configs + [ + "//build/config:default_libs", +] +if (is_win) { + _shared_library_configs += _windows_linker_configs +} else if (is_mac) { + _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ] +} set_defaults("shared_library") { - configs = _native_compiler_configs + [ - "//build/config:default_libs", - ] - if (is_win) { - configs += _windows_linker_configs - } else if (is_mac) { - configs += [ "//build/config/mac:mac_dynamic_flags" ] + configs = _shared_library_configs +} +if (is_component_build) { + set_defaults("component") { + configs = _native_compiler_configs } } +# Source set defaults (also for components in non-component mode). set_defaults("source_set") { configs = _native_compiler_configs } +if (!is_component_build) { + set_defaults("component") { + configs = _native_compiler_configs + } +} # ============================================================================== # TOOLCHAIN SETUP @@ -470,3 +483,114 @@ if (is_win) { host_toolchain = "//build/toolchain/mac:host_clang" set_default_toolchain("//build/toolchain/mac:clang") } + +# ============================================================================== +# COMPONENT SETUP +# ============================================================================== + +# TODO(brettw) erase this once the built-in "component" function is removed. +if (is_component_build) { + component_mode = "shared_library" +} else { + component_mode = "source_set" +} + +template("component") { + if (is_component_build) { + shared_library(target_name) { + # Configs will always be defined since we set_defaults for a component + # above. We want to use those rather than whatever came with the nested + # shared/static library inside the component. + configs = [] # Prevent list overwriting warning. + configs = invoker.configs + + if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs } + if (defined(invoker.cflags)) { cflags = invoker.cflags } + if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c } + if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc } + if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc } + if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc } + if (defined(invoker.data)) { data = invoker.data } + if (defined(invoker.datadeps)) { datadeps = invoker.datadeps } + if (defined(invoker.defines)) { defines = invoker.defines } + if (defined(invoker.deps)) { deps = invoker.deps } + if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs } + if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from } + if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs } + if (defined(invoker.ldflags)) { ldflags = invoker.ldflags } + if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs } + if (defined(invoker.libs)) { libs = invoker.libs } + if (defined(invoker.output_extension)) { output_extension = invoker.output_extension } + if (defined(invoker.output_name)) { output_name = invoker.output_name } + if (defined(invoker.public)) { public = invoker.public } + if (defined(invoker.sources)) { sources = invoker.sources } + if (defined(invoker.visibility)) { visibility = invoker.visibility } + } + } else { + source_set(target_name) { + # See above. + configs = [] # Prevent list overwriting warning. + configs = invoker.configs + + if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs } + if (defined(invoker.cflags)) { cflags = invoker.cflags } + if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c } + if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc } + if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc } + if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc } + if (defined(invoker.data)) { data = invoker.data } + if (defined(invoker.datadeps)) { datadeps = invoker.datadeps } + if (defined(invoker.defines)) { defines = invoker.defines } + if (defined(invoker.deps)) { deps = invoker.deps } + if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs } + if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from } + if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs } + if (defined(invoker.ldflags)) { ldflags = invoker.ldflags } + if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs } + if (defined(invoker.libs)) { libs = invoker.libs } + if (defined(invoker.output_extension)) { output_extension = invoker.output_extension } + if (defined(invoker.output_name)) { output_name = invoker.output_name } + if (defined(invoker.public)) { public = invoker.public } + if (defined(invoker.sources)) { sources = invoker.sources } + if (defined(invoker.visibility)) { visibility = invoker.visibility } + } + } +} + +# ============================================================================== +# TEST SETUP +# ============================================================================== + +# Define a test as an executable. In the future, we'll set "test only" flags +# on this (when such flags exist) and do something different for Android. +template("test") { + executable(target_name) { + # Configs will always be defined since we set_defaults for a component + # above. We want to use those rather than whatever came with the nested + # shared/static library inside the component. + configs = [] # Prevent list overwriting warning. + configs = invoker.configs + + if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs } + if (defined(invoker.cflags)) { cflags = invoker.cflags } + if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c } + if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc } + if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc } + if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc } + if (defined(invoker.data)) { data = invoker.data } + if (defined(invoker.datadeps)) { datadeps = invoker.datadeps } + if (defined(invoker.defines)) { defines = invoker.defines } + if (defined(invoker.deps)) { deps = invoker.deps } + if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs } + if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from } + if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs } + if (defined(invoker.ldflags)) { ldflags = invoker.ldflags } + if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs } + if (defined(invoker.libs)) { libs = invoker.libs } + if (defined(invoker.output_extension)) { output_extension = invoker.output_extension } + if (defined(invoker.output_name)) { output_name = invoker.output_name } + if (defined(invoker.public)) { public = invoker.public } + if (defined(invoker.sources)) { sources = invoker.sources } + if (defined(invoker.visibility)) { visibility = invoker.visibility } + } +} diff --git a/tools/gn/functions.cc b/tools/gn/functions.cc index 35e42d4..96b985d 100644 --- a/tools/gn/functions.cc +++ b/tools/gn/functions.cc @@ -643,14 +643,12 @@ struct FunctionInfoInitializer { INSERT_FUNCTION(Action, true) INSERT_FUNCTION(ActionForEach, true) - INSERT_FUNCTION(Component, true) INSERT_FUNCTION(Copy, true) INSERT_FUNCTION(Executable, true) INSERT_FUNCTION(Group, true) INSERT_FUNCTION(SharedLibrary, true) INSERT_FUNCTION(SourceSet, true) INSERT_FUNCTION(StaticLibrary, true) - INSERT_FUNCTION(Test, true) INSERT_FUNCTION(Assert, false) INSERT_FUNCTION(Config, false) diff --git a/tools/gn/functions.h b/tools/gn/functions.h index 45bb4de..ef93a32 100644 --- a/tools/gn/functions.h +++ b/tools/gn/functions.h @@ -80,15 +80,6 @@ Value RunAssert(Scope* scope, const std::vector<Value>& args, Err* err); -extern const char kComponent[]; -extern const char kComponent_HelpShort[]; -extern const char kComponent_Help[]; -Value RunComponent(Scope* scope, - const FunctionCallNode* function, - const std::vector<Value>& args, - BlockNode* block, - Err* err); - extern const char kConfig[]; extern const char kConfig_HelpShort[]; extern const char kConfig_Help[]; @@ -289,15 +280,6 @@ Value RunTemplate(Scope* scope, BlockNode* block, Err* err); -extern const char kTest[]; -extern const char kTest_HelpShort[]; -extern const char kTest_Help[]; -Value RunTest(Scope* scope, - const FunctionCallNode* function, - const std::vector<Value>& args, - BlockNode* block, - Err* err); - extern const char kTool[]; extern const char kTool_HelpShort[]; extern const char kTool_Help[]; diff --git a/tools/gn/functions_target.cc b/tools/gn/functions_target.cc index 8aea0128..1d5ad13 100644 --- a/tools/gn/functions_target.cc +++ b/tools/gn/functions_target.cc @@ -231,72 +231,6 @@ Value RunActionForEach(Scope* scope, block, err); } -// component ------------------------------------------------------------------- - -const char kComponent[] = "component"; -const char kComponent_HelpShort[] = - "component: Declare a component target."; -const char kComponent_Help[] = - "component: Declare a component target.\n" - "\n" - " A component is a shared library, static library, or source set\n" - " depending on the component mode. This allows a project to separate\n" - " out a build into shared libraries for faster development (link time is\n" - " reduced) but to switch to a static build for releases (for better\n" - " performance).\n" - "\n" - " To use this function you must set the value of the \"component_mode\"\n" - " variable to one of the following strings:\n" - " - \"shared_library\"\n" - " - \"static_library\"\n" - " - \"source_set\"\n" - " It is an error to call \"component\" without defining the mode\n" - " (typically this is done in the master build configuration file).\n"; - -Value RunComponent(Scope* scope, - const FunctionCallNode* function, - const std::vector<Value>& args, - BlockNode* block, - Err* err) { - // A component is either a shared or static library, depending on the value - // of |component_mode|. - const Value* component_mode_value = - scope->GetValue(variables::kComponentMode); - - static const char helptext[] = - "You're declaring a component here but have not defined " - "\"component_mode\" to\neither \"shared_library\" or \"static_library\"."; - if (!component_mode_value) { - *err = Err(function->function(), "No component mode set.", helptext); - return Value(); - } - if (component_mode_value->type() != Value::STRING || - (component_mode_value->string_value() != functions::kSharedLibrary && - component_mode_value->string_value() != functions::kStaticLibrary && - component_mode_value->string_value() != functions::kSourceSet)) { - *err = Err(function->function(), "Invalid component mode set.", helptext); - return Value(); - } - const std::string& component_mode = component_mode_value->string_value(); - - if (!EnsureNotProcessingImport(function, scope, err)) - return Value(); - Scope block_scope(scope); - if (!FillTargetBlockScope(scope, function, component_mode.c_str(), block, - args, &block_scope, err)) - return Value(); - - block->ExecuteBlockInScope(&block_scope, err); - if (err->has_error()) - return Value(); - - TargetGenerator::GenerateTarget(&block_scope, function, args, - component_mode, err); - - block_scope.CheckForUnusedVars(err); - return Value(); -} - // copy ------------------------------------------------------------------------ const char kCopy[] = "copy"; @@ -522,28 +456,4 @@ Value RunStaticLibrary(Scope* scope, block, err); } -// test ------------------------------------------------------------------------ - -const char kTest[] = "test"; -const char kTest_HelpShort[] = - "test: Declares a test target."; -const char kTest_Help[] = - "test: Declares a test target.\n" - "\n" - " This is like an executable target, but is named differently to make\n" - " the purpose of the target more obvious. It's possible in the future\n" - " we can do some enhancements like \"list all of the tests in a given\n" - " directory\".\n" - "\n" - " See \"gn help executable\" for usage.\n"; - -Value RunTest(Scope* scope, - const FunctionCallNode* function, - const std::vector<Value>& args, - BlockNode* block, - Err* err) { - return ExecuteGenericTarget(functions::kExecutable, scope, function, args, - block, err); -} - } // namespace functions diff --git a/tools/gn/variables.cc b/tools/gn/variables.cc index 5c67038..ccc5a00 100644 --- a/tools/gn/variables.cc +++ b/tools/gn/variables.cc @@ -8,25 +8,6 @@ namespace variables { // Built-in variables ---------------------------------------------------------- -const char kComponentMode[] = "component_mode"; -const char kComponentMode_HelpShort[] = - "component_mode: [string] Specifies the meaning of the component() call."; -const char kComponentMode_Help[] = - "component_mode: Specifies the meaning of the component() call.\n" - "\n" - " This value is looked up whenever a \"component\" target type is\n" - " encountered. The value controls whether the given target is a shared\n" - " or a static library.\n" - "\n" - " The initial value will be empty, which will cause a call to\n" - " component() to throw an error. Typically this value will be set in the\n" - " build config script.\n" - "\n" - "Possible values:\n" - " - \"shared_library\"\n" - " - \"source_set\"\n" - " - \"static_library\"\n"; - const char kCpuArch[] = "cpu_arch"; const char kCpuArch_HelpShort[] = "cpu_arch: [string] Current processor architecture."; @@ -845,7 +826,6 @@ const VariableInfoMap& GetBuiltinVariables() { INSERT_VARIABLE(BuildCpuArch) INSERT_VARIABLE(BuildOs) INSERT_VARIABLE(CpuArch) - INSERT_VARIABLE(ComponentMode) INSERT_VARIABLE(CurrentToolchain) INSERT_VARIABLE(DefaultToolchain) INSERT_VARIABLE(Os) diff --git a/tools/gn/variables.h b/tools/gn/variables.h index e2fd254..3a63c8a 100644 --- a/tools/gn/variables.h +++ b/tools/gn/variables.h @@ -21,10 +21,6 @@ extern const char kBuildOs[]; extern const char kBuildOs_HelpShort[]; extern const char kBuildOs_Help[]; -extern const char kComponentMode[]; -extern const char kComponentMode_HelpShort[]; -extern const char kComponentMode_Help[]; - extern const char kCpuArch[]; extern const char kCpuArch_HelpShort[]; extern const char kCpuArch_Help[]; |