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 # schemas [optional, default = false]
20 # Boolean indicating if the schema files should be generated.
22 # bundle [optional, default = false]
23 # Boolean indicating if the schema bundle files should be generated.
25 # bundle_registration [optional, default = false]
26 # Boolean indicating if the API registration bundle files should be generated.
28 # impl_dir [required if bundle_registration = true, otherwise unused]
29 # The path containing C++ implementations of API functions. This path is
30 # used as the root path when looking for {schema}/{schema}_api.h headers
31 # when generating API registration bundles. Such headers, if found, are
32 # automatically included by the generated code.
34 # uncompiled_sources [optional, only used when bundle = true or
35 # bundle_registration = true]
36 # A list of schema files which should not be compiled, but which should still
37 # be processed for API bundle generation.
40 # If any deps are specified they will be inherited by the static library
43 # The static library target also inherits the visibility and output_name
46 template("generated_extensions_api") {
47 assert(defined(invoker.sources),
48 "\"sources\" must be defined for the $target_name template.")
49 assert(defined(invoker.root_namespace),
50 "\"root_namespace\" must be defined for the $target_name template.")
52 schemas = defined(invoker.schemas) && invoker.schemas
53 bundle = defined(invoker.bundle) && invoker.bundle
54 bundle_registration = defined(invoker.bundle_registration) &&
55 invoker.bundle_registration
57 # Keep a copy of the target_name here since it will be trampled
59 target_visibility = ":$target_name"
61 generated_config_name = target_name + "_generated_config"
62 config(generated_config_name) {
63 include_dirs = [ target_gen_dir ]
64 visibility = target_visibility
67 sources = invoker.sources
68 root_namespace = invoker.root_namespace
70 compiler_root = "//tools/json_schema_compiler"
71 compiler_script = "$compiler_root/compiler.py"
73 "$compiler_root/cc_generator.py",
74 "$compiler_root/code.py",
75 "$compiler_root/compiler.py",
76 "$compiler_root/cpp_generator.py",
77 "$compiler_root/cpp_type_generator.py",
78 "$compiler_root/cpp_util.py",
79 "$compiler_root/h_generator.py",
80 "$compiler_root/idl_schema.py",
81 "$compiler_root/model.py",
82 "$compiler_root/util_cc_helper.py",
86 schema_generator_name = target_name + "_schema_generator"
87 action_foreach(schema_generator_name) {
88 script = compiler_script
89 inputs = compiler_sources
91 "$target_gen_dir/{{source_name_part}}.cc",
92 "$target_gen_dir/{{source_name_part}}.h",
96 "--root=" + rebase_path("//", root_build_dir),
97 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
98 "--namespace=$root_namespace",
100 visibility = target_visibility
105 uncompiled_sources = []
106 if (defined(invoker.uncompiled_sources)) {
107 uncompiled_sources = invoker.uncompiled_sources
110 bundle_generator_schema_name = target_name + "_bundle_generator_schema"
111 action(bundle_generator_schema_name) {
112 script = compiler_script
113 inputs = compiler_sources + sources + uncompiled_sources
115 "$target_gen_dir/generated_schemas.cc",
116 "$target_gen_dir/generated_schemas.h",
119 "--root=" + rebase_path("//", root_build_dir),
120 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
121 "--namespace=$root_namespace",
122 "--generator=cpp-bundle-schema",
124 rebase_path(sources, root_build_dir) +
125 rebase_path(uncompiled_sources, root_build_dir)
129 if (bundle_registration) {
130 uncompiled_sources = []
131 if (defined(invoker.uncompiled_sources)) {
132 uncompiled_sources = invoker.uncompiled_sources
135 assert(defined(invoker.impl_dir),
136 "\"impl_dir\" must be defined for the $target_name template.")
137 impl_dir = invoker.impl_dir
139 bundle_generator_registration_name = target_name +
140 "_bundle_generator_registration"
141 action(bundle_generator_registration_name) {
142 script = compiler_script
143 inputs = compiler_sources + sources + uncompiled_sources
145 "$root_gen_dir/$impl_dir/generated_api_registration.cc",
146 "$root_gen_dir/$impl_dir/generated_api_registration.h",
149 "--root=" + rebase_path("//", root_build_dir),
150 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
151 "--namespace=$root_namespace",
152 "--generator=cpp-bundle-registration",
153 "--impl-dir=" + rebase_path(impl_dir, "//"),
155 rebase_path(sources, root_build_dir) +
156 rebase_path(uncompiled_sources, root_build_dir)
160 source_set(target_name) {
165 sources += get_target_outputs(":$schema_generator_name")
167 ":$schema_generator_name",
168 "//tools/json_schema_compiler:generated_api_util",
173 sources += get_target_outputs(":$bundle_generator_schema_name")
174 deps += [ ":$bundle_generator_schema_name" ]
177 if (bundle_registration) {
178 sources += get_target_outputs(":$bundle_generator_registration_name")
179 deps += [ ":$bundle_generator_registration_name" ]
182 if (defined(invoker.deps)) {
185 direct_dependent_configs = [ ":$generated_config_name" ]
187 if (defined(invoker.visibility)) {
188 visibility = invoker.visibility
190 if (defined(invoker.output_name)) {
191 output_name = invoker.output_name