| Index: third_party/protobuf/proto_library.gni
|
| diff --git a/third_party/protobuf/proto_library.gni b/third_party/protobuf/proto_library.gni
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..aaba76c90954cfbaf65c23608c0b8ad158d67294
|
| --- /dev/null
|
| +++ b/third_party/protobuf/proto_library.gni
|
| @@ -0,0 +1,125 @@
|
| +# Copyright 2014 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 protocol buffer.
|
| +#
|
| +# The 'proto_in_dir' variable must be the relative path to the
|
| +# directory containing the .proto files. If left out, it defaults to '.'.
|
| +#
|
| +# The 'proto_out_dir' variable specifies the path suffix that output files are
|
| +# generated under. Targets that gyp-depend on my_proto_lib will be able to
|
| +# include the resulting proto headers with an include like:
|
| +# #include "dir/for/my_proto_lib/foo.pb.h"
|
| +# If undefined, this defaults to matching the input directory.
|
| +#
|
| +# If you need to add an EXPORT macro to a protobuf's C++ header, set the
|
| +# 'cc_generator_options' variable with the value: 'dllexport_decl=FOO_EXPORT:'
|
| +# e.g. 'dllexport_decl=BASE_EXPORT:'
|
| +#
|
| +# It is likely you also need to #include a file for the above EXPORT macro to
|
| +# work. You can do so with the 'cc_include' variable.
|
| +# e.g. 'base/base_export.h'
|
| +#
|
| +# Example:
|
| +# proto_library("mylib") {
|
| +# sources = [
|
| +# "foo.proto",
|
| +# ]
|
| +# }
|
| +
|
| +template("proto_library") {
|
| + assert(defined(invoker.sources), "Need sources for proto_library")
|
| +
|
| + action_name = "${target_name}_gen"
|
| + source_set_name = target_name
|
| + action_foreach(action_name) {
|
| + visibility = ":$source_set_name"
|
| +
|
| + script = "//tools/protoc_wrapper/protoc_wrapper.py"
|
| +
|
| + sources = invoker.sources
|
| +
|
| + # TODO(brettw) it would be better if this used the target gen dir.
|
| + if (defined(invoker.proto_out_dir)) {
|
| + proto_out_dir = invoker.proto_out_dir
|
| + } else {
|
| + # This computes the relative path inside the target_gen_dir that
|
| + # we'd put the files in, which maps to the current directory path.
|
| + # We'll insert "protoc_out" at the beginning for compatibility with GYP.
|
| + proto_out_dir = rebase_path(target_gen_dir, root_gen_dir)
|
| + }
|
| + cc_dir = "$root_gen_dir/protoc_out/$proto_out_dir"
|
| + py_dir = "$root_gen_dir/pyproto/$proto_out_dir"
|
| +
|
| + outputs = [
|
| + "$py_dir/{{source_name_part}}_pb2.py",
|
| + "$cc_dir/{{source_name_part}}.pb.cc",
|
| + "$cc_dir/{{source_name_part}}.pb.h",
|
| + ]
|
| +
|
| + args = []
|
| + if (defined(invoker.cc_include)) {
|
| + args += [ "--include", invoker.cc_include ]
|
| + }
|
| +
|
| + args += [
|
| + "--protobuf",
|
| + rebase_path("$cc_dir/{{source_name_part}}.pb.h", root_build_dir),
|
| + ]
|
| +
|
| + if (defined(invoker.proto_in_dir)) {
|
| + proto_in_dir = invoker.proto_in_dir
|
| + } else {
|
| + # Extract the current source dir.
|
| + proto_in_dir = get_label_info(":$target_name", "dir")
|
| + }
|
| + args += [
|
| + "--proto-in-dir",
|
| + rebase_path(proto_in_dir, root_build_dir),
|
| + "--proto-in-file", "{{source_file_part}}",
|
| + # TODO(brettw) support system protobuf compiler.
|
| + "--use-system-protobuf=0",
|
| + ]
|
| +
|
| + protoc_label = "//third_party/protobuf:protoc($host_toolchain)"
|
| + args += [
|
| + "--",
|
| + # Prepend with "./" so this will never pick up the system one (normally
|
| + # when not cross-compiling, protoc's output directory will be the same
|
| + # as the build dir, so the relative location will be empty.
|
| + "./" + rebase_path(get_label_info(protoc_label, "root_out_dir") +
|
| + "/protoc", root_build_dir),
|
| + ]
|
| +
|
| + # If passed cc_generator_options should end in a colon, which will separate
|
| + # it from the directory when we concatenate them. The proto compiler
|
| + # understands this syntax.
|
| + if (defined(invoker.cc_generator_options)) {
|
| + cc_generator_options = invoker.cc_generator_options
|
| + } else {
|
| + cc_generator_options = ""
|
| + }
|
| + args += [
|
| + "--cpp_out", cc_generator_options + rebase_path(cc_dir, root_build_dir),
|
| + "--python_out", rebase_path(py_dir, root_build_dir),
|
| + ]
|
| +
|
| + deps = [ protoc_label ]
|
| + }
|
| +
|
| + source_set(target_name) {
|
| + if (defined(invoker.visibility)) {
|
| + visibility = invoker.visibility
|
| + }
|
| +
|
| + sources = get_target_outputs(":$action_name")
|
| +
|
| + direct_dependent_configs = [ "//third_party/protobuf:using_proto" ]
|
| +
|
| + deps = [
|
| + ":$action_name",
|
| + "//third_party/protobuf:protobuf_lite",
|
| + ]
|
| + }
|
| +}
|
|
|