1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2016 The Chromium Authors 2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file. 4*8975f5c5SAndroid Build Coastguard Worker 5*8975f5c5SAndroid Build Coastguard Worker# Compile a flatbuffer. 6*8975f5c5SAndroid Build Coastguard Worker# 7*8975f5c5SAndroid Build Coastguard Worker# flatc_out_dir (optional) 8*8975f5c5SAndroid Build Coastguard Worker# Specifies the path suffix that output files are generated under. This 9*8975f5c5SAndroid Build Coastguard Worker# path will be appended to root_gen_dir. 10*8975f5c5SAndroid Build Coastguard Worker# 11*8975f5c5SAndroid Build Coastguard Worker# Targets that depend on the flatbuffer target will be able to include 12*8975f5c5SAndroid Build Coastguard Worker# the resulting FlatBuffers header with an include like: 13*8975f5c5SAndroid Build Coastguard Worker# #include "dir/for/my_flatbuffer/buffer_generated.h" 14*8975f5c5SAndroid Build Coastguard Worker# If undefined, this defaults to matchign the input directory for each 15*8975f5c5SAndroid Build Coastguard Worker# .fbs file (you should almost always use the default mode). 16*8975f5c5SAndroid Build Coastguard Worker# 17*8975f5c5SAndroid Build Coastguard Worker# flatc_include_dirs (optional) 18*8975f5c5SAndroid Build Coastguard Worker# Specifies the directories which FlatBuffers compiler uses to find 19*8975f5c5SAndroid Build Coastguard Worker# included .fbs files in. Almost always should be empty. 20*8975f5c5SAndroid Build Coastguard Worker# 21*8975f5c5SAndroid Build Coastguard Worker# The list always has an implicit first item corresponding to the root of 22*8975f5c5SAndroid Build Coastguard Worker# the source tree. This enables including .fbs files by absolute path. 23*8975f5c5SAndroid Build Coastguard Worker# 24*8975f5c5SAndroid Build Coastguard Worker# The compiler will try the directories in the order given, and if all 25*8975f5c5SAndroid Build Coastguard Worker# fail it will try to load relative to the directory of the schema file 26*8975f5c5SAndroid Build Coastguard Worker# being parsed. 27*8975f5c5SAndroid Build Coastguard Worker# 28*8975f5c5SAndroid Build Coastguard Worker# mutable (optional) 29*8975f5c5SAndroid Build Coastguard Worker# Boolean to compile flatbuffers with the "--gen-mutable" argument, which 30*8975f5c5SAndroid Build Coastguard Worker# generates non-const accessors for mutating FlatBuffers in-place. 31*8975f5c5SAndroid Build Coastguard Worker# 32*8975f5c5SAndroid Build Coastguard Worker# deps (optional) 33*8975f5c5SAndroid Build Coastguard Worker# Additional dependencies. 34*8975f5c5SAndroid Build Coastguard Worker# 35*8975f5c5SAndroid Build Coastguard Worker# Parameters for compiling the generated code: 36*8975f5c5SAndroid Build Coastguard Worker# 37*8975f5c5SAndroid Build Coastguard Worker# defines (optional) 38*8975f5c5SAndroid Build Coastguard Worker# Defines to supply to the source set that compiles the generated source 39*8975f5c5SAndroid Build Coastguard Worker# code. 40*8975f5c5SAndroid Build Coastguard Worker# 41*8975f5c5SAndroid Build Coastguard Worker# extra_configs (optional) 42*8975f5c5SAndroid Build Coastguard Worker# A list of config labels that will be appended to the configs applying 43*8975f5c5SAndroid Build Coastguard Worker# to the source set. 44*8975f5c5SAndroid Build Coastguard Worker# 45*8975f5c5SAndroid Build Coastguard Worker# testonly (optional) 46*8975f5c5SAndroid Build Coastguard Worker# Boolean to indicate whether the generated source sets should be labeled 47*8975f5c5SAndroid Build Coastguard Worker# as testonly. 48*8975f5c5SAndroid Build Coastguard Worker# 49*8975f5c5SAndroid Build Coastguard Worker# Example: 50*8975f5c5SAndroid Build Coastguard Worker# flatbuffer("mylib") { 51*8975f5c5SAndroid Build Coastguard Worker# sources = [ 52*8975f5c5SAndroid Build Coastguard Worker# "foo.fbs", 53*8975f5c5SAndroid Build Coastguard Worker# ] 54*8975f5c5SAndroid Build Coastguard Worker# } 55*8975f5c5SAndroid Build Coastguard Worker 56*8975f5c5SAndroid Build Coastguard Workerimport("//build/compiled_action.gni") 57*8975f5c5SAndroid Build Coastguard Worker 58*8975f5c5SAndroid Build Coastguard Workertemplate("flatbuffer") { 59*8975f5c5SAndroid Build Coastguard Worker assert(defined(invoker.sources), "Need sources for flatbuffers_library") 60*8975f5c5SAndroid Build Coastguard Worker 61*8975f5c5SAndroid Build Coastguard Worker action_name = "${target_name}_gen" 62*8975f5c5SAndroid Build Coastguard Worker source_set_name = target_name 63*8975f5c5SAndroid Build Coastguard Worker compiled_action_foreach(action_name) { 64*8975f5c5SAndroid Build Coastguard Worker visibility = [ ":$source_set_name" ] 65*8975f5c5SAndroid Build Coastguard Worker 66*8975f5c5SAndroid Build Coastguard Worker tool = "//third_party/flatbuffers:flatc" 67*8975f5c5SAndroid Build Coastguard Worker 68*8975f5c5SAndroid Build Coastguard Worker sources = invoker.sources 69*8975f5c5SAndroid Build Coastguard Worker deps = [] 70*8975f5c5SAndroid Build Coastguard Worker 71*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.flatc_out_dir)) { 72*8975f5c5SAndroid Build Coastguard Worker out_dir = "$root_gen_dir/" + invoker.flatc_out_dir 73*8975f5c5SAndroid Build Coastguard Worker } else { 74*8975f5c5SAndroid Build Coastguard Worker out_dir = "{{source_gen_dir}}" 75*8975f5c5SAndroid Build Coastguard Worker } 76*8975f5c5SAndroid Build Coastguard Worker 77*8975f5c5SAndroid Build Coastguard Worker outputs = [ "$out_dir/{{source_name_part}}_generated.h" ] 78*8975f5c5SAndroid Build Coastguard Worker 79*8975f5c5SAndroid Build Coastguard Worker args = [ 80*8975f5c5SAndroid Build Coastguard Worker "-c", 81*8975f5c5SAndroid Build Coastguard Worker "--keep-prefix", 82*8975f5c5SAndroid Build Coastguard Worker "-o", 83*8975f5c5SAndroid Build Coastguard Worker "$out_dir", 84*8975f5c5SAndroid Build Coastguard Worker "-I", 85*8975f5c5SAndroid Build Coastguard Worker rebase_path("//", root_build_dir), 86*8975f5c5SAndroid Build Coastguard Worker ] 87*8975f5c5SAndroid Build Coastguard Worker 88*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.flatc_include_dirs)) { 89*8975f5c5SAndroid Build Coastguard Worker foreach(include_dir, invoker.flatc_include_dirs) { 90*8975f5c5SAndroid Build Coastguard Worker args += [ 91*8975f5c5SAndroid Build Coastguard Worker "-I", 92*8975f5c5SAndroid Build Coastguard Worker rebase_path(include_dir, root_build_dir), 93*8975f5c5SAndroid Build Coastguard Worker ] 94*8975f5c5SAndroid Build Coastguard Worker } 95*8975f5c5SAndroid Build Coastguard Worker } 96*8975f5c5SAndroid Build Coastguard Worker 97*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.mutable) && invoker.mutable) { 98*8975f5c5SAndroid Build Coastguard Worker args += [ "--gen-mutable" ] 99*8975f5c5SAndroid Build Coastguard Worker } 100*8975f5c5SAndroid Build Coastguard Worker 101*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.args)) { 102*8975f5c5SAndroid Build Coastguard Worker args += invoker.args 103*8975f5c5SAndroid Build Coastguard Worker } 104*8975f5c5SAndroid Build Coastguard Worker 105*8975f5c5SAndroid Build Coastguard Worker args += [ "{{source}}" ] 106*8975f5c5SAndroid Build Coastguard Worker 107*8975f5c5SAndroid Build Coastguard Worker # The deps may have steps that have to run before running flatc. 108*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 109*8975f5c5SAndroid Build Coastguard Worker deps += invoker.deps 110*8975f5c5SAndroid Build Coastguard Worker } 111*8975f5c5SAndroid Build Coastguard Worker } 112*8975f5c5SAndroid Build Coastguard Worker 113*8975f5c5SAndroid Build Coastguard Worker source_set(target_name) { 114*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 115*8975f5c5SAndroid Build Coastguard Worker [ 116*8975f5c5SAndroid Build Coastguard Worker "visibility", 117*8975f5c5SAndroid Build Coastguard Worker "defines", 118*8975f5c5SAndroid Build Coastguard Worker ]) 119*8975f5c5SAndroid Build Coastguard Worker 120*8975f5c5SAndroid Build Coastguard Worker sources = get_target_outputs(":$action_name") 121*8975f5c5SAndroid Build Coastguard Worker 122*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.extra_configs)) { 123*8975f5c5SAndroid Build Coastguard Worker configs += invoker.extra_configs 124*8975f5c5SAndroid Build Coastguard Worker } 125*8975f5c5SAndroid Build Coastguard Worker 126*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.testonly)) { 127*8975f5c5SAndroid Build Coastguard Worker testonly = invoker.testonly 128*8975f5c5SAndroid Build Coastguard Worker } 129*8975f5c5SAndroid Build Coastguard Worker 130*8975f5c5SAndroid Build Coastguard Worker public_configs = [ "//third_party/flatbuffers:flatbuffers_config" ] 131*8975f5c5SAndroid Build Coastguard Worker 132*8975f5c5SAndroid Build Coastguard Worker public_deps = [ 133*8975f5c5SAndroid Build Coastguard Worker # The generated headers reference headers within FlatBuffers, so 134*8975f5c5SAndroid Build Coastguard Worker # dependencies must be able to find those headers too. 135*8975f5c5SAndroid Build Coastguard Worker ":$action_name", 136*8975f5c5SAndroid Build Coastguard Worker "//third_party/flatbuffers", 137*8975f5c5SAndroid Build Coastguard Worker ] 138*8975f5c5SAndroid Build Coastguard Worker 139*8975f5c5SAndroid Build Coastguard Worker # This will link any libraries in the deps (the use of invoker.deps in the 140*8975f5c5SAndroid Build Coastguard Worker # action won't link it). 141*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 142*8975f5c5SAndroid Build Coastguard Worker deps = invoker.deps 143*8975f5c5SAndroid Build Coastguard Worker } 144*8975f5c5SAndroid Build Coastguard Worker 145*8975f5c5SAndroid Build Coastguard Worker # Same for public_deps. 146*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.public_deps)) { 147*8975f5c5SAndroid Build Coastguard Worker public_deps += invoker.public_deps 148*8975f5c5SAndroid Build Coastguard Worker } 149*8975f5c5SAndroid Build Coastguard Worker } 150*8975f5c5SAndroid Build Coastguard Worker} 151