OLD | NEW |
(Empty) | |
| 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. |
| 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 |
| 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.") |
| 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 |
| 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( |
| 76 schemas, |
| 77 [ "$target_gen_dir/{{source_name_part}}.cc", |
| 78 "$target_gen_dir/{{source_name_part}}.h", |
| 79 ]) |
| 80 |
| 81 schema_generator_name = target_name + "_schema_generator" |
| 82 action_foreach(schema_generator_name) { |
| 83 script = compiler_script |
| 84 hard_dep = true |
| 85 source_prereqs = compiler_sources |
| 86 sources = schemas |
| 87 outputs = [ |
| 88 "$target_gen_dir/{{source_name_part}}.cc", |
| 89 "$target_gen_dir/{{source_name_part}}.h", |
| 90 ] |
| 91 args = [ |
| 92 "{{source}}", |
| 93 "--root=" + rebase_path("//", root_build_dir), |
| 94 "--destdir=" + rebase_path(root_gen_dir, root_build_dir), |
| 95 "--namespace=$root_namespace", |
| 96 "--generator=cpp" ] |
| 97 visibility = target_visibility |
| 98 } |
| 99 |
| 100 bundle_generator_name = target_name + "_bundle_generator" |
| 101 bundle_outputs = [ |
| 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", |
| 106 ] |
| 107 action(bundle_generator_name) { |
| 108 script = compiler_script |
| 109 hard_dep = true |
| 110 source_prereqs = compiler_sources + schemas + uncompiled_schemas |
| 111 outputs = bundle_outputs |
| 112 args = [ |
| 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, "//"), |
| 118 ] + |
| 119 rebase_path(schemas, root_build_dir) + |
| 120 rebase_path(uncompiled_schemas, root_build_dir) |
| 121 } |
| 122 |
| 123 source_set(target_name) { |
| 124 hard_dep = true |
| 125 sources = compiled_schema_outputs + bundle_outputs |
| 126 deps = [ |
| 127 ":$schema_generator_name", |
| 128 ":$bundle_generator_name", |
| 129 "//tools/json_schema_compiler:generated_api_util", |
| 130 ] |
| 131 |
| 132 if (defined(invoker.deps)) { |
| 133 deps += invoker.deps |
| 134 } |
| 135 direct_dependent_configs = [ ":$generated_config_name" ] |
| 136 |
| 137 if (defined(invoker.visibility)) { |
| 138 visibility = invoker.visibility |
| 139 } |
| 140 if (defined(invoker.output_name)) { |
| 141 output_name = invoker.output_name |
| 142 } |
| 143 } |
| 144 } |
OLD | NEW |