Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 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 # Compile a flatbuffer. | |
| 6 # | |
| 7 # flatc_out_dir (optional) | |
| 8 # Specifies the path suffix that output files are generated under. This | |
| 9 # path will be appended to root_gen_dir. | |
| 10 # | |
| 11 # Targets that depend on the proto target will be able to include the | |
| 12 # resulting flatbuffers header with an include like: | |
| 13 # #include "dir/for/my_flatbuffer/buffer_generated.h" | |
| 14 # If undefined, this defaults to matchign the input directory for each | |
| 15 # .fbs file (you should almost always use the default mode). | |
| 16 # | |
| 17 # deps (optional) | |
| 18 # Additional dependencies. | |
| 19 # | |
| 20 # Parameters for compiling the generated code: | |
| 21 # | |
| 22 # defines (optional) | |
| 23 # Defines to supply to the source set that compiles the generated source | |
| 24 # code. | |
| 25 # | |
| 26 # extra_configs (optional) | |
| 27 # A list of config labels that will be appended to the configs applying | |
| 28 # to the source set. | |
| 29 # | |
| 30 # testonly (optional) | |
| 31 # Boolean to indicate whether the generated source sets should be labeled | |
| 32 # as testonly. | |
| 33 # | |
| 34 # Example: | |
| 35 # flatbuffers_library("mylib") { | |
| 36 # sources = [ | |
| 37 # "foo.fbs", | |
| 38 # ] | |
| 39 # } | |
| 40 | |
| 41 template("flatbuffers_library") { | |
|
brettw
2016/04/21 20:00:03
I prefer to name the gni files the same as the tem
battre
2016/04/25 14:31:47
Done. I am uncertain what to do with the .gypi fil
| |
| 42 assert(defined(invoker.sources), "Need sources for flatbuffers_library") | |
| 43 | |
| 44 # Don't apply OS-specific sources filtering to the assignments later on. | |
| 45 # Platform files should have gotten filtered out in the sources assignment | |
| 46 # when this template was invoked. If they weren't, it was on purpose and | |
| 47 # this template shouldn't re-apply the filter. | |
| 48 set_sources_assignment_filter([]) | |
| 49 | |
| 50 action_name = "${target_name}_gen" | |
| 51 source_set_name = target_name | |
| 52 action_foreach(action_name) { | |
|
brettw
2016/04/21 20:00:03
This is wrong for cross-compile cases. You can sol
battre
2016/04/25 14:31:47
Done.
| |
| 53 visibility = [ ":$source_set_name" ] | |
| 54 | |
| 55 deps = [ | |
| 56 "//third_party/flatbuffers:flatc", | |
| 57 ] | |
| 58 | |
| 59 script = "//third_party/flatbuffers/flatc_wrapper.py" | |
| 60 | |
| 61 sources = invoker.sources | |
| 62 | |
| 63 if (defined(invoker.flatc_out_dir)) { | |
| 64 out_dir = "$root_gen_dir/" + invoker.flatc_out_dir | |
| 65 } else { | |
| 66 out_dir = "{{source_gen_dir}}" | |
| 67 } | |
| 68 | |
| 69 outputs = [ | |
| 70 "$out_dir/{{source_name_part}}_generated.h", | |
| 71 ] | |
| 72 | |
| 73 args = [ | |
| 74 "./flatc", | |
| 75 "-c", | |
| 76 "-o", | |
| 77 "$out_dir", | |
| 78 "{{source}}", | |
| 79 ] | |
| 80 | |
| 81 # The deps may have steps that have to run before running flatc. | |
| 82 if (defined(invoker.deps)) { | |
| 83 deps += invoker.deps | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 source_set(target_name) { | |
| 88 forward_variables_from(invoker, | |
| 89 [ | |
| 90 "visibility", | |
| 91 "defines", | |
| 92 ]) | |
| 93 | |
| 94 sources = get_target_outputs(":$action_name") | |
| 95 | |
| 96 if (defined(invoker.extra_configs)) { | |
| 97 configs += invoker.extra_configs | |
| 98 } | |
| 99 | |
| 100 if (defined(invoker.testonly)) { | |
| 101 testonly = invoker.testonly | |
| 102 } | |
| 103 | |
| 104 public_configs = [ "//third_party/flatbuffers:flatbuffers_config" ] | |
| 105 | |
| 106 public_deps = [ | |
| 107 # The generated headers reference headers within flatbuffers, so | |
| 108 # dependencies must be able to find those headers too. | |
| 109 "//third_party/flatbuffers:flatbuffers", | |
|
brettw
2016/04/21 20:00:03
Delete the redundant ":flatbuffers"
battre
2016/04/25 14:31:47
Done.
| |
| 110 ] | |
| 111 deps = [ | |
| 112 ":$action_name", | |
| 113 ] | |
| 114 | |
| 115 # This will link any libraries in the deps (the use of invoker.deps in the | |
| 116 # action won't link it). | |
| 117 if (defined(invoker.deps)) { | |
| 118 deps += invoker.deps | |
| 119 } | |
| 120 } | |
| 121 } | |
| OLD | NEW |