diff options
author | rockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-26 09:56:09 +0000 |
---|---|---|
committer | rockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-26 09:56:09 +0000 |
commit | 30c409f3564ecf2900f63d3fed28c386f039fe6a (patch) | |
tree | c123764c29b1ead4c77d2cc136b90a0104213aa3 | |
parent | e03dab6cdce4af876d1562944c29bc193832ad8c (diff) | |
download | chromium_src-30c409f3564ecf2900f63d3fed28c386f039fe6a.zip chromium_src-30c409f3564ecf2900f63d3fed28c386f039fe6a.tar.gz chromium_src-30c409f3564ecf2900f63d3fed28c386f039fe6a.tar.bz2 |
Add GN template for generated extensions API targets.
This adds a new GN template for generating static extensions API
library bundles from sets of schemas. It also adds invocations of
the template for core extensions and apps API targets.
BUG=None
TBR=kalman
Review URL: https://codereview.chromium.org/256453002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266341 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | BUILD.gn | 2 | ||||
-rw-r--r-- | apps/common/api/BUILD.gn | 13 | ||||
-rw-r--r-- | extensions/common/api/BUILD.gn | 21 | ||||
-rw-r--r-- | extensions/generated_extensions_api.gni | 144 | ||||
-rw-r--r-- | tools/json_schema_compiler/BUILD.gn | 13 |
5 files changed, 193 insertions, 0 deletions
@@ -17,6 +17,7 @@ group("root") { # This is a temporary test of the not-yet-complete NaCl cross-compilation. #"//base(//build/toolchain/nacl:x86_newlib)", + "//apps/common/api:apps_api", #"//chrome", "//components/language_usage_metrics", "//components/navigation_metrics", @@ -29,6 +30,7 @@ group("root") { "//components/url_matcher", "//crypto", "//device/usb", + #"//extensions/common/api:extensions_api", "//ipc", "//net", #"//sdch", diff --git a/apps/common/api/BUILD.gn b/apps/common/api/BUILD.gn new file mode 100644 index 0000000..5aa6dadc --- /dev/null +++ b/apps/common/api/BUILD.gn @@ -0,0 +1,13 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//extensions/generated_extensions_api.gni") + +generated_extensions_api("apps_api") { + sources = [ + "app_runtime.idl", + ] + root_namespace = "extensions::apps_api" + impl_dir = "//apps/browser/api" +} diff --git a/extensions/common/api/BUILD.gn b/extensions/common/api/BUILD.gn new file mode 100644 index 0000000..8ece118 --- /dev/null +++ b/extensions/common/api/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//extensions/generated_extensions_api.gni") + +generated_extensions_api("extensions_api") { + sources = [ + "dns.idl", + "extensions_manifest_types.json", + "socket.idl", + "sockets_tcp.idl", + "sockets_tcp_server.idl", + "sockets_udp.idl", + "storage.json", + "test.json", + ] + root_namespace = "extensions::core_api" + impl_dir = "//extensions/browser/api" + deps = [ "//skia" ] +} diff --git a/extensions/generated_extensions_api.gni b/extensions/generated_extensions_api.gni new file mode 100644 index 0000000..d4da603 --- /dev/null +++ b/extensions/generated_extensions_api.gni @@ -0,0 +1,144 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Defines a static library corresponding to the output of schema compiler tools +# over a set of extensions API schemas (IDL or JSON format.) The library target +# has implicit hard dependencies on all schema files listed by the invoker and +# is itself a hard dependency. +# +# Invocations of this template may use the following variables: +# +# sources [required] A list of schema files to be compiled. +# +# root_namespace [required] The namespace in which generated API code is to be +# wrapped. C++ namespace syntax is accepted for nested namespace +# (e.g. "foo::bar::api"). +# +# impl_dir [required] The path containing C++ implementations of API functions. +# This path is used as the root path when looking for +# {schema}/{schema}_api.h headers during the API bundle generation phase. +# Such headers, if found, are automatically included by the generated code. +# +# uncompiled_sources [optional] A list of schema files which should not be +# compiled, but which should still be processed for API bundle generation. +# +# deps [optional] If any deps are specified they will be inherited by the +# static library target. +# +# The static libarary target also inherits the visibility and output_name +# of its invoker. + +template("generated_extensions_api") { + assert(defined(invoker.sources), + "\"sources\" must be defined for the $target_name template.") + assert(defined(invoker.root_namespace), + "\"root_namespace\" must be defined for the $target_name template.") + assert(defined(invoker.impl_dir), + "\"impl_dir\" must be defined for the $target_name template.") + + # Keep a copy of the target_name here since it will be trampled + # in nested targets. + target_visibility = ":$target_name" + + generated_config_name = target_name + "_generated_config" + config(generated_config_name) { + include_dirs = [ target_gen_dir ] + visibility = target_visibility + } + + schemas = invoker.sources + root_namespace = invoker.root_namespace + impl_dir = invoker.impl_dir + uncompiled_schemas = [] + if (defined(invoker.uncompiled_sources)) { + uncompiled_schemas = invoker.uncompiled_sources + } + + compiler_root = "//tools/json_schema_compiler" + compiler_script = "$compiler_root/compiler.py" + compiler_sources = [ + "$compiler_root/cc_generator.py", + "$compiler_root/code.py", + "$compiler_root/compiler.py", + "$compiler_root/cpp_generator.py", + "$compiler_root/cpp_type_generator.py", + "$compiler_root/cpp_util.py", + "$compiler_root/h_generator.py", + "$compiler_root/idl_schema.py", + "$compiler_root/model.py", + "$compiler_root/util_cc_helper.py", + ] + + # This list mirrors the outputs that will be generated by the following + # action_foreach. It's used by the static_library target. + compiled_schema_outputs = process_file_template( + schemas, + [ "$target_gen_dir/{{source_name_part}}.cc", + "$target_gen_dir/{{source_name_part}}.h", + ]) + + schema_generator_name = target_name + "_schema_generator" + action_foreach(schema_generator_name) { + script = compiler_script + hard_dep = true + source_prereqs = compiler_sources + sources = schemas + outputs = [ + "$target_gen_dir/{{source_name_part}}.cc", + "$target_gen_dir/{{source_name_part}}.h", + ] + args = [ + "{{source}}", + "--root=" + rebase_path("//", root_build_dir), + "--destdir=" + rebase_path(root_gen_dir, root_build_dir), + "--namespace=$root_namespace", + "--generator=cpp" ] + visibility = target_visibility + } + + bundle_generator_name = target_name + "_bundle_generator" + bundle_outputs = [ + "$target_gen_dir/generated_api.cc", + "$target_gen_dir/generated_api.h", + "$target_gen_dir/generated_schemas.cc", + "$target_gen_dir/generated_schemas.h", + ] + action(bundle_generator_name) { + script = compiler_script + hard_dep = true + source_prereqs = compiler_sources + schemas + uncompiled_schemas + outputs = bundle_outputs + args = [ + "--root=" + rebase_path("//", root_build_dir), + "--destdir=" + rebase_path(root_gen_dir, root_build_dir), + "--namespace=$root_namespace", + "--generator=cpp-bundle", + "--impl-dir=" + rebase_path(impl_dir, "//"), + ] + + rebase_path(schemas, root_build_dir) + + rebase_path(uncompiled_schemas, root_build_dir) + } + + source_set(target_name) { + hard_dep = true + sources = compiled_schema_outputs + bundle_outputs + deps = [ + ":$schema_generator_name", + ":$bundle_generator_name", + "//tools/json_schema_compiler:generated_api_util", + ] + + if (defined(invoker.deps)) { + deps += invoker.deps + } + direct_dependent_configs = [ ":$generated_config_name" ] + + if (defined(invoker.visibility)) { + visibility = invoker.visibility + } + if (defined(invoker.output_name)) { + output_name = invoker.output_name + } + } +} diff --git a/tools/json_schema_compiler/BUILD.gn b/tools/json_schema_compiler/BUILD.gn new file mode 100644 index 0000000..2d7c183 --- /dev/null +++ b/tools/json_schema_compiler/BUILD.gn @@ -0,0 +1,13 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Utility sources against which generated API modules should be linked. +source_set("generated_api_util") { + sources = [ + "util.cc", + "util.h" + ] + deps = [ "//base" ] +} + |