1 # 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.
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.
10 # Invocations of this template may use the following variables:
12 # sources [required] A list of schema files to be compiled.
14 # root_namespace [required]
15 # 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".
19 # schema_include_rules [optional]
20 # A list of paths to include when searching for referenced objects,
21 # with the namespace separated by a :.
23 # [ '/foo/bar:Foo::Bar::%(namespace)s' ]
25 # schemas [optional, default = false]
26 # Boolean indicating if the schema files should be generated.
28 # bundle [optional, default = false]
29 # Boolean indicating if the schema bundle files should be generated.
31 # bundle_registration [optional, default = false]
32 # Boolean indicating if the API registration bundle files should be generated.
34 # impl_dir [required if bundle_registration = true, otherwise unused]
35 # 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
37 # when generating API registration bundles. Such headers, if found, are
38 # automatically included by the generated code.
40 # uncompiled_sources [optional, only used when bundle = true or
41 # bundle_registration = true]
42 # A list of schema files which should not be compiled, but which should still
43 # be processed for API bundle generation.
46 # If any deps are specified they will be inherited by the static library
49 # The static library target also inherits the visibility and output_name
52 template("generated_extensions_api") {
53 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.")
58 schemas = defined(invoker.schemas) && invoker.schemas
59 bundle = defined(invoker.bundle) && invoker.bundle
60 bundle_registration = defined(invoker.bundle_registration) &&
61 invoker.bundle_registration
63 schema_include_rules = ""
64 if (defined(invoker.schema_include_rules)) {
65 schema_include_rules = invoker.schema_include_rules
68 # Keep a copy of the target_name here since it will be trampled
70 target_visibility = ":$target_name"
72 generated_config_name = target_name + "_generated_config"
73 config(generated_config_name) {
74 include_dirs = [ target_gen_dir ]
75 visibility = target_visibility
78 sources = invoker.sources
79 root_namespace = invoker.root_namespace
81 compiler_root = "//tools/json_schema_compiler"
82 compiler_script = "$compiler_root/compiler.py"
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",
97 schema_generator_name = target_name + "_schema_generator"
98 action_foreach(schema_generator_name) {
99 script = compiler_script
100 inputs = compiler_sources
102 "$target_gen_dir/{{source_name_part}}.cc",
103 "$target_gen_dir/{{source_name_part}}.h",
107 "--root=" + rebase_path("//", root_build_dir),
108 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
109 "--namespace=$root_namespace",
111 "--include-rules=$schema_include_rules" ]
112 visibility = target_visibility
117 uncompiled_sources = []
118 if (defined(invoker.uncompiled_sources)) {
119 uncompiled_sources = invoker.uncompiled_sources
122 bundle_generator_schema_name = target_name + "_bundle_generator_schema"
123 action(bundle_generator_schema_name) {
124 script = compiler_script
125 inputs = compiler_sources + sources + uncompiled_sources
127 "$target_gen_dir/generated_schemas.cc",
128 "$target_gen_dir/generated_schemas.h",
131 "--root=" + rebase_path("//", root_build_dir),
132 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
133 "--namespace=$root_namespace",
134 "--generator=cpp-bundle-schema",
135 "--include-rules=$schema_include_rules" ]
136 + rebase_path(sources, root_build_dir)
137 + rebase_path(uncompiled_sources, root_build_dir)
141 if (bundle_registration) {
142 uncompiled_sources = []
143 if (defined(invoker.uncompiled_sources)) {
144 uncompiled_sources = invoker.uncompiled_sources
147 assert(defined(invoker.impl_dir),
148 "\"impl_dir\" must be defined for the $target_name template.")
149 impl_dir = invoker.impl_dir
151 bundle_generator_registration_name = target_name +
152 "_bundle_generator_registration"
153 action(bundle_generator_registration_name) {
154 script = compiler_script
155 inputs = compiler_sources + sources + uncompiled_sources
157 "$root_gen_dir/$impl_dir/generated_api_registration.cc",
158 "$root_gen_dir/$impl_dir/generated_api_registration.h",
161 "--root=" + rebase_path("//", root_build_dir),
162 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
163 "--namespace=$root_namespace",
164 "--generator=cpp-bundle-registration",
165 "--impl-dir=" + rebase_path(impl_dir, "//"),
166 "--include-rules=$schema_include_rules" ]
167 + rebase_path(sources, root_build_dir)
168 + rebase_path(uncompiled_sources, root_build_dir)
172 source_set(target_name) {
177 sources += get_target_outputs(":$schema_generator_name")
179 ":$schema_generator_name",
180 "//tools/json_schema_compiler:generated_api_util",
185 sources += get_target_outputs(":$bundle_generator_schema_name")
186 deps += [ ":$bundle_generator_schema_name" ]
189 if (bundle_registration) {
190 sources += get_target_outputs(":$bundle_generator_registration_name")
191 deps += [ ":$bundle_generator_registration_name" ]
194 if (defined(invoker.deps)) {
197 direct_dependent_configs = [ ":$generated_config_name" ]
199 if (defined(invoker.visibility)) {
200 visibility = invoker.visibility
202 if (defined(invoker.output_name)) {
203 output_name = invoker.output_name