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 # The namespace in which generated API code is to be
16 # wrapped. C++ namespace syntax is accepted for nested namespace
17 # (e.g. "foo::bar::api").
19 # bundle [optional, default = false]
20 # Boolean indicating if the schema files should be bundled or not.
22 # impl_dir [required if bundle = true, otherwise unused]
23 # The path containing C++ implementations of API functions. This path is
24 # used as the root path when looking for {schema}/{schema}_api.h headers
25 # during the API bundle generation phase. Such headers, if found, are
26 # automatically included by the generated code.
28 # uncompiled_sources [optional, only used when bundle = true]
29 # A list of schema files which should not be compiled, but which should still
30 # be processed for API bundle generation.
33 # If any deps are specified they will be inherited by the static library
36 # The static libarary target also inherits the visibility and output_name
39 template("generated_extensions_api") {
40 assert(defined(invoker.sources),
41 "\"sources\" must be defined for the $target_name template.")
42 assert(defined(invoker.root_namespace),
43 "\"root_namespace\" must be defined for the $target_name template.")
45 bundle = defined(invoker.bundle) && invoker.bundle
47 # Keep a copy of the target_name here since it will be trampled
49 target_visibility = ":$target_name"
51 generated_config_name = target_name + "_generated_config"
52 config(generated_config_name) {
53 include_dirs = [ target_gen_dir ]
54 visibility = target_visibility
57 schemas = invoker.sources
58 root_namespace = invoker.root_namespace
60 compiler_root = "//tools/json_schema_compiler"
61 compiler_script = "$compiler_root/compiler.py"
63 "$compiler_root/cc_generator.py",
64 "$compiler_root/code.py",
65 "$compiler_root/compiler.py",
66 "$compiler_root/cpp_generator.py",
67 "$compiler_root/cpp_type_generator.py",
68 "$compiler_root/cpp_util.py",
69 "$compiler_root/h_generator.py",
70 "$compiler_root/idl_schema.py",
71 "$compiler_root/model.py",
72 "$compiler_root/util_cc_helper.py",
75 schema_generator_name = target_name + "_schema_generator"
76 action_foreach(schema_generator_name) {
77 script = compiler_script
78 inputs = compiler_sources
81 "$target_gen_dir/{{source_name_part}}.cc",
82 "$target_gen_dir/{{source_name_part}}.h",
86 "--root=" + rebase_path("//", root_build_dir),
87 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
88 "--namespace=$root_namespace",
90 visibility = target_visibility
94 assert(defined(invoker.impl_dir),
95 "\"impl_dir\" must be defined for the $target_name template.")
96 impl_dir = invoker.impl_dir
98 uncompiled_schemas = []
99 if (defined(invoker.uncompiled_sources)) {
100 uncompiled_schemas = invoker.uncompiled_sources
103 bundle_generator_name = target_name + "_bundle_generator"
104 action(bundle_generator_name) {
105 script = compiler_script
106 inputs = compiler_sources + schemas + uncompiled_schemas
108 "$target_gen_dir/generated_api.cc",
109 "$target_gen_dir/generated_api.h",
110 "$target_gen_dir/generated_schemas.cc",
111 "$target_gen_dir/generated_schemas.h",
114 "--root=" + rebase_path("//", root_build_dir),
115 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
116 "--namespace=$root_namespace",
117 "--generator=cpp-bundle",
118 "--impl-dir=" + rebase_path(impl_dir, "//"),
120 rebase_path(schemas, root_build_dir) +
121 rebase_path(uncompiled_schemas, root_build_dir)
125 source_set(target_name) {
126 sources = get_target_outputs(":$schema_generator_name")
129 ":$schema_generator_name",
130 "//tools/json_schema_compiler:generated_api_util",
134 sources += get_target_outputs(":$bundle_generator_name")
135 deps += [ ":$bundle_generator_name" ]
138 if (defined(invoker.deps)) {
141 direct_dependent_configs = [ ":$generated_config_name" ]
143 if (defined(invoker.visibility)) {
144 visibility = invoker.visibility
146 if (defined(invoker.output_name)) {
147 output_name = invoker.output_name