Home | History | Annotate | Download | only in json_to_struct
      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 # Converts a .json file to a C++ struct.
      6 #
      7 # Variables:
      8 #
      9 #   source (required)
     10 #       Single file name of source .json file.
     11 #
     12 #   schema_file (required)
     13 #       Single file name of the .json file that defines the schema.
     14 #
     15 #   namespace (required)
     16 #       Namespace name to put result in.
     17 #
     18 #   visibility (optional)
     19 #       Normal meaning.
     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")
     24 
     25   action_name = target_name + "_action"
     26   source_set_name = target_name
     27 
     28   action(action_name) {
     29     visibility = [ ":$source_set_name" ]
     30     script = "//tools/json_to_struct/json_to_struct.py"
     31 
     32     inputs = [
     33       "//tools/json_to_struct/element_generator.py",
     34       "//tools/json_to_struct/struct_generator.py",
     35       invoker.source,
     36     ]
     37 
     38     out_dir = get_path_info(invoker.source, "gen_dir")
     39     out_name = get_path_info(invoker.source, "name")
     40     outputs = [
     41       "$out_dir/$out_name.cc",
     42       "$out_dir/$out_name.h",
     43     ]
     44 
     45     args = [
     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),
     50     ]
     51   }
     52 
     53   source_set(source_set_name) {
     54     if (defined(invoker.visibility)) {
     55       visibility = invoker.visibility
     56     }
     57 
     58     sources = get_target_outputs(":$action_name")
     59 
     60     deps = [ ":$action_name" ]
     61   }
     62 }
     63