tree: 6e542257a582156db34f0a56965c46c7bb8c7a45 [path history] [tgz]
  1. examples/
  2. BUILD.gn
  3. fidlmerge.go
  4. flags.go
  5. OWNERS
  6. README.md
tools/fidl/fidlmerge/README.md

fidlmerge

A host tool for generating arbitrary code from FIDL namespace JSON.

fidlmerge merges the FIDL namespace JSON generated by the FIDL compiler front end with a template. Templates are based on go's text/template package.

Usage

fidlmerge -template <template path> -json <json path> -output-base <output file base name> [ -options key=value,... ] [ -amend <amend path> ]

Example templates reside in the examples subdirectory.

The json path is something like out/x64/fidling/gen/sdk/fidl/fuchsia.netstack.fidl.json.

The output file base name is used to generate output file names. The template can add extensions to the base name.

Options can be accessed by templates using the getOption function or one of its variants.

The amend path refers to a json file that contains amendments to the FIDL json. Declarations can be omitted from the FIDL data using the “exclusions” property:

{
  "exclusions": [
    "fuchsia.media/VideoProfile",
    "fuchsia.media/PixelFormat"
  ]
}

Templates

Template format documentation is here. Also see the example templates in the examples subdirectory.

Template files contain multiple named templates. The main template is invoked initially and given a main.Root struct (see generator.go) as the dot value. Text generated by the template is routed to stdout, which will be unsuitable for most purposes. Normally, the main template will use main.Root.Generate to generate a specific file or files. Here, for example, we're generating two files, one a .h and the other a .cc:

{{- define "Main" }}
    {{- $include_path := .Output ".h" }}
    {{- $implementation_path := .Output ".cc" }}
    {{ .Generate $include_path "IncludeFile" . }}
    {{ .Generate $implementation_path "ImplementationFile" . }}
{{ end }}

The .h file is generated by a template named IncludeFile, and the .cc file is generated by a template named ImplmentationFile.

main.Root provides the .Output and .Generate methods. The description of the FIDL namespace is defined by types.Root (in fidl/compiler/backend/types), which is part of main.Root.