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] The namespace in which generated API code is to be
15 # wrapped. C++ namespace syntax is accepted for nested namespace
16 # (e.g. "foo::bar::api").
18 # impl_dir [required] The path containing C++ implementations of API functions.
19 # This path is used as the root path when looking for
20 # {schema}/{schema}_api.h headers during the API bundle generation phase.
21 # Such headers, if found, are automatically included by the generated code.
23 # uncompiled_sources [optional] A list of schema files which should not be
24 # compiled, but which should still be processed for API bundle generation.
26 # deps [optional] If any deps are specified they will be inherited by the
27 # static library target.
29 # The static libarary target also inherits the visibility and output_name
32 template("generated_extensions_api") {
33 assert(defined(invoker.sources),
34 "\"sources\" must be defined for the $target_name template.")
35 assert(defined(invoker.root_namespace),
36 "\"root_namespace\" must be defined for the $target_name template.")
37 assert(defined(invoker.impl_dir),
38 "\"impl_dir\" must be defined for the $target_name template.")
40 # Keep a copy of the target_name here since it will be trampled
42 target_visibility = ":$target_name"
44 generated_config_name = target_name + "_generated_config"
45 config(generated_config_name) {
46 include_dirs = [ target_gen_dir ]
47 visibility = target_visibility
50 schemas = invoker.sources
51 root_namespace = invoker.root_namespace
52 impl_dir = invoker.impl_dir
53 uncompiled_schemas = []
54 if (defined(invoker.uncompiled_sources)) {
55 uncompiled_schemas = invoker.uncompiled_sources
58 compiler_root = "//tools/json_schema_compiler"
59 compiler_script = "$compiler_root/compiler.py"
61 "$compiler_root/cc_generator.py",
62 "$compiler_root/code.py",
63 "$compiler_root/compiler.py",
64 "$compiler_root/cpp_generator.py",
65 "$compiler_root/cpp_type_generator.py",
66 "$compiler_root/cpp_util.py",
67 "$compiler_root/h_generator.py",
68 "$compiler_root/idl_schema.py",
69 "$compiler_root/model.py",
70 "$compiler_root/util_cc_helper.py",
73 # This list mirrors the outputs that will be generated by the following
74 # action_foreach. It's used by the static_library target.
75 compiled_schema_outputs = process_file_template(
77 [ "$target_gen_dir/{{source_name_part}}.cc",
78 "$target_gen_dir/{{source_name_part}}.h",
81 schema_generator_name = target_name + "_schema_generator"
82 action_foreach(schema_generator_name) {
83 script = compiler_script
85 source_prereqs = compiler_sources
88 "$target_gen_dir/{{source_name_part}}.cc",
89 "$target_gen_dir/{{source_name_part}}.h",
93 "--root=" + rebase_path("//", root_build_dir),
94 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
95 "--namespace=$root_namespace",
97 visibility = target_visibility
100 bundle_generator_name = target_name + "_bundle_generator"
102 "$target_gen_dir/generated_api.cc",
103 "$target_gen_dir/generated_api.h",
104 "$target_gen_dir/generated_schemas.cc",
105 "$target_gen_dir/generated_schemas.h",
107 action(bundle_generator_name) {
108 script = compiler_script
110 source_prereqs = compiler_sources + schemas + uncompiled_schemas
111 outputs = bundle_outputs
113 "--root=" + rebase_path("//", root_build_dir),
114 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
115 "--namespace=$root_namespace",
116 "--generator=cpp-bundle",
117 "--impl-dir=" + rebase_path(impl_dir, "//"),
119 rebase_path(schemas, root_build_dir) +
120 rebase_path(uncompiled_schemas, root_build_dir)
123 source_set(target_name) {
125 sources = compiled_schema_outputs + bundle_outputs
127 ":$schema_generator_name",
128 ":$bundle_generator_name",
129 "//tools/json_schema_compiler:generated_api_util",
132 if (defined(invoker.deps)) {
135 direct_dependent_configs = [ ":$generated_config_name" ]
137 if (defined(invoker.visibility)) {
138 visibility = invoker.visibility
140 if (defined(invoker.output_name)) {
141 output_name = invoker.output_name