blob: c8817a6d443569ecdc4bb913f04a655165ff5840 [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#
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").
17#
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.
22#
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.
25#
26# deps [optional] If any deps are specified they will be inherited by the
27# static library target.
28#
29# The static libarary target also inherits the visibility and output_name
30# of its invoker.
31
32template("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.")
39
40 # Keep a copy of the target_name here since it will be trampled
41 # in nested targets.
42 target_visibility = ":$target_name"
43
44 generated_config_name = target_name + "_generated_config"
45 config(generated_config_name) {
46 include_dirs = [ target_gen_dir ]
47 visibility = target_visibility
48 }
49
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
56 }
57
58 compiler_root = "//tools/json_schema_compiler"
59 compiler_script = "$compiler_root/compiler.py"
60 compiler_sources = [
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",
71 ]
72
[email protected]30c409f2014-04-26 09:56:0973 schema_generator_name = target_name + "_schema_generator"
74 action_foreach(schema_generator_name) {
75 script = compiler_script
[email protected]30c409f2014-04-26 09:56:0976 source_prereqs = compiler_sources
77 sources = schemas
78 outputs = [
79 "$target_gen_dir/{{source_name_part}}.cc",
80 "$target_gen_dir/{{source_name_part}}.h",
81 ]
82 args = [
83 "{{source}}",
84 "--root=" + rebase_path("//", root_build_dir),
85 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
86 "--namespace=$root_namespace",
87 "--generator=cpp" ]
88 visibility = target_visibility
89 }
90
91 bundle_generator_name = target_name + "_bundle_generator"
[email protected]30c409f2014-04-26 09:56:0992 action(bundle_generator_name) {
93 script = compiler_script
[email protected]30c409f2014-04-26 09:56:0994 source_prereqs = compiler_sources + schemas + uncompiled_schemas
[email protected]351f238a2014-05-09 01:32:1095 outputs = [
96 "$target_gen_dir/generated_api.cc",
97 "$target_gen_dir/generated_api.h",
98 "$target_gen_dir/generated_schemas.cc",
99 "$target_gen_dir/generated_schemas.h",
100 ]
[email protected]30c409f2014-04-26 09:56:09101 args = [
102 "--root=" + rebase_path("//", root_build_dir),
103 "--destdir=" + rebase_path(root_gen_dir, root_build_dir),
104 "--namespace=$root_namespace",
105 "--generator=cpp-bundle",
106 "--impl-dir=" + rebase_path(impl_dir, "//"),
107 ] +
108 rebase_path(schemas, root_build_dir) +
109 rebase_path(uncompiled_schemas, root_build_dir)
110 }
111
112 source_set(target_name) {
[email protected]351f238a2014-05-09 01:32:10113 sources =
114 get_target_outputs(":$schema_generator_name") +
115 get_target_outputs(":$bundle_generator_name")
116
[email protected]30c409f2014-04-26 09:56:09117 deps = [
118 ":$schema_generator_name",
119 ":$bundle_generator_name",
120 "//tools/json_schema_compiler:generated_api_util",
121 ]
122
123 if (defined(invoker.deps)) {
124 deps += invoker.deps
125 }
126 direct_dependent_configs = [ ":$generated_config_name" ]
127
128 if (defined(invoker.visibility)) {
129 visibility = invoker.visibility
130 }
131 if (defined(invoker.output_name)) {
132 output_name = invoker.output_name
133 }
134 }
135}