Adds BUILD.gn file for protobufs.
This is a first cut of the BUILD.gn file. So far I have protoc
compiling successfully. I have not yet tried to use protoc
and so this may change in a later CL.
I haven't yet created a target that uses a compiled_action() to
trigger the build of protoc. For now I have created a target called
"protoc_host_build" that invokes the "protoc" target and
specifies the host toolchain. We may chose to remove this later.
I found I needed to edit a C++ file that is used during the build.
The file embed.cc generates a C++ file called
"well_known_types_embed.cc" that is used by protoc when generating
.js files. But embed.cc writes its generated output to std::cout
and the bazel file redirects std out to "well_known_types_embed.cc".
Wheras the Bazel file used a "genrule" I used a "compiled_action".
But compiled_action doesn't offer a way to redirect the std out from
the process being invoked so instead I changed the process to take
a flag specifying the output.
Change-Id: I21b07564ac1bbdaa4286e787debd003cc9f53917
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 0000000..427dfcf
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,533 @@
+# Copyright 2017 The Fuchsia Authors. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import("//build/compiled_action.gni")
+
+config("protobuf_config") {
+ include_dirs = [ "src" ]
+ defines = [
+ "GOOGLE_PROTOBUF_NO_RTTI",
+ "GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
+ "HAVE_PTHREAD",
+ ]
+}
+config("protobuf_warnings") {
+ cflags = []
+ if (is_clang) {
+ # protobuf-3 contains a few functions that are unused.
+ cflags += [ "-Wno-unused-function" ]
+ # Note(rudominer) I added these because there were a lot of warnings.
+ cflags += [ "-Wno-sign-compare",
+ "-Wno-missing-field-initializers" ]
+ }
+}
+
+executable("js_embed") {
+ sources = [
+ "src/google/protobuf/compiler/js/embed.cc",
+ ]
+}
+
+compiled_action("run_js_embed") {
+ tool = ":js_embed"
+
+ inputs = [
+ "src/google/protobuf/compiler/js/well_known_types/any.js",
+ "src/google/protobuf/compiler/js/well_known_types/struct.js",
+ "src/google/protobuf/compiler/js/well_known_types/timestamp.js",
+ ]
+
+ outputs = [
+ "$target_gen_dir/google/protobuf/compiler/js/well_known_types_embed.cc",
+ ]
+
+ args = [
+ "--output_file",
+ rebase_path("$target_gen_dir/google/protobuf/compiler/js/well_known_types_embed.cc", root_build_dir),
+ ] + rebase_path(inputs, root_build_dir)
+}
+
+# This config should be applied to targets using generated code from the proto
+# compiler. It sets up the include directories properly.
+config("using_proto") {
+ include_dirs = [
+ "src",
+ "$root_gen_dir",
+ ]
+}
+
+protobuf_lite_sources = [
+ "src/google/protobuf/arena.cc",
+ "src/google/protobuf/arena.h",
+ "src/google/protobuf/arenastring.cc",
+ "src/google/protobuf/arenastring.h",
+ "src/google/protobuf/extension_set.cc",
+ "src/google/protobuf/extension_set.h",
+ "src/google/protobuf/generated_message_util.cc",
+ "src/google/protobuf/generated_message_util.h",
+ "src/google/protobuf/io/coded_stream.cc",
+ "src/google/protobuf/io/coded_stream.h",
+ "src/google/protobuf/io/coded_stream_inl.h",
+ "src/google/protobuf/io/zero_copy_stream.cc",
+ "src/google/protobuf/io/zero_copy_stream.h",
+ "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
+ "src/google/protobuf/io/zero_copy_stream_impl_lite.h",
+ "src/google/protobuf/map.h",
+ "src/google/protobuf/map_entry_lite.h",
+ "src/google/protobuf/map_field_lite.h",
+ "src/google/protobuf/map_type_handler.h",
+ "src/google/protobuf/message_lite.cc",
+ "src/google/protobuf/message_lite.h",
+ "src/google/protobuf/repeated_field.cc",
+ "src/google/protobuf/repeated_field.h",
+ "src/google/protobuf/stubs/atomicops.h",
+ "src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h",
+ "src/google/protobuf/stubs/atomicops_internals_arm_gcc.h",
+ "src/google/protobuf/stubs/atomicops_internals_arm_qnx.h",
+ "src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h",
+ "src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h",
+ "src/google/protobuf/stubs/atomicops_internals_generic_gcc.h",
+ "src/google/protobuf/stubs/atomicops_internals_mips_gcc.h",
+ "src/google/protobuf/stubs/atomicops_internals_power.h",
+ "src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h",
+ "src/google/protobuf/stubs/atomicops_internals_solaris.h",
+ "src/google/protobuf/stubs/atomicops_internals_tsan.h",
+ "src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
+ "src/google/protobuf/stubs/atomicops_internals_x86_gcc.h",
+ "src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc",
+ "src/google/protobuf/stubs/atomicops_internals_x86_msvc.h",
+ "src/google/protobuf/stubs/atomic_sequence_num.h",
+ "src/google/protobuf/stubs/bytestream.cc",
+ "src/google/protobuf/stubs/bytestream.h",
+ "src/google/protobuf/stubs/callback.h",
+ "src/google/protobuf/stubs/casts.h",
+ "src/google/protobuf/stubs/common.cc",
+ "src/google/protobuf/stubs/common.h",
+ "src/google/protobuf/stubs/fastmem.h",
+ "src/google/protobuf/stubs/hash.h",
+ "src/google/protobuf/stubs/int128.cc",
+ "src/google/protobuf/stubs/int128.h",
+ "src/google/protobuf/stubs/logging.h",
+ "src/google/protobuf/stubs/macros.h",
+ "src/google/protobuf/stubs/map_util.h",
+ "src/google/protobuf/stubs/mutex.h",
+ "src/google/protobuf/stubs/once.cc",
+ "src/google/protobuf/stubs/once.h",
+ "src/google/protobuf/stubs/platform_macros.h",
+ "src/google/protobuf/stubs/port.h",
+ "src/google/protobuf/stubs/scoped_ptr.h",
+ "src/google/protobuf/stubs/shared_ptr.h",
+ "src/google/protobuf/stubs/status.cc",
+ "src/google/protobuf/stubs/status.h",
+ "src/google/protobuf/stubs/status_macros.h",
+ "src/google/protobuf/stubs/statusor.cc",
+ "src/google/protobuf/stubs/statusor.h",
+ "src/google/protobuf/stubs/stl_util.h",
+ "src/google/protobuf/stubs/stringpiece.cc",
+ "src/google/protobuf/stubs/stringpiece.h",
+ "src/google/protobuf/stubs/stringprintf.cc",
+ "src/google/protobuf/stubs/stringprintf.h",
+ "src/google/protobuf/stubs/structurally_valid.cc",
+ "src/google/protobuf/stubs/strutil.cc",
+ "src/google/protobuf/stubs/strutil.h",
+ "src/google/protobuf/stubs/template_util.h",
+ "src/google/protobuf/stubs/type_traits.h",
+ "src/google/protobuf/stubs/time.cc",
+ "src/google/protobuf/stubs/time.h",
+ "src/google/protobuf/wire_format_lite.cc",
+ "src/google/protobuf/wire_format_lite.h",
+ "src/google/protobuf/wire_format_lite_inl.h",
+]
+
+static_library("protobuf_lite") {
+ sources = protobuf_lite_sources
+ configs += [
+ ":protobuf_warnings",
+ ]
+ public_configs = [
+ ":protobuf_config",
+ ]
+ cflags = []
+}
+
+# This is the full, heavy protobuf lib that's needed for c++ .protos that don't
+# specify the LITE_RUNTIME option. The protocol compiler itself (protoc) falls
+# into that category.
+static_library("protobuf_full") {
+ # Prevent people from depending on this outside our file.
+ visibility = [
+ ":*",
+ ]
+ sources = protobuf_lite_sources + [
+ "src/google/protobuf/any.cc",
+ "src/google/protobuf/any.h",
+ "src/google/protobuf/any.pb.cc",
+ "src/google/protobuf/any.pb.h",
+ "src/google/protobuf/api.pb.cc",
+ "src/google/protobuf/api.pb.h",
+ "src/google/protobuf/compiler/importer.cc",
+ "src/google/protobuf/compiler/importer.h",
+ "src/google/protobuf/compiler/parser.cc",
+ "src/google/protobuf/compiler/parser.h",
+ "src/google/protobuf/descriptor.cc",
+ "src/google/protobuf/descriptor.h",
+ "src/google/protobuf/descriptor.pb.cc",
+ "src/google/protobuf/descriptor.pb.h",
+ "src/google/protobuf/descriptor_database.cc",
+ "src/google/protobuf/descriptor_database.h",
+ "src/google/protobuf/duration.pb.cc",
+ "src/google/protobuf/duration.pb.h",
+ "src/google/protobuf/dynamic_message.cc",
+ "src/google/protobuf/dynamic_message.h",
+ "src/google/protobuf/empty.pb.cc",
+ "src/google/protobuf/empty.pb.h",
+ "src/google/protobuf/extension_set_heavy.cc",
+ "src/google/protobuf/field_mask.pb.cc",
+ "src/google/protobuf/field_mask.pb.h",
+ "src/google/protobuf/generated_enum_reflection.h",
+ "src/google/protobuf/generated_enum_util.h",
+ "src/google/protobuf/generated_message_reflection.cc",
+ "src/google/protobuf/generated_message_reflection.h",
+ # gzip_stream.cc pulls in zlib, but it's not actually used by protoc, just
+ # by test code, so instead of compiling zlib for the host, let's just
+ # exclude this.
+ # "src/google/protobuf/io/gzip_stream.cc",
+ # "src/google/protobuf/io/gzip_stream.h",
+ "src/google/protobuf/io/printer.cc",
+ "src/google/protobuf/io/printer.h",
+ "src/google/protobuf/io/strtod.cc",
+ "src/google/protobuf/io/strtod.h",
+ "src/google/protobuf/io/tokenizer.cc",
+ "src/google/protobuf/io/tokenizer.h",
+ "src/google/protobuf/io/zero_copy_stream_impl.cc",
+ "src/google/protobuf/io/zero_copy_stream_impl.h",
+ "src/google/protobuf/map_entry.h",
+ "src/google/protobuf/map_field.cc",
+ "src/google/protobuf/map_field.h",
+ "src/google/protobuf/map_field_inl.h",
+ "src/google/protobuf/message.cc",
+ "src/google/protobuf/message.h",
+ "src/google/protobuf/metadata.h",
+ "src/google/protobuf/reflection.h",
+ "src/google/protobuf/reflection_internal.h",
+ "src/google/protobuf/reflection_ops.cc",
+ "src/google/protobuf/reflection_ops.h",
+ "src/google/protobuf/service.cc",
+ "src/google/protobuf/service.h",
+ "src/google/protobuf/source_context.pb.cc",
+ "src/google/protobuf/source_context.pb.h",
+ "src/google/protobuf/struct.pb.cc",
+ "src/google/protobuf/struct.pb.h",
+ "src/google/protobuf/stubs/mathlimits.cc",
+ "src/google/protobuf/stubs/mathlimits.h",
+ "src/google/protobuf/stubs/mathutil.h",
+ "src/google/protobuf/stubs/singleton.h",
+ "src/google/protobuf/stubs/substitute.cc",
+ "src/google/protobuf/stubs/substitute.h",
+ "src/google/protobuf/text_format.cc",
+ "src/google/protobuf/text_format.h",
+ "src/google/protobuf/timestamp.pb.cc",
+ "src/google/protobuf/timestamp.pb.h",
+ "src/google/protobuf/type.pb.cc",
+ "src/google/protobuf/type.pb.h",
+ "src/google/protobuf/unknown_field_set.cc",
+ "src/google/protobuf/unknown_field_set.h",
+ "src/google/protobuf/util/field_comparator.cc",
+ "src/google/protobuf/util/field_comparator.h",
+ "src/google/protobuf/util/field_mask_util.cc",
+ "src/google/protobuf/util/field_mask_util.h",
+ "src/google/protobuf/util/internal/constants.h",
+ "src/google/protobuf/util/internal/datapiece.cc",
+ "src/google/protobuf/util/internal/datapiece.h",
+ "src/google/protobuf/util/internal/default_value_objectwriter.cc",
+ "src/google/protobuf/util/internal/default_value_objectwriter.h",
+ "src/google/protobuf/util/internal/error_listener.cc",
+ "src/google/protobuf/util/internal/error_listener.h",
+ "src/google/protobuf/util/internal/field_mask_utility.cc",
+ "src/google/protobuf/util/internal/field_mask_utility.h",
+ "src/google/protobuf/util/internal/json_escaping.cc",
+ "src/google/protobuf/util/internal/json_escaping.h",
+ "src/google/protobuf/util/internal/json_objectwriter.cc",
+ "src/google/protobuf/util/internal/json_objectwriter.h",
+ "src/google/protobuf/util/internal/json_stream_parser.cc",
+ "src/google/protobuf/util/internal/json_stream_parser.h",
+ "src/google/protobuf/util/internal/location_tracker.h",
+ "src/google/protobuf/util/internal/object_location_tracker.h",
+ "src/google/protobuf/util/internal/object_source.h",
+ "src/google/protobuf/util/internal/object_writer.cc",
+ "src/google/protobuf/util/internal/object_writer.h",
+ "src/google/protobuf/util/internal/proto_writer.cc",
+ "src/google/protobuf/util/internal/proto_writer.h",
+ "src/google/protobuf/util/internal/protostream_objectsource.cc",
+ "src/google/protobuf/util/internal/protostream_objectsource.h",
+ "src/google/protobuf/util/internal/protostream_objectwriter.cc",
+ "src/google/protobuf/util/internal/protostream_objectwriter.h",
+ "src/google/protobuf/util/internal/structured_objectwriter.h",
+ "src/google/protobuf/util/internal/type_info.cc",
+ "src/google/protobuf/util/internal/type_info.h",
+ "src/google/protobuf/util/internal/type_info_test_helper.cc",
+ "src/google/protobuf/util/internal/type_info_test_helper.h",
+ "src/google/protobuf/util/internal/utility.cc",
+ "src/google/protobuf/util/internal/utility.h",
+ "src/google/protobuf/util/json_util.cc",
+ "src/google/protobuf/util/json_util.h",
+ "src/google/protobuf/util/message_differencer.cc",
+ "src/google/protobuf/util/message_differencer.h",
+ "src/google/protobuf/util/time_util.cc",
+ "src/google/protobuf/util/time_util.h",
+ "src/google/protobuf/util/type_resolver.h",
+ "src/google/protobuf/util/type_resolver_util.cc",
+ "src/google/protobuf/util/type_resolver_util.h",
+ "src/google/protobuf/wire_format.cc",
+ "src/google/protobuf/wire_format.h",
+ "src/google/protobuf/wrappers.pb.cc",
+ "src/google/protobuf/wrappers.pb.h",
+ ]
+ configs += [
+ ":protobuf_warnings",
+ ]
+ public_configs = [
+ ":protobuf_config",
+ ]
+ cflags = []
+}
+
+# Only compile the compiler for the host architecture.
+if (current_toolchain == host_toolchain) {
+ # protoc compiler is separated into protoc library and executable targets to
+ # support protoc plugins that need to link libprotoc, but not the main()
+ # itself. See src/google/protobuf/compiler/plugin.h
+ static_library("protoc_lib") {
+ sources = [
+ "src/google/protobuf/compiler/code_generator.cc",
+ "src/google/protobuf/compiler/code_generator.h",
+ "src/google/protobuf/compiler/command_line_interface.cc",
+ "src/google/protobuf/compiler/command_line_interface.h",
+ "src/google/protobuf/compiler/cpp/cpp_enum.cc",
+ "src/google/protobuf/compiler/cpp/cpp_enum.h",
+ "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_enum_field.h",
+ "src/google/protobuf/compiler/cpp/cpp_extension.cc",
+ "src/google/protobuf/compiler/cpp/cpp_extension.h",
+ "src/google/protobuf/compiler/cpp/cpp_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_field.h",
+ "src/google/protobuf/compiler/cpp/cpp_file.cc",
+ "src/google/protobuf/compiler/cpp/cpp_file.h",
+ "src/google/protobuf/compiler/cpp/cpp_generator.cc",
+ "src/google/protobuf/compiler/cpp/cpp_generator.h",
+ "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
+ "src/google/protobuf/compiler/cpp/cpp_helpers.h",
+ "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_map_field.h",
+ "src/google/protobuf/compiler/cpp/cpp_message.cc",
+ "src/google/protobuf/compiler/cpp/cpp_message.h",
+ "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_message_field.h",
+ "src/google/protobuf/compiler/cpp/cpp_options.h",
+ "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_primitive_field.h",
+ "src/google/protobuf/compiler/cpp/cpp_service.cc",
+ "src/google/protobuf/compiler/cpp/cpp_service.h",
+ "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_string_field.h",
+ "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
+ "src/google/protobuf/compiler/csharp/csharp_doc_comment.h",
+ "src/google/protobuf/compiler/csharp/csharp_enum.cc",
+ "src/google/protobuf/compiler/csharp/csharp_enum.h",
+ "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_enum_field.h",
+ "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
+ "src/google/protobuf/compiler/csharp/csharp_field_base.h",
+ "src/google/protobuf/compiler/csharp/csharp_generator.cc",
+ "src/google/protobuf/compiler/csharp/csharp_generator.h",
+ "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
+ "src/google/protobuf/compiler/csharp/csharp_helpers.h",
+ "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_map_field.h",
+ "src/google/protobuf/compiler/csharp/csharp_message.cc",
+ "src/google/protobuf/compiler/csharp/csharp_message.h",
+ "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_message_field.h",
+ "src/google/protobuf/compiler/csharp/csharp_options.h",
+ "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_primitive_field.h",
+ "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
+ "src/google/protobuf/compiler/csharp/csharp_reflection_class.h",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h",
+ "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
+ "src/google/protobuf/compiler/csharp/csharp_source_generator_base.h",
+ "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_wrapper_field.h",
+ "src/google/protobuf/compiler/java/java_context.cc",
+ "src/google/protobuf/compiler/java/java_context.h",
+ "src/google/protobuf/compiler/java/java_doc_comment.cc",
+ "src/google/protobuf/compiler/java/java_doc_comment.h",
+ "src/google/protobuf/compiler/java/java_enum.cc",
+ "src/google/protobuf/compiler/java/java_enum.h",
+ "src/google/protobuf/compiler/java/java_enum_field.cc",
+ "src/google/protobuf/compiler/java/java_enum_field.h",
+ "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_enum_field_lite.h",
+ "src/google/protobuf/compiler/java/java_enum_lite.cc",
+ "src/google/protobuf/compiler/java/java_enum_lite.h",
+ "src/google/protobuf/compiler/java/java_extension.cc",
+ "src/google/protobuf/compiler/java/java_extension.h",
+ "src/google/protobuf/compiler/java/java_extension_lite.cc",
+ "src/google/protobuf/compiler/java/java_extension_lite.h",
+ "src/google/protobuf/compiler/java/java_field.cc",
+ "src/google/protobuf/compiler/java/java_field.h",
+ "src/google/protobuf/compiler/java/java_file.cc",
+ "src/google/protobuf/compiler/java/java_file.h",
+ "src/google/protobuf/compiler/java/java_generator.cc",
+ "src/google/protobuf/compiler/java/java_generator.h",
+ "src/google/protobuf/compiler/java/java_generator_factory.cc",
+ "src/google/protobuf/compiler/java/java_generator_factory.h",
+ "src/google/protobuf/compiler/java/java_helpers.cc",
+ "src/google/protobuf/compiler/java/java_helpers.h",
+ "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
+ "src/google/protobuf/compiler/java/java_lazy_message_field.h",
+ "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_lazy_message_field_lite.h",
+ "src/google/protobuf/compiler/java/java_map_field.cc",
+ "src/google/protobuf/compiler/java/java_map_field.h",
+ "src/google/protobuf/compiler/java/java_map_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_map_field_lite.h",
+ "src/google/protobuf/compiler/java/java_message.cc",
+ "src/google/protobuf/compiler/java/java_message.h",
+ "src/google/protobuf/compiler/java/java_message_builder.cc",
+ "src/google/protobuf/compiler/java/java_message_builder.h",
+ "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
+ "src/google/protobuf/compiler/java/java_message_builder_lite.h",
+ "src/google/protobuf/compiler/java/java_message_field.cc",
+ "src/google/protobuf/compiler/java/java_message_field.h",
+ "src/google/protobuf/compiler/java/java_message_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_message_field_lite.h",
+ "src/google/protobuf/compiler/java/java_message_lite.cc",
+ "src/google/protobuf/compiler/java/java_message_lite.h",
+ "src/google/protobuf/compiler/java/java_name_resolver.cc",
+ "src/google/protobuf/compiler/java/java_name_resolver.h",
+ "src/google/protobuf/compiler/java/java_primitive_field.cc",
+ "src/google/protobuf/compiler/java/java_primitive_field.h",
+ "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_primitive_field_lite.h",
+ "src/google/protobuf/compiler/java/java_service.cc",
+ "src/google/protobuf/compiler/java/java_service.h",
+ "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
+ "src/google/protobuf/compiler/java/java_shared_code_generator.h",
+ "src/google/protobuf/compiler/java/java_string_field.cc",
+ "src/google/protobuf/compiler/java/java_string_field.h",
+ "src/google/protobuf/compiler/java/java_string_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_string_field_lite.h",
+ "src/google/protobuf/compiler/javanano/javanano_enum.cc",
+ "src/google/protobuf/compiler/javanano/javanano_enum.h",
+ "src/google/protobuf/compiler/javanano/javanano_enum_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_enum_field.h",
+ "src/google/protobuf/compiler/javanano/javanano_extension.cc",
+ "src/google/protobuf/compiler/javanano/javanano_extension.h",
+ "src/google/protobuf/compiler/javanano/javanano_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_field.h",
+ "src/google/protobuf/compiler/javanano/javanano_file.cc",
+ "src/google/protobuf/compiler/javanano/javanano_file.h",
+ "src/google/protobuf/compiler/javanano/javanano_generator.cc",
+ "src/google/protobuf/compiler/javanano/javanano_generator.h",
+ "src/google/protobuf/compiler/javanano/javanano_helpers.cc",
+ "src/google/protobuf/compiler/javanano/javanano_helpers.h",
+ "src/google/protobuf/compiler/javanano/javanano_map_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_map_field.h",
+ "src/google/protobuf/compiler/javanano/javanano_message.cc",
+ "src/google/protobuf/compiler/javanano/javanano_message.h",
+ "src/google/protobuf/compiler/javanano/javanano_message_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_message_field.h",
+ "src/google/protobuf/compiler/javanano/javanano_primitive_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_primitive_field.h",
+ "src/google/protobuf/compiler/js/js_generator.cc",
+ "src/google/protobuf/compiler/js/js_generator.h",
+ "$target_gen_dir/google/protobuf/compiler/js/well_known_types_embed.cc",
+ "src//google/protobuf/compiler/js/well_known_types_embed.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_enum.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_enum_field.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_extension.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_field.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_file.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_generator.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_helpers.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_map_field.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_message.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_message_field.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_oneof.h",
+ "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h",
+ "src/google/protobuf/compiler/php/php_generator.cc",
+ "src/google/protobuf/compiler/php/php_generator.h",
+ "src/google/protobuf/compiler/plugin.cc",
+ "src/google/protobuf/compiler/plugin.h",
+ "src/google/protobuf/compiler/plugin.pb.cc",
+ "src/google/protobuf/compiler/plugin.pb.h",
+ "src/google/protobuf/compiler/python/python_generator.cc",
+ "src/google/protobuf/compiler/python/python_generator.h",
+ "src/google/protobuf/compiler/ruby/ruby_generator.cc",
+ "src/google/protobuf/compiler/ruby/ruby_generator.h",
+ "src/google/protobuf/compiler/subprocess.cc",
+ "src/google/protobuf/compiler/subprocess.h",
+ "src/google/protobuf/compiler/zip_writer.cc",
+ "src/google/protobuf/compiler/zip_writer.h",
+ ]
+ configs += [
+ ":protobuf_warnings",
+ ]
+ public_deps = [
+ ":protobuf_full",
+ ":run_js_embed",
+ ]
+ }
+
+ executable("protoc") {
+ sources = [
+ "src/google/protobuf/compiler/main.cc",
+ ]
+ deps = [
+ ":protoc_lib",
+ ]
+ }
+}
diff --git a/proto_library.gni b/proto_library.gni
new file mode 100644
index 0000000..79896d7
--- /dev/null
+++ b/proto_library.gni
@@ -0,0 +1,367 @@
+# 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.
+#
+# Protobuf parameters:
+#
+# proto_in_dir (optional)
+# Specifies the path relative to the current BUILD.gn file where
+# proto files are located and the directory structure of
+# this proto library starts.
+#
+# This option can be calculated automatically but it will raise an
+# assertion error if any nested directories are found.
+#
+# proto_out_dir (optional)
+# Specifies the path suffix that output files are generated under.
+# This path will be appended to |root_gen_dir|, but for python stubs
+# it will be appended to |root_build_dir|/pyproto.
+#
+# generate_python (optional, default true)
+# Generate Python protobuf stubs.
+#
+# generate_cc (optional, default true)
+# Generate C++ protobuf stubs.
+#
+# cc_generator_options (optional)
+# List of extra flags passed to the protocol compiler. 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:' (note trailing colon).
+#
+# It is likely you also need to #include a file for the above EXPORT
+# macro to work (see cc_include) and set
+# component_build_force_source_set = true.
+#
+# cc_include (optional)
+# String listing an extra include that should be passed.
+# Example: cc_include = "foo/bar.h"
+#
+# generator_plugin_label (optional)
+# GN label for plugin executable which generates custom cc stubs.
+# Don't specify a toolchain, host toolchain is assumed.
+#
+# generator_plugin_script (optional)
+# Path to plugin script. Mutually exclusive with |generator_plugin_label|.
+#
+# generator_plugin_script_deps (optional)
+# List of additional files required for generator plugin script.
+#
+# generator_plugin_suffix[es] (required if using a plugin)
+# Suffix (before extension) for generated .cc and .h files
+# or list of suffixes for all files (with extensions).
+#
+# generator_plugin_options (optional)
+# Extra flags passed to the plugin. See cc_generator_options.
+#
+# deps (optional)
+# Additional dependencies.
+#
+# use_protobuf_full (optional)
+# If adding protobuf library would be required, adds protobuf_full to deps
+# instead of protobuf_lite.
+#
+# import_dirs (optional)
+# A list of extra import directories to be passed to protoc compiler. The
+# default case is just proto_in_dir.
+# WARNING: This options should not be used in Chrome code until
+# http://crbug.com/691451 is resolved.
+#
+# Parameters for compiling the generated code:
+#
+# defines (optional)
+# Defines to supply to the source set that compiles the generated source
+# code.
+#
+# extra_configs (optional)
+# A list of config labels that will be appended to the configs applying
+# to the source set.
+#
+# Example:
+# proto_library("mylib") {
+# sources = [
+# "foo.proto",
+# ]
+# }
+
+template("proto_library") {
+ assert(defined(invoker.sources), "Need sources for proto_library")
+ proto_sources = invoker.sources
+
+ # 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([])
+
+ if (defined(invoker.generate_cc)) {
+ generate_cc = invoker.generate_cc
+ } else {
+ generate_cc = true
+ }
+
+ if (defined(invoker.generate_python)) {
+ generate_python = invoker.generate_python
+ } else {
+ generate_python = true
+ }
+
+ if (defined(invoker.generator_plugin_label)) {
+ # Straightforward way to get the name of executable doesn't work because
+ # |root_out_dir| and |root_build_dir| may differ in cross-compilation and
+ # also Windows executables have .exe at the end.
+
+ plugin_host_label = invoker.generator_plugin_label + "($host_toolchain)"
+ plugin_path =
+ get_label_info(plugin_host_label, "root_out_dir") + "/" +
+ get_label_info(plugin_host_label, "name") + host_executable_suffix
+ generate_with_plugin = true
+ } else if (defined(invoker.generator_plugin_script)) {
+ plugin_path = invoker.generator_plugin_script
+ generate_with_plugin = true
+ } else {
+ generate_with_plugin = false
+ }
+
+ if (generate_with_plugin) {
+ if (defined(invoker.generator_plugin_suffix)) {
+ generator_plugin_suffixes = [
+ "${invoker.generator_plugin_suffix}.h",
+ "${invoker.generator_plugin_suffix}.cc",
+ ]
+ } else {
+ generator_plugin_suffixes = invoker.generator_plugin_suffixes
+ }
+ }
+
+ if (defined(invoker.proto_in_dir)) {
+ proto_in_dir = invoker.proto_in_dir
+ has_nested_dirs = false
+ foreach(proto_source, proto_sources) {
+ if (get_path_info(proto_source, "dir") != proto_in_dir) {
+ has_nested_dirs = true
+ }
+ }
+ } else {
+ proto_in_dir = get_path_info(proto_sources[0], "dir")
+ has_nested_dirs = false
+
+ # Sanity check, |proto_in_dir| should be defined to allow sub-directories.
+ foreach(proto_source, proto_sources) {
+ assert(get_path_info(proto_source, "dir") == proto_in_dir,
+ "Please define |proto_in_dir| to allow nested directories.")
+ }
+ }
+
+ # Avoid absolute path because of the assumption that |proto_in_dir| is
+ # relative to the directory of current BUILD.gn file.
+ proto_in_dir = rebase_path(proto_in_dir, ".")
+
+ if (defined(invoker.proto_out_dir)) {
+ proto_out_dir = invoker.proto_out_dir
+ } else {
+ # Absolute path to the directory of current BUILD.gn file excluding "//".
+ proto_out_dir = rebase_path(".", "//")
+ if (proto_in_dir != ".") {
+ proto_out_dir += "/$proto_in_dir"
+ }
+ }
+
+ # We need both absolute path to use in GN statements and a relative one
+ # to pass to external script.
+ if (generate_cc || generate_with_plugin) {
+ cc_out_dir = "$root_gen_dir/" + proto_out_dir
+ rel_cc_out_dir = rebase_path(cc_out_dir, root_build_dir)
+ }
+ if (generate_python) {
+ py_out_dir = "$root_out_dir/pyproto/" + proto_out_dir
+ rel_py_out_dir = rebase_path(py_out_dir, root_build_dir)
+ }
+
+ protos = rebase_path(invoker.sources, proto_in_dir)
+ protogens = []
+
+ # List output files.
+ foreach(proto, protos) {
+ proto_dir = get_path_info(proto, "dir")
+ proto_name = get_path_info(proto, "name")
+ proto_path = proto_dir + "/" + proto_name
+
+ if (generate_cc) {
+ protogens += [
+ "$cc_out_dir/$proto_path.pb.h",
+ "$cc_out_dir/$proto_path.pb.cc",
+ ]
+ }
+ if (generate_python) {
+ protogens += [ "$py_out_dir/${proto_path}_pb2.py" ]
+ }
+ if (generate_with_plugin) {
+ foreach(suffix, generator_plugin_suffixes) {
+ protogens += [ "$cc_out_dir/${proto_path}${suffix}" ]
+ }
+ }
+ }
+
+ action_name = "${target_name}_gen"
+ source_set_name = target_name
+
+ # Generate protobuf stubs.
+ action(action_name) {
+ visibility = [ ":$source_set_name" ]
+ script = "//third_party/protobuf/protoc_wrapper.py"
+ sources = proto_sources
+ outputs = get_path_info(protogens, "abspath")
+ args = protos
+
+ protoc_label = "//third_party/protobuf:protoc($host_toolchain)"
+ protoc_path = get_label_info(protoc_label, "root_out_dir") + "/protoc" +
+ host_executable_suffix
+ args += [
+ # Wrapper should never pick a system protoc.
+ # Path should be rebased because |root_build_dir| for current toolchain
+ # may be different from |root_out_dir| of protoc built on host toolchain.
+ "--protoc",
+ "./" + rebase_path(protoc_path, root_build_dir),
+ "--proto-in-dir",
+ rebase_path(proto_in_dir, root_build_dir),
+ ]
+
+ if (generate_cc) {
+ args += [
+ "--cc-out-dir",
+ rel_cc_out_dir,
+ ]
+ if (defined(invoker.cc_generator_options)) {
+ args += [
+ "--cc-options",
+ invoker.cc_generator_options,
+ ]
+ }
+ if (defined(invoker.cc_include)) {
+ args += [
+ "--include",
+ invoker.cc_include,
+ ]
+ }
+ }
+
+ if (generate_python) {
+ args += [
+ "--py-out-dir",
+ rel_py_out_dir,
+ ]
+ }
+
+ if (generate_with_plugin) {
+ args += [
+ "--plugin",
+ rebase_path(plugin_path, root_build_dir),
+ "--plugin-out-dir",
+ rel_cc_out_dir,
+ ]
+ if (defined(invoker.generator_plugin_options)) {
+ args += [
+ "--plugin-options",
+ invoker.generator_plugin_options,
+ ]
+ }
+ }
+
+ if (defined(invoker.import_dirs)) {
+ foreach(path, invoker.import_dirs) {
+ args += [ "--import-dir=" + rebase_path(path, root_build_dir) ]
+ }
+ }
+
+ # System protoc is not used so it's necessary to build one.
+ inputs = [
+ protoc_path,
+ ]
+ deps = [
+ protoc_label,
+ ]
+
+ if (generate_with_plugin) {
+ inputs += [ plugin_path ]
+ if (defined(invoker.generator_plugin_script_deps)) {
+ # Additional scripts for plugin.
+ inputs += invoker.generator_plugin_script_deps
+ }
+ if (defined(plugin_host_label)) {
+ # Action depends on native generator plugin but for host toolchain only.
+ deps += [ plugin_host_label ]
+ }
+ }
+
+ if (defined(invoker.deps)) {
+ # The deps may have steps that have to run before running protoc.
+ deps += invoker.deps
+ }
+ }
+
+ # Option to disable building a library in component build.
+ if (defined(invoker.component_build_force_source_set) &&
+ invoker.component_build_force_source_set && is_component_build) {
+ link_target_type = "source_set"
+ } else {
+
+ }
+
+ # Build generated protobuf stubs as static libary.
+ static_library(target_name) {
+ forward_variables_from(invoker,
+ [
+ "defines",
+ "testonly",
+ "visibility",
+ ])
+
+ sources = get_target_outputs(":$action_name")
+
+ if (defined(invoker.extra_configs)) {
+ configs += invoker.extra_configs
+ }
+
+ configs += ["//third_party/protobuf:protobuf_warnings"]
+ public_configs = [ "//third_party/protobuf:using_proto" ]
+
+ if (generate_cc || generate_with_plugin) {
+ # Not necessary if all protos are located in the same directory.
+ if (has_nested_dirs) {
+ # It's not enough to set |include_dirs| for target since public imports
+ # expose corresponding includes to header files as well.
+ public_configs += [ ":$config_name" ]
+ }
+
+ # If using built-in cc generator, the resulting headers reference headers
+ # within protobuf_lite. Hence, dependencies require those headers too.
+ # If using generator plugin, extra deps should be resolved by the invoker.
+ if (generate_cc) {
+ if (defined(invoker.use_protobuf_full) &&
+ invoker.use_protobuf_full == true) {
+ public_deps = [
+ "//third_party/protobuf:protobuf_full",
+ ]
+ } else {
+ public_deps = [
+ "//third_party/protobuf:protobuf_lite",
+ ]
+ }
+
+ }
+ }
+
+ deps = [
+ ":$action_name",
+ ]
+
+ # This will link any libraries in the deps (the use of invoker.deps in the
+ # action won't link it).
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+ }
+}
diff --git a/protoc_wrapper.py b/protoc_wrapper.py
new file mode 100755
index 0000000..d969e7e
--- /dev/null
+++ b/protoc_wrapper.py
@@ -0,0 +1,143 @@
+#!/usr/bin/env python
+# Copyright 2012 Google Inc. All Rights Reserved.
+
+"""
+A simple wrapper for protoc.
+Script for //third_party/protobuf/proto_library.gni .
+Features:
+- Inserts #include for extra header automatically.
+- Prevents bad proto names.
+"""
+
+from __future__ import print_function
+import argparse
+import os.path
+import subprocess
+import sys
+import tempfile
+
+PROTOC_INCLUDE_POINT = "// @@protoc_insertion_point(includes)"
+
+
+def FormatGeneratorOptions(options):
+ if not options:
+ return ""
+ if options.endswith(":"):
+ return options
+ return options + ":"
+
+
+def VerifyProtoNames(protos):
+ for filename in protos:
+ if "-" in filename:
+ raise RuntimeError("Proto file names must not contain hyphens "
+ "(see http://crbug.com/386125 for more information).")
+
+
+def StripProtoExtension(filename):
+ if not filename.endswith(".proto"):
+ raise RuntimeError("Invalid proto filename extension: "
+ "{0} .".format(filename))
+ return filename.rsplit(".", 1)[0]
+
+
+def WriteIncludes(headers, include):
+ for filename in headers:
+ include_point_found = False
+ contents = []
+ with open(filename) as f:
+ for line in f:
+ stripped_line = line.strip()
+ contents.append(stripped_line)
+ if stripped_line == PROTOC_INCLUDE_POINT:
+ if include_point_found:
+ raise RuntimeException("Multiple include points found.")
+ include_point_found = True
+ extra_statement = "#include \"{0}\"".format(include)
+ contents.append(extra_statement)
+
+ if not include_point_found:
+ raise RuntimeError("Include point not found in header: "
+ "{0} .".format(filename))
+
+ with open(filename, "w") as f:
+ for line in contents:
+ print(line, file=f)
+
+
+def main(argv):
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--protoc",
+ help="Relative path to compiler.")
+
+ parser.add_argument("--proto-in-dir",
+ help="Base directory with source protos.")
+ parser.add_argument("--cc-out-dir",
+ help="Output directory for standard C++ generator.")
+ parser.add_argument("--py-out-dir",
+ help="Output directory for standard Python generator.")
+ parser.add_argument("--plugin-out-dir",
+ help="Output directory for custom generator plugin.")
+
+ parser.add_argument("--plugin",
+ help="Relative path to custom generator plugin.")
+ parser.add_argument("--plugin-options",
+ help="Custom generator plugin options.")
+ parser.add_argument("--cc-options",
+ help="Standard C++ generator options.")
+ parser.add_argument("--include",
+ help="Name of include to insert into generated headers.")
+ parser.add_argument("--import-dir", action="append", default=[],
+ help="Extra import directory for protos, can be repeated."
+ )
+ parser.add_argument("protos", nargs="+",
+ help="Input protobuf definition file(s).")
+
+ options = parser.parse_args()
+
+ proto_dir = os.path.relpath(options.proto_in_dir)
+ protoc_cmd = [os.path.realpath(options.protoc)]
+
+ protos = options.protos
+ headers = []
+ VerifyProtoNames(protos)
+
+ if options.py_out_dir:
+ protoc_cmd += ["--python_out", options.py_out_dir]
+
+ if options.cc_out_dir:
+ cc_out_dir = options.cc_out_dir
+ cc_options = FormatGeneratorOptions(options.cc_options)
+ protoc_cmd += ["--cpp_out", cc_options + cc_out_dir]
+ for filename in protos:
+ stripped_name = StripProtoExtension(filename)
+ headers.append(os.path.join(cc_out_dir, stripped_name + ".pb.h"))
+
+ if options.plugin_out_dir:
+ plugin_options = FormatGeneratorOptions(options.plugin_options)
+ protoc_cmd += [
+ "--plugin", "protoc-gen-plugin=" + os.path.relpath(options.plugin),
+ "--plugin_out", plugin_options + options.plugin_out_dir
+ ]
+
+ protoc_cmd += ["--proto_path", proto_dir]
+ for path in options.import_dir:
+ protoc_cmd += ["--proto_path", path]
+
+ protoc_cmd += [os.path.join(proto_dir, name) for name in protos]
+
+ ret = subprocess.call(protoc_cmd)
+ if ret != 0:
+ raise RuntimeError("Protoc has returned non-zero status: "
+ "{0} .".format(ret))
+
+ if options.include:
+ WriteIncludes(headers, options.include)
+
+
+if __name__ == "__main__":
+ try:
+ main(sys.argv)
+ except RuntimeError as e:
+ print(e, file=sys.stderr)
+ sys.exit(1)
diff --git a/src/google/protobuf/compiler/js/embed.cc b/src/google/protobuf/compiler/js/embed.cc
index a725b62..c732c18 100644
--- a/src/google/protobuf/compiler/js/embed.cc
+++ b/src/google/protobuf/compiler/js/embed.cc
@@ -34,8 +34,6 @@
#include <iostream>
#include <string>
-const char output_file[] = "well_known_types_embed.cc";
-
static bool AsciiIsPrint(unsigned char c) {
return c >= 32 && c < 127;
}
@@ -96,17 +94,45 @@
*out << "},\n";
}
-int main(int argc, char *argv[]) {
- std::cout << "#include "
- "\"google/protobuf/compiler/js/well_known_types_embed.h\"\n";
- std::cout << "struct FileToc well_known_types_js[] = {\n";
+static void WriteOutput(char* file_names[], int num_file_names,
+ std::ostream* out) {
+ *out << "#include "
+ "\"google/protobuf/compiler/js/well_known_types_embed.h\"\n";
+ *out << "struct FileToc well_known_types_js[] = {\n";
- for (int i = 1; i < argc; i++) {
- AddFile(argv[i], &std::cout);
+ for (int i = 0; i < num_file_names; i++) {
+ AddFile(file_names[i], out);
}
- std::cout << " {NULL, NULL} // Terminate the list.\n";
- std::cout << "};\n";
+ *out << " {NULL, NULL} // Terminate the list.\n";
+ *out << "};\n";
+}
+int main(int argc, char* argv[]) {
+ // If argv[1] is the flag "--output_file" and argv[2] is the path to a file
+ // that we can successfully open for output, then we write the output to
+ // that file and interpret the remaining arguments as input file names.
+ // Otherwise we interpret all arguments as input file names and write the
+ // output to std out.
+ std::ostream* out = &std::cout;
+ std::ofstream ofs;
+ char** file_names = (argc > 1 ? &argv[1] : nullptr);
+ int num_file_names = argc - 1;
+ if (argc > 2) {
+ std::string arg1(argv[1]);
+ if (arg1 == "--output_file") {
+ // Try to open the file specified by argv[2]
+ ofs.open(argv[2]);
+ if (ofs.is_open()) {
+ file_names = (argc > 3 ? &argv[3] : nullptr);
+ num_file_names = argc - 3;
+ out = &ofs;
+ }
+ }
+ }
+ WriteOutput(file_names, num_file_names, out);
+ if (ofs.is_open()) {
+ ofs.close();
+ }
return EXIT_SUCCESS;
}
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h
index 0afd55d..2bdf883 100644
--- a/src/google/protobuf/stubs/port.h
+++ b/src/google/protobuf/stubs/port.h
@@ -254,10 +254,12 @@
#ifdef GOOGLE_PROTOBUF_DONT_USE_UNALIGNED
# define GOOGLE_PROTOBUF_USE_UNALIGNED 0
-#else
// x86 and x86-64 can perform unaligned loads/stores directly.
-# define GOOGLE_PROTOBUF_USE_UNALIGNED defined(_M_X64) || \
- defined(__x86_64__) || defined(_M_IX86) || defined(__i386__)
+#elif defined(_M_X64) || defined(__x86_64__) || defined(_M_IX86) || \
+ defined(__i386__)
+#define GOOGLE_PROTOBUF_USE_UNALIGNED 1
+#else
+#define GOOGLE_PROTOBUF_USE_UNALIGNED 0
#endif
#if GOOGLE_PROTOBUF_USE_UNALIGNED