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# TODO(brettw) this should maybe be moved to tools/json_schema_compiler/ where 6# the script is. Currently, we keep it in the build directory with the gyp 7# version to make it easier to find. 8# 9# Or, considering the fact that it references the chrome/extensions directory, 10# it should possibly be moved there. 11 12_api_gen_dir = "//tools/json_schema_compiler" 13_api_gen = "$_api_gen_dir/compiler.py" 14_impl_dir = "chrome/browser/extensions/api" 15 16_python_files = [ 17 "$_api_gen_dir/cc_generator.py", 18 "$_api_gen_dir/code.py", 19 "$_api_gen_dir/compiler.py", 20 "$_api_gen_dir/cpp_bundle_generator.py", 21 "$_api_gen_dir/cpp_type_generator.py", 22 "$_api_gen_dir/cpp_util.py", 23 "$_api_gen_dir/h_generator.py", 24 "$_api_gen_dir/idl_schema.py", 25 "$_api_gen_dir/json_schema.py", 26 "$_api_gen_dir/model.py", 27 "$_api_gen_dir/util_cc_helper.py", 28] 29 30# Runs the schema compiler over a list of sources. 31# 32# Parameters: 33# sources 34# The .json and .idl files to compile. 35# 36# root_namespace 37# The C++ namespace that all generated files go under. 38# 39# deps, visibility (optional) 40template("json_schema_compile") { 41 assert(defined(invoker.sources), "Need sources for $target_name") 42 assert(defined(invoker.root_namespace), 43 "Need root_namespace defined for $target_name") 44 45 action_name = "${target_name}_action" 46 source_set_name = target_name 47 48 action_foreach(action_name) { 49 visibility = ":$source_set_name" 50 script = _api_gen 51 52 source_prereqs = _python_files 53 sources = invoker.sources 54 55 # TODO(GYP) We should probably be using {{source_gen_dir}} instead of 56 # $target_gen_dir but support for this string isn't pushed out in GN 57 # binaries yet. Replace this when it is. 58 outputs = [ 59 "$target_gen_dir/{{source_name_part}}.cc", 60 "$target_gen_dir/{{source_name_part}}.h", 61 ] 62 63 args = [ 64 "--root", rebase_path("//", root_build_dir), 65 "--destdir", rebase_path(root_gen_dir, root_build_dir), 66 "--namespace", invoker.root_namespace, 67 "--generator=cpp", 68 "--impl-dir", _impl_dir, 69 "{{source}}", 70 ] 71 } 72 73 source_set(source_set_name) { 74 if (defined(invoker.visibility)) { 75 visibility = invoker.visibility 76 } 77 78 sources = get_target_outputs(":$action_name") 79 80 deps = [ ":$action_name" ] 81 if (defined(invoker.deps)) { 82 deps += invoker.deps 83 } 84 } 85} 86 87# Runs the schema bundler. 88# 89# Parameters: 90# sources 91# The .json and .idl files to bundle. 92# 93# root_namespace 94# The C++ namespace that all generated files go under. 95# 96# deps, visibility (optional) 97template("json_schema_bundle") { 98 assert(defined(invoker.sources), "Need sources for $target_name") 99 assert(defined(invoker.root_namespace), 100 "Need root_namespace defined for $target_name") 101 102 action_name = "${target_name}_action" 103 source_set_name = target_name 104 105 action(action_name) { 106 visibility = ":$source_set_name" 107 script = _api_gen 108 109 source_prereqs = _python_files 110 source_prereqs += invoker.sources 111 112 outputs = [ 113 "$target_gen_dir/generated_api.h", 114 "$target_gen_dir/generated_api.cc", 115 "$target_gen_dir/generated_schemas.h", 116 "$target_gen_dir/generated_schemas.cc", 117 ] 118 119 args = [ 120 "--root", rebase_path("//", root_build_dir), 121 "--destdir", rebase_path(root_gen_dir, root_build_dir), 122 "--namespace", invoker.root_namespace, 123 "--generator=cpp-bundle", 124 "--impl-dir", _impl_dir, 125 ] + rebase_path(invoker.sources, root_build_dir) 126 } 127 128 source_set(source_set_name) { 129 if (defined(invoker.visibility)) { 130 visibility = invoker.visibility 131 } 132 133 sources = get_target_outputs(":$action_name") 134 135 deps = [ ":$action_name" ] 136 if (defined(invoker.deps)) { 137 deps += invoker.deps 138 } 139 } 140} 141