# Copyright 2016 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # Compile a flatbuffer to typescript. # # flatc_include_dirs (optional) # Specifies the directories which FlatBuffers compiler uses to find # included .fbs files in. Almost always should be empty. # # The list always has an implicit first item corresponding to the root of # the source tree. This enables including .fbs files by absolute path. # # The compiler will try the directories in the order given, and if all # fail it will try to load relative to the directory of the schema file # being parsed. # # deps (optional) # Additional dependencies. # # Example: # ts_flatbuffer("foo_ts") { # sources = [ # "foo.fbs", # ] # } import("//build/compiled_action.gni") template("ts_flatbuffer") { assert(defined(invoker.sources), "Need sources for flatbuffers_library") # Don't apply OS-specific sources filtering to the assignments later on. # Platform files should have gotten filtered out in the sources assignment # when this template was invoked. If they weren't, it was on purpose and # this template shouldn't re-apply the filter. set_sources_assignment_filter([]) copy_name = target_name + "_copy" copy(copy_name) { sources = [ "//third_party/flatbuffers/src/js/flatbuffers.js" ] outputs = [ "$target_gen_dir/flatbuffers.js" ] } compiled_action_foreach(target_name) { tool = "//third_party/flatbuffers:flatc" sources = invoker.sources deps = [ ":" + copy_name ] out_dir = target_gen_dir outputs = [ "$out_dir/{{source_name_part}}_generated.ts", ] args = [ "--ts", "--no-fb-import", "--gen-mutable", "-o", rebase_path(out_dir, root_build_dir), "-I", rebase_path("//", root_build_dir), ] if (defined(invoker.flatc_include_dirs)) { foreach(include_dir, invoker.flatc_include_dirs) { args += [ "-I", rebase_path(include_dir, root_build_dir), ] } } args += [ "{{source}}" ] # The deps may have steps that have to run before running flatc. if (defined(invoker.deps)) { deps += invoker.deps } } }