blob: 94966415955e470453407d00433bab327fe56c74 [file] [log] [blame] [edit]
# Helper file to convert text format protobuf files to binary format.
# Note: This file is similar to proto_library.gni, but is kept separate because
# - They expect different inputs/outputs: both rules would have to set default
# values for variables that are not really sensible.
# To use this rule, add a target to your gn file defining:
# protoc_proto_dir: The directory where the proto definition can be found.
# protoc_proto_def: Relative path to proto definition from |protoc_proto_dir|.
# protoc_message_name: The fully qualified name of the message contained in
# the protobuf.
# protoc_text_dir: The directory where the text format protobuf[s] can be found.
# protoc_bin_dir: The full path to the output directory. Note that this path is
# not relative to the <(SHARED_INTERMEDIATE_DIR). You must ensure that this
# directory is unique across all platform2 projects to avoid collisions. One
# way to do this is to include your project name in the directory path.
# Finally, specify the protobuf files in text format as the sources. These files
# should have a '.prototxt' file extension.
template("protoc_text_to_bin") {
action_name = "${target_name}_gen"
action_foreach(action_name) {
visibility = [ ":*" ]
forward_variables_from(invoker,
[
"protoc_bin_dir",
"protoc_message_name",
"protoc_proto_dir",
"protoc_proto_def",
"protoc_text_dir",
# Sources might be generated by actions in deps,
# which must be explicitly specified.
"deps",
])
protoc_proto_dir = rebase_path(protoc_proto_dir)
protoc_text_dir = rebase_path(protoc_text_dir)
sources = invoker.sources
script = "//common-mk/file_generator_wrapper.py"
args = [
"protoc",
"--proto_path",
"${protoc_proto_dir}",
"--encode",
"${protoc_message_name}",
"--protobuf_in",
"${protoc_text_dir}/{{source_file_part}}",
"--protobuf_out",
"${protoc_bin_dir}/{{source_name_part}}.pbf",
"${protoc_proto_dir}/${protoc_proto_def}",
]
outputs = [ "${protoc_bin_dir}/{{source_name_part}}.pbf" ]
}
source_set(target_name) {
forward_variables_from(invoker,
[
"defines",
"visibility",
])
if (defined(invoker.configs)) {
configs += invoker.configs
}
data = get_target_outputs(":${action_name}")
deps = [ ":${action_name}" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
}