blob: 68a9fdd57ab4bd116ff39c7255c994c64250e213 [file] [log] [blame]
[email protected]30c409f2014-04-26 09:56:091# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# Defines a static library corresponding to the output of schema compiler tools
6# over a set of extensions API schemas (IDL or JSON format.) The library target
7# has implicit hard dependencies on all schema files listed by the invoker and
8# is itself a hard dependency.
9#
10# Invocations of this template may use the following variables:
11#
12# sources [required] A list of schema files to be compiled.
13#
[email protected]fca567b2014-07-02 17:37:3414# root_namespace [required]
[email protected]8d368d62014-08-05 08:02:0615# A Python string substituion pattern used to generate the C++
16# namespace for each API. Use %(namespace)s to replace with the API
17# namespace, like "toplevel::%(namespace)s_api".
[email protected]30c409f2014-04-26 09:56:0918#
lfg8a1bee32014-08-29 03:56:2819# schema_include_rules [optional]
20# A list of paths to include when searching for referenced objects,
21# with the namespace separated by a :.
22# Example:
23# [ '/foo/bar:Foo::Bar::%(namespace)s' ]
24#
yoz774dcda2d2014-08-27 03:32:5825# schemas [optional, default = false]
26# Boolean indicating if the schema files should be generated.
yoz3b70ef142014-08-27 00:51:2327#
yoz774dcda2d2014-08-27 03:32:5828# bundle [optional, default = false]
29# Boolean indicating if the schema bundle files should be generated.
30#
31# bundle_registration [optional, default = false]
32# Boolean indicating if the API registration bundle files should be generated.
33#
34# impl_dir [required if bundle_registration = true, otherwise unused]
[email protected]fca567b2014-07-02 17:37:3435# The path containing C++ implementations of API functions. This path is
36# used as the root path when looking for {schema}/{schema}_api.h headers
yoz774dcda2d2014-08-27 03:32:5837# when generating API registration bundles. Such headers, if found, are
[email protected]fca567b2014-07-02 17:37:3438# automatically included by the generated code.
[email protected]30c409f2014-04-26 09:56:0939#
yoz774dcda2d2014-08-27 03:32:5840# uncompiled_sources [optional, only used when bundle = true or
41# bundle_registration = true]
[email protected]fca567b2014-07-02 17:37:3442# A list of schema files which should not be compiled, but which should still
43# be processed for API bundle generation.
44#
45# deps [optional]
46# If any deps are specified they will be inherited by the static library
47# target.
[email protected]30c409f2014-04-26 09:56:0948#
yoz774dcda2d2014-08-27 03:32:5849# The static library target also inherits the visibility and output_name
[email protected]30c409f2014-04-26 09:56:0950# of its invoker.
51
James Robinson145636c42014-09-30 22:26:5252template("json_schema_api") {
[email protected]30c409f2014-04-26 09:56:0953 assert(defined(invoker.sources),
54 "\"sources\" must be defined for the $target_name template.")
55 assert(defined(invoker.root_namespace),
56 "\"root_namespace\" must be defined for the $target_name template.")
[email protected]fca567b2014-07-02 17:37:3457
yoz774dcda2d2014-08-27 03:32:5858 schemas = defined(invoker.schemas) && invoker.schemas
[email protected]fca567b2014-07-02 17:37:3459 bundle = defined(invoker.bundle) && invoker.bundle
scottmgb1992542014-12-02 00:25:2060 bundle_registration =
61 defined(invoker.bundle_registration) && invoker.bundle_registration
[email protected]30c409f2014-04-26 09:56:0962
lfg8a1bee32014-08-29 03:56:2863 schema_include_rules = ""
64 if (defined(invoker.schema_include_rules)) {
65 schema_include_rules = invoker.schema_include_rules
66 }
67
[email protected]30c409f2014-04-26 09:56:0968 # Keep a copy of the target_name here since it will be trampled
69 # in nested targets.
brettw9af42622014-09-06 21:21:0270 target_visibility = [ ":$target_name" ]
[email protected]30c409f2014-04-26 09:56:0971
72 generated_config_name = target_name + "_generated_config"
73 config(generated_config_name) {
vchigrin227791802015-01-13 18:34:4674 include_dirs = [ root_gen_dir ]
[email protected]30c409f2014-04-26 09:56:0975 visibility = target_visibility
76 }
77
yoz774dcda2d2014-08-27 03:32:5878 sources = invoker.sources
[email protected]30c409f2014-04-26 09:56:0979 root_namespace = invoker.root_namespace
[email protected]30c409f2014-04-26 09:56:0980
81 compiler_root = "//tools/json_schema_compiler"
82 compiler_script = "$compiler_root/compiler.py"
83 compiler_sources = [
84 "$compiler_root/cc_generator.py",
85 "$compiler_root/code.py",
86 "$compiler_root/compiler.py",
87 "$compiler_root/cpp_generator.py",
88 "$compiler_root/cpp_type_generator.py",
89 "$compiler_root/cpp_util.py",
90 "$compiler_root/h_generator.py",
91 "$compiler_root/idl_schema.py",
92 "$compiler_root/model.py",
93 "$compiler_root/util_cc_helper.py",
94 ]
95
yoz774dcda2d2014-08-27 03:32:5896 if (schemas) {
97 schema_generator_name = target_name + "_schema_generator"
98 action_foreach(schema_generator_name) {
99 script = compiler_script
100 inputs = compiler_sources
101 outputs = [
102 "$target_gen_dir/{{source_name_part}}.cc",
103 "$target_gen_dir/{{source_name_part}}.h",
104 ]
105 args = [
106 "{{source}}",
107 "--root=" + rebase_path("//", root_build_dir),
108 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
109 "--namespace=$root_namespace",
lfg8a1bee32014-08-29 03:56:28110 "--generator=cpp",
scottmgb1992542014-12-02 00:25:20111 "--include-rules=$schema_include_rules",
112 ]
brettwa78fded2014-09-07 00:27:41113
114 if (defined(invoker.visibility)) {
115 # If visibility is restricted, add our own target to it.
brettwa68ea2b2015-02-01 02:54:07116 visibility = invoker.visibility + target_visibility
brettwa78fded2014-09-07 00:27:41117 }
yoz774dcda2d2014-08-27 03:32:58118 }
[email protected]30c409f2014-04-26 09:56:09119 }
120
[email protected]fca567b2014-07-02 17:37:34121 if (bundle) {
yoz774dcda2d2014-08-27 03:32:58122 uncompiled_sources = []
[email protected]fca567b2014-07-02 17:37:34123 if (defined(invoker.uncompiled_sources)) {
scottmgb1992542014-12-02 00:25:20124 uncompiled_sources = invoker.uncompiled_sources
[email protected]fca567b2014-07-02 17:37:34125 }
126
yoz774dcda2d2014-08-27 03:32:58127 bundle_generator_schema_name = target_name + "_bundle_generator_schema"
128 action(bundle_generator_schema_name) {
[email protected]fca567b2014-07-02 17:37:34129 script = compiler_script
yoz774dcda2d2014-08-27 03:32:58130 inputs = compiler_sources + sources + uncompiled_sources
[email protected]fca567b2014-07-02 17:37:34131 outputs = [
[email protected]fca567b2014-07-02 17:37:34132 "$target_gen_dir/generated_schemas.cc",
133 "$target_gen_dir/generated_schemas.h",
134 ]
135 args = [
scottmgb1992542014-12-02 00:25:20136 "--root=" + rebase_path("//", root_build_dir),
137 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
138 "--namespace=$root_namespace",
139 "--generator=cpp-bundle-schema",
140 "--include-rules=$schema_include_rules",
141 ] + rebase_path(sources, root_build_dir) +
142 rebase_path(uncompiled_sources, root_build_dir)
yoz774dcda2d2014-08-27 03:32:58143 }
144 }
145
146 if (bundle_registration) {
147 uncompiled_sources = []
148 if (defined(invoker.uncompiled_sources)) {
scottmgb1992542014-12-02 00:25:20149 uncompiled_sources = invoker.uncompiled_sources
yoz774dcda2d2014-08-27 03:32:58150 }
151
152 assert(defined(invoker.impl_dir),
153 "\"impl_dir\" must be defined for the $target_name template.")
154 impl_dir = invoker.impl_dir
155
scottmgb1992542014-12-02 00:25:20156 bundle_generator_registration_name =
157 target_name + "_bundle_generator_registration"
yoz774dcda2d2014-08-27 03:32:58158 action(bundle_generator_registration_name) {
159 script = compiler_script
160 inputs = compiler_sources + sources + uncompiled_sources
161 outputs = [
162 "$root_gen_dir/$impl_dir/generated_api_registration.cc",
163 "$root_gen_dir/$impl_dir/generated_api_registration.h",
164 ]
165 args = [
scottmgb1992542014-12-02 00:25:20166 "--root=" + rebase_path("//", root_build_dir),
167 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
168 "--namespace=$root_namespace",
169 "--generator=cpp-bundle-registration",
170 "--impl-dir=" + rebase_path(impl_dir, "//"),
171 "--include-rules=$schema_include_rules",
172 ] + rebase_path(sources, root_build_dir) +
173 rebase_path(uncompiled_sources, root_build_dir)
[email protected]fca567b2014-07-02 17:37:34174 }
[email protected]30c409f2014-04-26 09:56:09175 }
176
177 source_set(target_name) {
yoz774dcda2d2014-08-27 03:32:58178 sources = []
179 deps = []
Brett Wilson0380637c2014-09-19 21:24:40180 public_deps = []
181
yoz774dcda2d2014-08-27 03:32:58182 if (schemas) {
183 sources += get_target_outputs(":$schema_generator_name")
Brett Wilson0380637c2014-09-19 21:24:40184 public_deps += [ ":$schema_generator_name" ]
185 deps += [ "//tools/json_schema_compiler:generated_api_util" ]
dpranke8ec93a3a2015-02-20 23:36:08186 configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
yoz774dcda2d2014-08-27 03:32:58187 }
[email protected]30c409f2014-04-26 09:56:09188
[email protected]fca567b2014-07-02 17:37:34189 if (bundle) {
yoz774dcda2d2014-08-27 03:32:58190 sources += get_target_outputs(":$bundle_generator_schema_name")
191 deps += [ ":$bundle_generator_schema_name" ]
192 }
193
194 if (bundle_registration) {
195 sources += get_target_outputs(":$bundle_generator_registration_name")
196 deps += [ ":$bundle_generator_registration_name" ]
[email protected]fca567b2014-07-02 17:37:34197 }
198
[email protected]30c409f2014-04-26 09:56:09199 if (defined(invoker.deps)) {
200 deps += invoker.deps
201 }
Brett Wilsone53895272014-09-23 23:41:46202 public_configs = [ ":$generated_config_name" ]
[email protected]30c409f2014-04-26 09:56:09203
204 if (defined(invoker.visibility)) {
205 visibility = invoker.visibility
206 }
207 if (defined(invoker.output_name)) {
208 output_name = invoker.output_name
209 }
210 }
211}