From 7a0c431c8f2e5071c54f7f0fa37834138d9648de Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 18 Jun 2015 16:45:27 -0700 Subject: [PATCH] Enable tests for bazel build. Change-Id: I63ed5fb58a45e098f2fd1fa457a219148de030bd --- BUILD | 175 ++++++++++++++++++++++++------------------- WORKSPACE | 16 ++++ gmock.BUILD | 23 ++++++ update_file_lists.sh | 3 + 4 files changed, 140 insertions(+), 77 deletions(-) create mode 100644 gmock.BUILD diff --git a/BUILD b/BUILD index e897617d034d4..f50770605d2db 100644 --- a/BUILD +++ b/BUILD @@ -286,11 +286,13 @@ PROTOS = LITE_TEST_PROTOS + TEST_PROTOS INPUTS = PROTOS + WELL_KNOWN_PROTOS +OUTPUTS = ["src/" + x[:-5] + "pb.h" for x in PROTOS] + \ + ["src/" + x[:-5] + "pb.cc" for x in PROTOS] + genrule( name = "gen_test_protos", srcs = ["src/" + x for x in INPUTS], - outs = ["src/" + x[:-5] + "pb.h" for x in PROTOS] + - ["src/" + x[:-5] + "pb.cc" for x in PROTOS], + outs = OUTPUTS, cmd = "$(location :protoc) --cpp_out=$(@D)/src" + "".join([" -I" + x + "=$(location src/" + x + ")" for x in INPUTS]) + @@ -307,78 +309,97 @@ COMMON_TEST_SRCS = [ "src/google/protobuf/testing/googletest.cc", ] -# TODO(liujisi): Add gtest dependency and enable tests. -# cc_test( -# name = "protobuf_test", -# srcs = OUTPUTS + COMMON_TEST_SRCS + [ -# "src/google/protobuf/any_test.cc", -# "src/google/protobuf/arena_unittest.cc", -# "src/google/protobuf/arenastring_unittest.cc", -# "src/google/protobuf/compiler/command_line_interface_unittest.cc", -# "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc", -# "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc", -# "src/google/protobuf/compiler/cpp/cpp_unittest.cc", -# "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc", -# "src/google/protobuf/compiler/importer_unittest.cc", -# "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc", -# "src/google/protobuf/compiler/java/java_plugin_unittest.cc", -# "src/google/protobuf/compiler/mock_code_generator.cc", -# "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc", -# "src/google/protobuf/compiler/parser_unittest.cc", -# "src/google/protobuf/compiler/python/python_plugin_unittest.cc", -# "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc", -# "src/google/protobuf/descriptor_database_unittest.cc", -# "src/google/protobuf/descriptor_unittest.cc", -# "src/google/protobuf/drop_unknown_fields_test.cc", -# "src/google/protobuf/dynamic_message_unittest.cc", -# "src/google/protobuf/extension_set_unittest.cc", -# "src/google/protobuf/generated_message_reflection_unittest.cc", -# "src/google/protobuf/io/coded_stream_unittest.cc", -# "src/google/protobuf/io/printer_unittest.cc", -# "src/google/protobuf/io/tokenizer_unittest.cc", -# "src/google/protobuf/io/zero_copy_stream_unittest.cc", -# "src/google/protobuf/map_field_test.cc", -# "src/google/protobuf/map_test.cc", -# "src/google/protobuf/message_unittest.cc", -# "src/google/protobuf/no_field_presence_test.cc", -# "src/google/protobuf/preserve_unknown_enum_test.cc", -# "src/google/protobuf/proto3_arena_unittest.cc", -# "src/google/protobuf/reflection_ops_unittest.cc", -# "src/google/protobuf/repeated_field_reflection_unittest.cc", -# "src/google/protobuf/repeated_field_unittest.cc", -# "src/google/protobuf/stubs/bytestream_unittest.cc", -# "src/google/protobuf/stubs/common_unittest.cc", -# "src/google/protobuf/stubs/once_unittest.cc", -# "src/google/protobuf/stubs/status_test.cc", -# "src/google/protobuf/stubs/statusor_test.cc", -# "src/google/protobuf/stubs/stringpiece_unittest.cc", -# "src/google/protobuf/stubs/stringprintf_unittest.cc", -# "src/google/protobuf/stubs/structurally_valid_unittest.cc", -# "src/google/protobuf/stubs/strutil_unittest.cc", -# "src/google/protobuf/stubs/template_util_unittest.cc", -# "src/google/protobuf/stubs/time_test.cc", -# "src/google/protobuf/stubs/type_traits_unittest.cc", -# "src/google/protobuf/text_format_unittest.cc", -# "src/google/protobuf/unknown_field_set_unittest.cc", -# "src/google/protobuf/util/field_comparator_test.cc", -# "src/google/protobuf/util/internal/default_value_objectwriter_test.cc", -# "src/google/protobuf/util/internal/json_objectwriter_test.cc", -# "src/google/protobuf/util/internal/json_stream_parser_test.cc", -# "src/google/protobuf/util/internal/protostream_objectsource_test.cc", -# "src/google/protobuf/util/internal/protostream_objectwriter_test.cc", -# "src/google/protobuf/util/internal/type_info_test_helper.cc", -# "src/google/protobuf/util/json_util_test.cc", -# "src/google/protobuf/util/type_resolver_util_test.cc", -# "src/google/protobuf/well_known_types_unittest.cc", -# "src/google/protobuf/wire_format_unittest.cc", -# ], -# copts = COPTS, -# includes = [ -# "src/", -# ], -# linkopts = LINK_OPTS, -# deps = [ -# ":protobuf", -# ":protoc_lib", -# ], -# ) +cc_binary( + name = "test_plugin", + srcs = [ + # AUTOGEN(test_plugin_srcs) + "src/google/protobuf/compiler/mock_code_generator.cc", + "src/google/protobuf/compiler/test_plugin.cc", + "src/google/protobuf/testing/file.cc", + ], + deps = [ + ":protobuf", + ":protoc_lib", + "//external:gtest", + ], +) + +cc_test( + name = "protobuf_test", + srcs = OUTPUTS + COMMON_TEST_SRCS + [ + # AUTOGEN(test_srcs) + "src/google/protobuf/any_test.cc", + "src/google/protobuf/arena_unittest.cc", + "src/google/protobuf/arenastring_unittest.cc", + "src/google/protobuf/compiler/command_line_interface_unittest.cc", + "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc", + "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc", + "src/google/protobuf/compiler/cpp/cpp_unittest.cc", + "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc", + "src/google/protobuf/compiler/importer_unittest.cc", + "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc", + "src/google/protobuf/compiler/java/java_plugin_unittest.cc", + "src/google/protobuf/compiler/mock_code_generator.cc", + "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc", + "src/google/protobuf/compiler/parser_unittest.cc", + "src/google/protobuf/compiler/python/python_plugin_unittest.cc", + "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc", + "src/google/protobuf/descriptor_database_unittest.cc", + "src/google/protobuf/descriptor_unittest.cc", + "src/google/protobuf/drop_unknown_fields_test.cc", + "src/google/protobuf/dynamic_message_unittest.cc", + "src/google/protobuf/extension_set_unittest.cc", + "src/google/protobuf/generated_message_reflection_unittest.cc", + "src/google/protobuf/io/coded_stream_unittest.cc", + "src/google/protobuf/io/printer_unittest.cc", + "src/google/protobuf/io/tokenizer_unittest.cc", + "src/google/protobuf/io/zero_copy_stream_unittest.cc", + "src/google/protobuf/map_field_test.cc", + "src/google/protobuf/map_test.cc", + "src/google/protobuf/message_unittest.cc", + "src/google/protobuf/no_field_presence_test.cc", + "src/google/protobuf/preserve_unknown_enum_test.cc", + "src/google/protobuf/proto3_arena_unittest.cc", + "src/google/protobuf/reflection_ops_unittest.cc", + "src/google/protobuf/repeated_field_reflection_unittest.cc", + "src/google/protobuf/repeated_field_unittest.cc", + "src/google/protobuf/stubs/bytestream_unittest.cc", + "src/google/protobuf/stubs/common_unittest.cc", + "src/google/protobuf/stubs/once_unittest.cc", + "src/google/protobuf/stubs/status_test.cc", + "src/google/protobuf/stubs/statusor_test.cc", + "src/google/protobuf/stubs/stringpiece_unittest.cc", + "src/google/protobuf/stubs/stringprintf_unittest.cc", + "src/google/protobuf/stubs/structurally_valid_unittest.cc", + "src/google/protobuf/stubs/strutil_unittest.cc", + "src/google/protobuf/stubs/template_util_unittest.cc", + "src/google/protobuf/stubs/time_test.cc", + "src/google/protobuf/stubs/type_traits_unittest.cc", + "src/google/protobuf/text_format_unittest.cc", + "src/google/protobuf/unknown_field_set_unittest.cc", + "src/google/protobuf/util/field_comparator_test.cc", + "src/google/protobuf/util/internal/default_value_objectwriter_test.cc", + "src/google/protobuf/util/internal/json_objectwriter_test.cc", + "src/google/protobuf/util/internal/json_stream_parser_test.cc", + "src/google/protobuf/util/internal/protostream_objectsource_test.cc", + "src/google/protobuf/util/internal/protostream_objectwriter_test.cc", + "src/google/protobuf/util/internal/type_info_test_helper.cc", + "src/google/protobuf/util/json_util_test.cc", + "src/google/protobuf/util/type_resolver_util_test.cc", + "src/google/protobuf/well_known_types_unittest.cc", + "src/google/protobuf/wire_format_unittest.cc", + ], + copts = COPTS, + data = [ + ":test_plugin", + ], + includes = [ + "src/", + ], + linkopts = LINK_OPTS, + deps = [ + ":protobuf", + ":protoc_lib", + "//external:gtest_main", + ], +) diff --git a/WORKSPACE b/WORKSPACE index e69de29bb2d1d..f72f239a066e0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -0,0 +1,16 @@ +new_http_archive( + name = "gmock_archive", + url = "https://googlemock.googlecode.com/files/gmock-1.7.0.zip", + sha256 = "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b", + build_file = "gmock.BUILD", +) + +bind( + name = "gtest", + actual = "@gmock_archive//:gtest", +) + +bind( + name = "gtest_main", + actual = "@gmock_archive//:gtest_main", +) diff --git a/gmock.BUILD b/gmock.BUILD new file mode 100644 index 0000000000000..66cddea9f4d6c --- /dev/null +++ b/gmock.BUILD @@ -0,0 +1,23 @@ +cc_library( + name = "gtest", + srcs = [ + "gmock-1.7.0/gtest/src/gtest-all.cc", + "gmock-1.7.0/src/gmock-all.cc", + ], + includes = [ + "gmock-1.7.0", + "gmock-1.7.0/gtest", + "gmock-1.7.0/gtest/include", + "gmock-1.7.0/include", + ], + linkopts = ["-pthread"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "gtest_main", + srcs = ["gmock-1.7.0/src/gmock_main.cc"], + linkopts = ["-pthread"], + visibility = ["//visibility:public"], + deps = [":gtest"], +) diff --git a/update_file_lists.sh b/update_file_lists.sh index aa0d15aec710e..34443456f03df 100755 --- a/update_file_lists.sh +++ b/update_file_lists.sh @@ -57,6 +57,7 @@ WKT_PROTOS=$(get_variable_value $MAKEFILE nobase_dist_proto_DATA) COMMON_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_TEST_SOURCES) TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_test_SOURCES) LITE_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_test_SOURCES) +TEST_PLUGIN_SOURCES=$(get_source_files $MAKEFILE test_plugin_SOURCES) ################################################################################ # Update cmake files. @@ -177,3 +178,5 @@ set_bazel_value $BAZEL_BUILD well_known_protos "" $WKT_PROTOS set_bazel_value $BAZEL_BUILD test_protos "" $PROTOS set_bazel_value $BAZEL_BUILD common_test_srcs $BAZEL_PREFIX $COMMON_TEST_SOURCES set_bazel_value $BAZEL_BUILD test_srcs $BAZEL_PREFIX $TEST_SOURCES +set_bazel_value $BAZEL_BUILD test_plugin_srcs $BAZEL_PREFIX $TEST_PLUGIN_SOURCES +