1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
|
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This file contains templates for generating static libraries based on the
# corresponding output of the schema compiler tools. The output can be either
# the generated C++ types (generated_types template), the bundled extension
# function registration (json_schema_api template with
# bundle_registration = true), or the bundled JSON strings of the APIs
# (json_schema_api template with bundle = true). The generated library target
# has implicit hard dependencies on all schema files listed by the invoker and
# is itself a hard dependency.
#
# Common variables that can be used in all templates are:
# - sources [required] A list of schema files used to generate the C++ types.
#
# - root_namespace [required]
# A Python string substituion pattern used to generate the C++
# namespace for each API. Use %(namespace)s to replace with the API
# namespace, like "toplevel::%(namespace)s_api".
#
# schema_include_rules [optional]
# A list of paths to include when searching for referenced objects,
# with the namespace separated by a :.
# Example:
# [ '/foo/bar:Foo::Bar::%(namespace)s' ]
#
# - configs [optional]
# Extra gn configs to apply to the compile step.
#
# - deps [optional]
# If any deps are specified they will be inherited by the static library
# target.
#
# - visibility [optional]
# A specific visibility to apply for the generated static library. If
# omitted, visibility will be inherited from the invoker.
# NOTE: Common variables here for when multiple templates use them.
compiler_root = "//tools/json_schema_compiler"
compiler_script = "$compiler_root/compiler.py"
compiler_sources = [
"$compiler_root/cc_generator.py",
"$compiler_root/code_util.py",
"$compiler_root/compiler.py",
"$compiler_root/cpp_bundle_generator.py",
"$compiler_root/cpp_generator.py",
"$compiler_root/cpp_type_generator.py",
"$compiler_root/cpp_util.py",
"$compiler_root/h_generator.py",
"$compiler_root/idl_schema.py",
"$compiler_root/model.py",
"$compiler_root/util_cc_helper.py",
]
# Outputs the bundle of generated JSON strings for each API.
#
# Template-specific variables (in addition to the common ones described above):
#
# bundle_name [required]
# A string to prepend to generated bundle class names, so that multiple
# bundle rules can be used without conflicting. Only used with one of
# the cpp-bundle generators.
#
# root [optional]
# base directory of the source json file(s)
# defaults to "//"
#
# target_prefix [optional]
# subdir below root_gen_dir that is the base directory for the generated
# output files, defaults to empty string (no subdir)
template("generated_json_strings") {
assert(defined(invoker.sources),
"\"sources\" must be defined for the $target_name template.")
assert(defined(invoker.root_namespace),
"\"root_namespace\" must be defined for the $target_name template.")
assert(defined(invoker.bundle_name),
"\"bundle_name\" must be defined for bundles")
assert(!defined(invoker.root) || defined(invoker.target_prefix),
"\"target_prefix\" is required when \"root\" is specified")
schema_include_rules = ""
if (defined(invoker.schema_include_rules)) {
schema_include_rules = invoker.schema_include_rules
}
include_dir = root_gen_dir
destdir = rebase_path(root_gen_dir, root_build_dir)
if (defined(invoker.target_prefix)) {
destdir += "/${invoker.target_prefix}"
include_dir += "/${invoker.target_prefix}"
}
generated_config_name = target_name + "_generated_config"
config(generated_config_name) {
include_dirs = [ include_dir ]
}
root_namespace = invoker.root_namespace
if (defined(invoker.root)) {
root_folder = invoker.root
} else {
root_folder = "//"
}
# Save the target_name, since other targets (like the action() and
# action_foreach() below) need to reference them, but would have their own
# target_name variable.
root_target_name = target_name
bundle_generator_schema_name = target_name + "_bundle_generator_schema"
action(bundle_generator_schema_name) {
visibility = [ ":$root_target_name" ]
script = compiler_script
inputs = compiler_sources + invoker.sources
outputs = [
"$target_gen_dir/generated_schemas.cc",
"$target_gen_dir/generated_schemas.h",
]
args = [
"--root=" + rebase_path(root_folder, root_build_dir),
"--destdir=$destdir",
"--namespace=$root_namespace",
"--bundle-name=" + invoker.bundle_name,
"--generator=cpp-bundle-schema",
"--include-rules=$schema_include_rules",
] + rebase_path(invoker.sources, root_build_dir)
}
# Compute the contents of the library/source set.
lib_sources = get_target_outputs(":$bundle_generator_schema_name")
lib_deps = [ ":$bundle_generator_schema_name" ]
lib_public_deps = [
# For base::StringPiece.
"//base",
]
lib_extra_configs = []
if (defined(invoker.configs)) {
lib_extra_configs += invoker.configs
}
if (defined(invoker.deps)) {
lib_deps += invoker.deps
}
static_library(target_name) {
sources = lib_sources
deps = lib_deps
public_deps = lib_public_deps
configs += lib_extra_configs
configs += [ "//build/config/compiler:wexit_time_destructors" ]
public_configs = [ ":$generated_config_name" ]
if (defined(invoker.visibility)) {
visibility = invoker.visibility
}
}
}
# Outputs the bundle of extension function registrations.
#
# Template-specific variables (in addition to the common ones described above):
#
# bundle_name [required]
# A string to prepend to generated bundle class names, so that multiple
# bundle rules can be used without conflicting. Only used with one of
# the cpp-bundle generators.
#
# impl_dir [required if bundle_registration = true, otherwise unused]
# The path containing C++ implementations of API functions. This path is
# used as the root path when looking for {schema}/{schema}_api.h headers
# when generating API registration bundles. Such headers, if found, are
# automatically included by the generated code.
#
# root [optional]
# base directory of the source json file(s)
# defaults to "//"
#
# target_prefix [optional]
# subdir below root_gen_dir that is the base directory for the generated
# output files, defaults to empty string (no subdir)
template("function_registration") {
assert(defined(invoker.sources),
"\"sources\" must be defined for the $target_name template.")
assert(defined(invoker.root_namespace),
"\"root_namespace\" must be defined for the $target_name template.")
assert(defined(invoker.bundle_name),
"\"bundle_name\" must be defined for bundle registrations")
assert(defined(invoker.impl_dir),
"\"impl_dir\" must be defined for the $target_name template.")
assert(!defined(invoker.root) || defined(invoker.target_prefix),
"\"target_prefix\" is required when \"root\" is specified")
schema_include_rules = ""
if (defined(invoker.schema_include_rules)) {
schema_include_rules = invoker.schema_include_rules
}
include_dir = root_gen_dir
destdir = rebase_path(root_gen_dir, root_build_dir)
if (defined(invoker.target_prefix)) {
destdir += "/${invoker.target_prefix}"
include_dir += "/${invoker.target_prefix}"
}
generated_config_name = target_name + "_generated_config"
config(generated_config_name) {
include_dirs = [ include_dir ]
}
root_namespace = invoker.root_namespace
# Save the target_name, since other targets (like the action() and
# action_foreach() below) need to reference them, but would have their own
# target_name variable.
root_target_name = target_name
if (defined(invoker.root)) {
root_folder = invoker.root
} else {
root_folder = "//"
}
# Child directory inside the generated file tree.
gen_child_dir = get_path_info(invoker.impl_dir + "/", "gen_dir")
bundle_generator_registration_name =
target_name + "_bundle_generator_registration"
action(bundle_generator_registration_name) {
visibility = [ ":$root_target_name" ]
script = compiler_script
inputs = compiler_sources + invoker.sources
outputs = [
"$gen_child_dir/generated_api_registration.cc",
"$gen_child_dir/generated_api_registration.h",
]
args = [
"--root=" + rebase_path(root_folder, root_build_dir),
"--destdir=$destdir",
"--namespace=$root_namespace",
"--bundle-name=" + invoker.bundle_name,
"--generator=cpp-bundle-registration",
"--impl-dir=" + rebase_path(invoker.impl_dir, root_folder),
"--include-rules=$schema_include_rules",
] + rebase_path(invoker.sources, root_build_dir)
}
# Compute the contents of the library/source set.
lib_sources = get_target_outputs(":$bundle_generator_registration_name")
lib_deps = [ ":$bundle_generator_registration_name" ]
lib_extra_configs = []
if (defined(invoker.configs)) {
lib_extra_configs += invoker.configs
}
if (defined(invoker.deps)) {
lib_deps += invoker.deps
}
static_library(target_name) {
sources = lib_sources
deps = lib_deps
public_deps = []
configs += lib_extra_configs
configs += [ "//build/config/compiler:wexit_time_destructors" ]
public_configs = [ ":$generated_config_name" ]
if (defined(invoker.visibility)) {
visibility = invoker.visibility
}
}
}
# Generates the C++ types for the given APIs.
#
# root [optional]
# base directory of the source json file(s)
# defaults to "//"
#
# target_prefix [optional]
# subdir below root_gen_dir that is the base directory for the generated
# output files, defaults to empty string (no subdir)
template("generated_types") {
assert(defined(invoker.sources),
"\"sources\" must be defined for the $target_name template.")
assert(defined(invoker.root_namespace),
"\"root_namespace\" must be defined for the $target_name template.")
assert(!defined(invoker.root) || defined(invoker.target_prefix),
"\"target_prefix\" is required when \"root\" is specified")
schema_include_rules = ""
if (defined(invoker.schema_include_rules)) {
schema_include_rules = invoker.schema_include_rules
}
include_dir = root_gen_dir
destdir = rebase_path(root_gen_dir, root_build_dir)
if (defined(invoker.target_prefix)) {
destdir += "/${invoker.target_prefix}"
include_dir += "/${invoker.target_prefix}"
}
generated_config_name = target_name + "_generated_config"
config(generated_config_name) {
include_dirs = [ include_dir ]
}
if (defined(invoker.root)) {
root_folder = invoker.root
} else {
root_folder = "//"
}
root_namespace = invoker.root_namespace
# Save the target_name, since other targets (like the action() and
# action_foreach() below) need to reference them, but would have their own
# target_name variable.
root_target_name = target_name
schema_generator_name = target_name + "_schema_generator"
action_foreach(schema_generator_name) {
visibility = [ ":$root_target_name" ]
script = compiler_script
sources = invoker.sources
inputs = compiler_sources
outputs = [
"$target_gen_dir/{{source_name_part}}.cc",
"$target_gen_dir/{{source_name_part}}.h",
]
args = [
"{{source}}",
"--root=" + rebase_path(root_folder, root_build_dir),
"--destdir=$destdir",
"--namespace=$root_namespace",
"--generator=cpp",
"--include-rules=$schema_include_rules",
]
}
# Compute the contents of the library/source set.
lib_sources = get_target_outputs(":$schema_generator_name")
lib_public_deps = [ ":$schema_generator_name" ]
lib_deps = [
"//base",
"//tools/json_schema_compiler:generated_api_util",
]
lib_extra_configs = []
if (defined(invoker.configs)) {
lib_extra_configs += invoker.configs
}
if (defined(invoker.deps)) {
lib_deps += invoker.deps
}
static_library(target_name) {
sources = lib_sources
deps = lib_deps
public_deps = lib_public_deps
configs += lib_extra_configs
configs += [ "//build/config/compiler:wexit_time_destructors" ]
public_configs = [ ":$generated_config_name" ]
if (defined(invoker.visibility)) {
visibility = invoker.visibility
}
}
}
|