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 # Converts a .json file to a C++ struct.
10 # Single file name of source .json file.
12 # schema_file (required)
13 # Single file name of the .json file that defines the schema.
15 # namespace (required)
16 # Namespace name to put result in.
18 # visibility (optional)
20 template("json_to_struct") {
21 assert(defined(invoker.source), "source required in $target_name")
22 assert(defined(invoker.schema_file), "schema_file required in $target_name")
23 assert(defined(invoker.namespace), "namespace required in $target_name")
25 action_name = target_name + "_action"
26 source_set_name = target_name
29 visibility = [ ":$source_set_name" ]
30 script = "//tools/json_to_struct/json_to_struct.py"
33 "//tools/json_to_struct/element_generator.py",
34 "//tools/json_to_struct/struct_generator.py",
38 out_dir = get_path_info(invoker.source, "gen_dir")
39 out_name = get_path_info(invoker.source, "name")
41 "$out_dir/$out_name.cc",
42 "$out_dir/$out_name.h",
46 rebase_path(invoker.source, root_build_dir),
47 "--destbase=" + rebase_path(out_dir, root_build_dir),
48 "--namespace=" + invoker.namespace,
49 "--schema=" + rebase_path(invoker.schema_file, root_build_dir),
53 source_set(source_set_name) {
54 if (defined(invoker.visibility)) {
55 visibility = invoker.visibility
58 sources = get_target_outputs(":$action_name")