From 3c5442a95d9608519a76a5db27d21d71dd1137a1 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Mon, 26 Mar 2018 16:54:32 -0400 Subject: Include googletest as a submodule (#3993) Add googletest as a submodule in third_party/googletest. --- .gitignore | 10 ++++++- .gitmodules | 4 +++ Makefile.am | 15 +++++----- WORKSPACE | 13 ++++----- appveyor.yml | 10 +------ autogen.sh | 18 ------------ cmake/README.md | 19 +++---------- cmake/tests.cmake | 20 ++++++++------ configure.ac | 2 +- gmock.BUILD | 28 ------------------- jenkins/pull_request_in_docker.sh | 3 ++ kokoro/linux/pull_request_in_docker.sh | 3 ++ src/Makefile.am | 50 ++++++++++++++++++---------------- src/README.md | 2 +- tests.sh | 5 ++++ third_party/googletest | 1 + 16 files changed, 83 insertions(+), 120 deletions(-) delete mode 100644 gmock.BUILD create mode 160000 third_party/googletest diff --git a/.gitignore b/.gitignore index af88e226..0efa2145 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,7 @@ m4/lt~obsolete.m4 autom4te.cache # downloaded files -gmock +./gmock # in-tree configure-generated files Makefile @@ -180,3 +180,11 @@ ruby/Gemfile.lock ruby/compatibility_tests/v3.0.0/protoc ruby/compatibility_tests/v3.0.0/tests/generated_code_pb.rb ruby/compatibility_tests/v3.0.0/tests/test_import_pb.rb + +# IntelliJ CLion Config files and build output +cmake/.idea +cmake/cmake-build-debug/ + +# Common build subdirectories. +./.build/ +./_build/ diff --git a/.gitmodules b/.gitmodules index 55a47cea..bcd125a4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "third_party/benchmark"] path = third_party/benchmark url = https://github.com/google/benchmark.git +[submodule "third_party/googletest"] + path = third_party/googletest + url = https://github.com/google/googletest.git + ignore = dirty diff --git a/Makefile.am b/Makefile.am index 045bc553..8e85484b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,8 +8,8 @@ AUTOMAKE_OPTIONS = foreign # the right time. SUBDIRS = . src -# Always include gmock in distributions. -DIST_SUBDIRS = $(subdirs) src conformance benchmarks +# Always include third_party directories in distributions. +DIST_SUBDIRS = src conformance benchmarks third_party/googletest # Build gmock before we build protobuf tests. We don't add gmock to SUBDIRS # because then "make check" would also build and run all of gmock's own tests, @@ -18,8 +18,8 @@ DIST_SUBDIRS = $(subdirs) src conformance benchmarks # the installed version of gmock if there is one. check-local: @echo "Making lib/libgmock.a lib/libgmock_main.a in gmock" - @cd gmock && $(MAKE) $(AM_MAKEFLAGS) lib/libgmock.la lib/libgmock_main.la - @cd gmock/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la + @cd third_party/googletest/googletest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la + @cd third_party/googletest/googlemock && $(MAKE) $(AM_MAKEFLAGS) lib/libgmock.la lib/libgmock_main.la # We would like to clean gmock when "make clean" is invoked. But we have to # be careful because clean-local is also invoked during "make distclean", but @@ -28,9 +28,9 @@ check-local: # cd to the directory again and "make clean" it will fail. So, check that the # Makefile exists before recursing. clean-local: - @if test -e gmock/Makefile; then \ - echo "Making clean in gmock"; \ - cd gmock && $(MAKE) $(AM_MAKEFLAGS) clean; \ + @if test -e third_party/googletest/Makefile; then \ + echo "Making clean in googletest"; \ + cd third_party/googletest && $(MAKE) $(AM_MAKEFLAGS) clean; \ fi; \ if test -e conformance/Makefile; then \ echo "Making clean in conformance"; \ @@ -1008,7 +1008,6 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ CHANGES.txt \ update_file_lists.sh \ BUILD \ - gmock.BUILD \ WORKSPACE \ cmake/CMakeLists.txt \ cmake/README.md \ diff --git a/WORKSPACE b/WORKSPACE index 1066a0e6..06a8a841 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,10 +1,9 @@ workspace(name = "com_google_protobuf") -new_git_repository( - name = "googletest", - build_file = "gmock.BUILD", - remote = "https://github.com/google/googletest", - tag = "release-1.8.0", +new_local_repository( + name = "submodule_gmock", + path = "third_party/googletest", + build_file = "third_party/googletest/BUILD.bazel" ) new_http_archive( @@ -21,12 +20,12 @@ bind( bind( name = "gtest", - actual = "@googletest//:gtest", + actual = "@submodule_gmock//:gtest", ) bind( name = "gtest_main", - actual = "@googletest//:gtest_main", + actual = "@submodule_gmock//:gtest_main", ) bind( diff --git a/appveyor.yml b/appveyor.yml index aab56b04..02e0d313 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,15 +22,7 @@ environment: test: off install: - - curl -L -o release-1.7.0.zip https://github.com/google/googlemock/archive/release-1.7.0.zip - - 7z x release-1.7.0.zip - - del /Q release-1.7.0.zip - - rename googlemock-release-1.7.0 gmock - - curl -L -o release-1.7.0.zip "https://github.com/google/googletest/archive/release-1.7.0.zip" - - 7z x release-1.7.0.zip - - del /Q release-1.7.0.zip - - rename googletest-release-1.7.0 gtest - - move gtest gmock + - git submodule update --init --recursive before_build: - if %platform%==Win32 set generator=Visual Studio 14 diff --git a/autogen.sh b/autogen.sh index 9560aaf1..580714b9 100755 --- a/autogen.sh +++ b/autogen.sh @@ -17,7 +17,6 @@ if [ ! -z "$@" ]; then done fi - # Check that we're being run from the right directory. if test ! -f src/google/protobuf/stubs/common.h; then cat >&2 << __EOF__ @@ -27,23 +26,6 @@ __EOF__ exit 1 fi -# Check that gmock is present. Usually it is already there since the -# directory is set up as an SVN external. -if test ! -e gmock; then - echo "Google Mock not present. Fetching gmock-1.7.0 from the web..." - curl $curlopts -L -O https://github.com/google/googlemock/archive/release-1.7.0.zip - unzip -q release-1.7.0.zip - rm release-1.7.0.zip - mv googlemock-release-1.7.0 gmock -fi - -if test ! -e gmock/gtest; then - curl $curlopts -L -O https://github.com/google/googletest/archive/release-1.7.0.zip - unzip -q release-1.7.0.zip - rm release-1.7.0.zip - mv googletest-release-1.7.0 gmock/gtest -fi - set -ex # TODO(kenton): Remove the ",no-obsolete" part and fix the resulting warnings. diff --git a/cmake/README.md b/cmake/README.md index 305ebb88..de14b012 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -55,22 +55,11 @@ Go to the project folder: C:\Path\to>cd protobuf C:\Path\to\protobuf> -Protobuf unit-tests require gmock to build. If you download protobuf source code -from the *releases* page, the *gmock* directory should already be there. If you checkout -the code via `git clone`, this *gmock* directory won't exist and you will have to -download it manually or skip building protobuf unit-tests. +Remember to update any submodules: -You can download gmock as follows: - - C:\Path\to\protobuf>git clone -b release-1.7.0 https://github.com/google/googlemock.git gmock - -Then go to *gmock* folder and download gtest: - - C:\Path\to\protobuf>cd gmock - C:\Path\to\protobuf\gmock>git clone -b release-1.7.0 https://github.com/google/googletest.git gtest - -If you absolutely don't want to build and run protobuf unit-tests, skip -this steps and use protobuf at your own risk. +```console +C:\Path\to> git submodule update --init --recursive +``` Now go to *cmake* folder in protobuf sources: diff --git a/cmake/tests.cmake b/cmake/tests.cmake index e7c483d4..d7522759 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -1,24 +1,26 @@ -if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt") - message(FATAL_ERROR "Cannot find gmock directory.") +if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../third_party/googletest/CMakeLists.txt") + message(FATAL_ERROR "Cannot find third_party/googletest directory.") endif() option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH "Using absolute test_plugin path in tests" ON) mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH) +set(googlemock_source_dir "${protobuf_source_dir}/third_party/googletest/googlemock") +set(googletest_source_dir "${protobuf_source_dir}/third_party/googletest/googletest") include_directories( - ${protobuf_source_dir}/gmock - ${protobuf_source_dir}/gmock/gtest - ${protobuf_source_dir}/gmock/gtest/include - ${protobuf_source_dir}/gmock/include + ${googlemock_source_dir} + ${googletest_source_dir} + ${googletest_source_dir}/include + ${googlemock_source_dir}/include ) add_library(gmock STATIC - ${protobuf_source_dir}/gmock/src/gmock-all.cc - ${protobuf_source_dir}/gmock/gtest/src/gtest-all.cc + "${googlemock_source_dir}/src/gmock-all.cc" + "${googletest_source_dir}/src/gtest-all.cc" ) target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) -add_library(gmock_main STATIC ${protobuf_source_dir}/gmock/src/gmock_main.cc) +add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc") target_link_libraries(gmock_main gmock) set(lite_test_protos diff --git a/configure.ac b/configure.ac index 4e3dc613..6283e317 100644 --- a/configure.ac +++ b/configure.ac @@ -214,7 +214,7 @@ AX_CXX_COMPILE_STDCXX([11], [noext], [optional]) # too. export CFLAGS export CXXFLAGS -AC_CONFIG_SUBDIRS([gmock]) +AC_CONFIG_SUBDIRS([third_party/googletest]) AC_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc]) AC_OUTPUT diff --git a/gmock.BUILD b/gmock.BUILD deleted file mode 100644 index b1ae15a9..00000000 --- a/gmock.BUILD +++ /dev/null @@ -1,28 +0,0 @@ -cc_library( - name = "gtest", - srcs = [ - "googletest/src/gtest-all.cc", - "googlemock/src/gmock-all.cc", - ], - hdrs = glob([ - "**/*.h", - "googletest/src/*.cc", - "googlemock/src/*.cc", - ]), - includes = [ - "googlemock", - "googletest", - "googletest/include", - "googlemock/include", - ], - linkopts = ["-pthread"], - visibility = ["//visibility:public"], -) - -cc_library( - name = "gtest_main", - srcs = ["googlemock/src/gmock_main.cc"], - linkopts = ["-pthread"], - visibility = ["//visibility:public"], - deps = [":gtest"], -) diff --git a/jenkins/pull_request_in_docker.sh b/jenkins/pull_request_in_docker.sh index 10daf0a5..19753c39 100755 --- a/jenkins/pull_request_in_docker.sh +++ b/jenkins/pull_request_in_docker.sh @@ -19,6 +19,9 @@ cd $BUILD_DIR git clone /var/local/jenkins/protobuf cd protobuf +# Initialize any submodules: +git submodule update --init --recursive + # Set up the directory where our test output is going to go. OUTPUT_DIR=`mktemp -d` LOG_OUTPUT_DIR=$OUTPUT_DIR/logs diff --git a/kokoro/linux/pull_request_in_docker.sh b/kokoro/linux/pull_request_in_docker.sh index 23e63961..df3636cc 100755 --- a/kokoro/linux/pull_request_in_docker.sh +++ b/kokoro/linux/pull_request_in_docker.sh @@ -19,6 +19,9 @@ cd $BUILD_DIR git clone /var/local/kokoro/protobuf cd protobuf +# Initialize any submodules: +git submodule update --init --recursive + # Set up the directory where our test output is going to go. OUTPUT_DIR=`mktemp -d` LOG_OUTPUT_DIR=$OUTPUT_DIR/logs diff --git a/src/Makefile.am b/src/Makefile.am index 9639fcb8..7310210e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -711,15 +711,19 @@ COMMON_TEST_SOURCES = \ google/protobuf/testing/file.cc \ google/protobuf/testing/file.h +GOOGLETEST_BUILD_DIR=../third_party/googletest/googletest +GOOGLEMOCK_BUILD_DIR=../third_party/googletest/googlemock +GOOGLETEST_SRC_DIR=$(srcdir)/../third_party/googletest/googletest +GOOGLEMOCK_SRC_DIR=$(srcdir)/../third_party/googletest/googlemock check_PROGRAMS = protoc protobuf-test protobuf-lazy-descriptor-test \ protobuf-lite-test test_plugin protobuf-lite-arena-test \ no-warning-test $(GZCHECKPROGRAMS) protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ - ../gmock/gtest/lib/libgtest.la \ - ../gmock/lib/libgmock.la \ - ../gmock/lib/libgmock_main.la -protobuf_test_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include \ - -I$(srcdir)/../gmock/include + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la +protobuf_test_CPPFLAGS = -I$(GOOGLETEST_SRC_DIR)/include \ + -I$(GOOGLEMOCK_SRC_DIR)/include # Disable optimization for tests unless the user explicitly asked for it, # since test_util.cc takes forever to compile with optimization (with GCC). # See configure.ac for more info. @@ -807,11 +811,11 @@ $(am_protobuf_test_OBJECTS): unittest_proto_middleman # Run cpp_unittest again with PROTOBUF_TEST_NO_DESCRIPTORS defined. protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \ libprotoc.la \ - ../gmock/gtest/lib/libgtest.la \ - ../gmock/lib/libgmock.la \ - ../gmock/lib/libgmock_main.la -protobuf_lazy_descriptor_test_CPPFLAGS = -I$(srcdir)/../gmock/include \ - -I$(srcdir)/../gmock/gtest/include \ + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la +protobuf_lazy_descriptor_test_CPPFLAGS = -I$(GOOGLEMOCK_SRC_DIR)/include \ + -I$(GOOGLETEST_SRC_DIR)/include \ -DPROTOBUF_TEST_NO_DESCRIPTORS protobuf_lazy_descriptor_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) protobuf_lazy_descriptor_test_SOURCES = \ @@ -832,12 +836,12 @@ COMMON_LITE_TEST_SOURCES = \ # depend on gtest because our internal version of gtest depend on proto # full runtime and we want to make sure this test builds without full # runtime. -protobuf_lite_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \ - ../gmock/gtest/lib/libgtest.la \ - ../gmock/lib/libgmock.la \ - ../gmock/lib/libgmock_main.la -protobuf_lite_test_CPPFLAGS= -I$(srcdir)/../gmock/include \ - -I$(srcdir)/../gmock/gtest/include +protobuf_lite_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \ + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la +protobuf_lite_test_CPPFLAGS= -I$(GOOGLEMOCK_SRC_DIR)/include \ + -I$(GOOGLETEST_SRC_DIR)/include protobuf_lite_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) protobuf_lite_test_SOURCES = \ google/protobuf/lite_unittest.cc \ @@ -849,11 +853,11 @@ $(am_protobuf_lite_test_OBJECTS): unittest_proto_middleman # gtest when building the test internally our memory sanitizer doesn't detect # memory leaks (don't know why). protobuf_lite_arena_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \ - ../gmock/gtest/lib/libgtest.la \ - ../gmock/lib/libgmock.la \ - ../gmock/lib/libgmock_main.la -protobuf_lite_arena_test_CPPFLAGS = -I$(srcdir)/../gmock/include \ - -I$(srcdir)/../gmock/gtest/include + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la +protobuf_lite_arena_test_CPPFLAGS = -I$(GOOGLEMOCK_SRC_DIR)/include \ + -I$(GOOGLETEST_SRC_DIR)/include protobuf_lite_arena_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) protobuf_lite_arena_test_SOURCES = \ google/protobuf/lite_arena_unittest.cc \ @@ -863,8 +867,8 @@ $(am_protobuf_lite_arena_test_OBJECTS): unittest_proto_middleman # Test plugin binary. test_plugin_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ - ../gmock/gtest/lib/libgtest.la -test_plugin_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la +test_plugin_CPPFLAGS = -I$(GOOGLETEST_SRC_DIR)/include test_plugin_SOURCES = \ google/protobuf/compiler/mock_code_generator.cc \ google/protobuf/testing/file.cc \ diff --git a/src/README.md b/src/README.md index 3ae23fa6..b553cf27 100644 --- a/src/README.md +++ b/src/README.md @@ -15,7 +15,6 @@ To build protobuf from source, the following tools are needed: * autoconf * automake * libtool - * curl (used to download gmock) * make * g++ * unzip @@ -30,6 +29,7 @@ install them before proceeding. If you get the source from github, you need to generate the configure script first: + $ git submodule update --init --recursive $ ./autogen.sh This will download gmock source (which is used for C++ Protocol Buffer diff --git a/tests.sh b/tests.sh index fbbfd448..feb90c59 100755 --- a/tests.sh +++ b/tests.sh @@ -27,6 +27,9 @@ internal_build_cpp() { export CXX="g++-4.8" CC="gcc-4.8" fi + # Initialize any submodules. + git submodule update --init --recursive + ./autogen.sh ./configure CXXFLAGS="-fPIC" # -fPIC is needed for python cpp test. # See python/setup.py for more details @@ -53,6 +56,8 @@ build_cpp() { } build_cpp_distcheck() { + # Initialize any submodules. + git submodule update --init --recursive ./autogen.sh ./configure make dist diff --git a/third_party/googletest b/third_party/googletest new file mode 160000 index 00000000..c3bb0ee2 --- /dev/null +++ b/third_party/googletest @@ -0,0 +1 @@ +Subproject commit c3bb0ee2a63279a803aaad956b9b26d74bf9e6e2 -- cgit v1.2.3