Include googletest as a submodule (#3993)

Add googletest as a submodule in third_party/googletest.
pull/4432/head
Carlos O'Ryan 7 years ago committed by Feng Xiao
parent 1156ee7ea7
commit 3c5442a95d
  1. 10
      .gitignore
  2. 4
      .gitmodules
  3. 15
      Makefile.am
  4. 13
      WORKSPACE
  5. 10
      appveyor.yml
  6. 18
      autogen.sh
  7. 19
      cmake/README.md
  8. 20
      cmake/tests.cmake
  9. 2
      configure.ac
  10. 28
      gmock.BUILD
  11. 3
      jenkins/pull_request_in_docker.sh
  12. 3
      kokoro/linux/pull_request_in_docker.sh
  13. 50
      src/Makefile.am
  14. 2
      src/README.md
  15. 5
      tests.sh
  16. 1
      third_party/googletest

10
.gitignore vendored

@ -19,7 +19,7 @@ m4/lt~obsolete.m4
autom4te.cache autom4te.cache
# downloaded files # downloaded files
gmock ./gmock
# in-tree configure-generated files # in-tree configure-generated files
Makefile Makefile
@ -180,3 +180,11 @@ ruby/Gemfile.lock
ruby/compatibility_tests/v3.0.0/protoc 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/generated_code_pb.rb
ruby/compatibility_tests/v3.0.0/tests/test_import_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/

4
.gitmodules vendored

@ -1,3 +1,7 @@
[submodule "third_party/benchmark"] [submodule "third_party/benchmark"]
path = third_party/benchmark path = third_party/benchmark
url = https://github.com/google/benchmark.git url = https://github.com/google/benchmark.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
ignore = dirty

@ -8,8 +8,8 @@ AUTOMAKE_OPTIONS = foreign
# the right time. # the right time.
SUBDIRS = . src SUBDIRS = . src
# Always include gmock in distributions. # Always include third_party directories in distributions.
DIST_SUBDIRS = $(subdirs) src conformance benchmarks DIST_SUBDIRS = src conformance benchmarks third_party/googletest
# Build gmock before we build protobuf tests. We don't add gmock to SUBDIRS # 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, # 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. # the installed version of gmock if there is one.
check-local: check-local:
@echo "Making lib/libgmock.a lib/libgmock_main.a in gmock" @echo "Making lib/libgmock.a lib/libgmock_main.a in gmock"
@cd gmock && $(MAKE) $(AM_MAKEFLAGS) lib/libgmock.la lib/libgmock_main.la @cd third_party/googletest/googletest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la
@cd gmock/gtest && $(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 # 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 # 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 # cd to the directory again and "make clean" it will fail. So, check that the
# Makefile exists before recursing. # Makefile exists before recursing.
clean-local: clean-local:
@if test -e gmock/Makefile; then \ @if test -e third_party/googletest/Makefile; then \
echo "Making clean in gmock"; \ echo "Making clean in googletest"; \
cd gmock && $(MAKE) $(AM_MAKEFLAGS) clean; \ cd third_party/googletest && $(MAKE) $(AM_MAKEFLAGS) clean; \
fi; \ fi; \
if test -e conformance/Makefile; then \ if test -e conformance/Makefile; then \
echo "Making clean in conformance"; \ echo "Making clean in conformance"; \
@ -1008,7 +1008,6 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
CHANGES.txt \ CHANGES.txt \
update_file_lists.sh \ update_file_lists.sh \
BUILD \ BUILD \
gmock.BUILD \
WORKSPACE \ WORKSPACE \
cmake/CMakeLists.txt \ cmake/CMakeLists.txt \
cmake/README.md \ cmake/README.md \

@ -1,10 +1,9 @@
workspace(name = "com_google_protobuf") workspace(name = "com_google_protobuf")
new_git_repository( new_local_repository(
name = "googletest", name = "submodule_gmock",
build_file = "gmock.BUILD", path = "third_party/googletest",
remote = "https://github.com/google/googletest", build_file = "third_party/googletest/BUILD.bazel"
tag = "release-1.8.0",
) )
new_http_archive( new_http_archive(
@ -21,12 +20,12 @@ bind(
bind( bind(
name = "gtest", name = "gtest",
actual = "@googletest//:gtest", actual = "@submodule_gmock//:gtest",
) )
bind( bind(
name = "gtest_main", name = "gtest_main",
actual = "@googletest//:gtest_main", actual = "@submodule_gmock//:gtest_main",
) )
bind( bind(

@ -22,15 +22,7 @@ environment:
test: off test: off
install: install:
- curl -L -o release-1.7.0.zip https://github.com/google/googlemock/archive/release-1.7.0.zip - git submodule update --init --recursive
- 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
before_build: before_build:
- if %platform%==Win32 set generator=Visual Studio 14 - if %platform%==Win32 set generator=Visual Studio 14

@ -17,7 +17,6 @@ if [ ! -z "$@" ]; then
done done
fi fi
# Check that we're being run from the right directory. # Check that we're being run from the right directory.
if test ! -f src/google/protobuf/stubs/common.h; then if test ! -f src/google/protobuf/stubs/common.h; then
cat >&2 << __EOF__ cat >&2 << __EOF__
@ -27,23 +26,6 @@ __EOF__
exit 1 exit 1
fi 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 set -ex
# TODO(kenton): Remove the ",no-obsolete" part and fix the resulting warnings. # TODO(kenton): Remove the ",no-obsolete" part and fix the resulting warnings.

@ -55,22 +55,11 @@ Go to the project folder:
C:\Path\to>cd protobuf C:\Path\to>cd protobuf
C:\Path\to\protobuf> C:\Path\to\protobuf>
Protobuf unit-tests require gmock to build. If you download protobuf source code Remember to update any submodules:
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.
You can download gmock as follows: ```console
C:\Path\to> git submodule update --init --recursive
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.
Now go to *cmake* folder in protobuf sources: Now go to *cmake* folder in protobuf sources:

@ -1,24 +1,26 @@
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt") if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../third_party/googletest/CMakeLists.txt")
message(FATAL_ERROR "Cannot find gmock directory.") message(FATAL_ERROR "Cannot find third_party/googletest directory.")
endif() endif()
option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
"Using absolute test_plugin path in tests" ON) "Using absolute test_plugin path in tests" ON)
mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH) 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( include_directories(
${protobuf_source_dir}/gmock ${googlemock_source_dir}
${protobuf_source_dir}/gmock/gtest ${googletest_source_dir}
${protobuf_source_dir}/gmock/gtest/include ${googletest_source_dir}/include
${protobuf_source_dir}/gmock/include ${googlemock_source_dir}/include
) )
add_library(gmock STATIC add_library(gmock STATIC
${protobuf_source_dir}/gmock/src/gmock-all.cc "${googlemock_source_dir}/src/gmock-all.cc"
${protobuf_source_dir}/gmock/gtest/src/gtest-all.cc "${googletest_source_dir}/src/gtest-all.cc"
) )
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) 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) target_link_libraries(gmock_main gmock)
set(lite_test_protos set(lite_test_protos

@ -214,7 +214,7 @@ AX_CXX_COMPILE_STDCXX([11], [noext], [optional])
# too. # too.
export CFLAGS export CFLAGS
export CXXFLAGS 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_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc])
AC_OUTPUT AC_OUTPUT

@ -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"],
)

@ -19,6 +19,9 @@ cd $BUILD_DIR
git clone /var/local/jenkins/protobuf git clone /var/local/jenkins/protobuf
cd protobuf cd protobuf
# Initialize any submodules:
git submodule update --init --recursive
# Set up the directory where our test output is going to go. # Set up the directory where our test output is going to go.
OUTPUT_DIR=`mktemp -d` OUTPUT_DIR=`mktemp -d`
LOG_OUTPUT_DIR=$OUTPUT_DIR/logs LOG_OUTPUT_DIR=$OUTPUT_DIR/logs

@ -19,6 +19,9 @@ cd $BUILD_DIR
git clone /var/local/kokoro/protobuf git clone /var/local/kokoro/protobuf
cd protobuf cd protobuf
# Initialize any submodules:
git submodule update --init --recursive
# Set up the directory where our test output is going to go. # Set up the directory where our test output is going to go.
OUTPUT_DIR=`mktemp -d` OUTPUT_DIR=`mktemp -d`
LOG_OUTPUT_DIR=$OUTPUT_DIR/logs LOG_OUTPUT_DIR=$OUTPUT_DIR/logs

@ -711,15 +711,19 @@ COMMON_TEST_SOURCES = \
google/protobuf/testing/file.cc \ google/protobuf/testing/file.cc \
google/protobuf/testing/file.h 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 \ check_PROGRAMS = protoc protobuf-test protobuf-lazy-descriptor-test \
protobuf-lite-test test_plugin protobuf-lite-arena-test \ protobuf-lite-test test_plugin protobuf-lite-arena-test \
no-warning-test $(GZCHECKPROGRAMS) no-warning-test $(GZCHECKPROGRAMS)
protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
../gmock/gtest/lib/libgtest.la \ $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \
../gmock/lib/libgmock.la \ $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \
../gmock/lib/libgmock_main.la $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la
protobuf_test_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include \ protobuf_test_CPPFLAGS = -I$(GOOGLETEST_SRC_DIR)/include \
-I$(srcdir)/../gmock/include -I$(GOOGLEMOCK_SRC_DIR)/include
# Disable optimization for tests unless the user explicitly asked for it, # Disable optimization for tests unless the user explicitly asked for it,
# since test_util.cc takes forever to compile with optimization (with GCC). # since test_util.cc takes forever to compile with optimization (with GCC).
# See configure.ac for more info. # 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. # Run cpp_unittest again with PROTOBUF_TEST_NO_DESCRIPTORS defined.
protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \ protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \
libprotoc.la \ libprotoc.la \
../gmock/gtest/lib/libgtest.la \ $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \
../gmock/lib/libgmock.la \ $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \
../gmock/lib/libgmock_main.la $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la
protobuf_lazy_descriptor_test_CPPFLAGS = -I$(srcdir)/../gmock/include \ protobuf_lazy_descriptor_test_CPPFLAGS = -I$(GOOGLEMOCK_SRC_DIR)/include \
-I$(srcdir)/../gmock/gtest/include \ -I$(GOOGLETEST_SRC_DIR)/include \
-DPROTOBUF_TEST_NO_DESCRIPTORS -DPROTOBUF_TEST_NO_DESCRIPTORS
protobuf_lazy_descriptor_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) protobuf_lazy_descriptor_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
protobuf_lazy_descriptor_test_SOURCES = \ 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 # 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 # full runtime and we want to make sure this test builds without full
# runtime. # runtime.
protobuf_lite_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \ protobuf_lite_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \
../gmock/gtest/lib/libgtest.la \ $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \
../gmock/lib/libgmock.la \ $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \
../gmock/lib/libgmock_main.la $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la
protobuf_lite_test_CPPFLAGS= -I$(srcdir)/../gmock/include \ protobuf_lite_test_CPPFLAGS= -I$(GOOGLEMOCK_SRC_DIR)/include \
-I$(srcdir)/../gmock/gtest/include -I$(GOOGLETEST_SRC_DIR)/include
protobuf_lite_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) protobuf_lite_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
protobuf_lite_test_SOURCES = \ protobuf_lite_test_SOURCES = \
google/protobuf/lite_unittest.cc \ 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 # gtest when building the test internally our memory sanitizer doesn't detect
# memory leaks (don't know why). # memory leaks (don't know why).
protobuf_lite_arena_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \ protobuf_lite_arena_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \
../gmock/gtest/lib/libgtest.la \ $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \
../gmock/lib/libgmock.la \ $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \
../gmock/lib/libgmock_main.la $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la
protobuf_lite_arena_test_CPPFLAGS = -I$(srcdir)/../gmock/include \ protobuf_lite_arena_test_CPPFLAGS = -I$(GOOGLEMOCK_SRC_DIR)/include \
-I$(srcdir)/../gmock/gtest/include -I$(GOOGLETEST_SRC_DIR)/include
protobuf_lite_arena_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) protobuf_lite_arena_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
protobuf_lite_arena_test_SOURCES = \ protobuf_lite_arena_test_SOURCES = \
google/protobuf/lite_arena_unittest.cc \ google/protobuf/lite_arena_unittest.cc \
@ -863,8 +867,8 @@ $(am_protobuf_lite_arena_test_OBJECTS): unittest_proto_middleman
# Test plugin binary. # Test plugin binary.
test_plugin_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ test_plugin_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
../gmock/gtest/lib/libgtest.la $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la
test_plugin_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include test_plugin_CPPFLAGS = -I$(GOOGLETEST_SRC_DIR)/include
test_plugin_SOURCES = \ test_plugin_SOURCES = \
google/protobuf/compiler/mock_code_generator.cc \ google/protobuf/compiler/mock_code_generator.cc \
google/protobuf/testing/file.cc \ google/protobuf/testing/file.cc \

@ -15,7 +15,6 @@ To build protobuf from source, the following tools are needed:
* autoconf * autoconf
* automake * automake
* libtool * libtool
* curl (used to download gmock)
* make * make
* g++ * g++
* unzip * unzip
@ -30,6 +29,7 @@ install them before proceeding.
If you get the source from github, you need to generate the configure script If you get the source from github, you need to generate the configure script
first: first:
$ git submodule update --init --recursive
$ ./autogen.sh $ ./autogen.sh
This will download gmock source (which is used for C++ Protocol Buffer This will download gmock source (which is used for C++ Protocol Buffer

@ -27,6 +27,9 @@ internal_build_cpp() {
export CXX="g++-4.8" CC="gcc-4.8" export CXX="g++-4.8" CC="gcc-4.8"
fi fi
# Initialize any submodules.
git submodule update --init --recursive
./autogen.sh ./autogen.sh
./configure CXXFLAGS="-fPIC" # -fPIC is needed for python cpp test. ./configure CXXFLAGS="-fPIC" # -fPIC is needed for python cpp test.
# See python/setup.py for more details # See python/setup.py for more details
@ -53,6 +56,8 @@ build_cpp() {
} }
build_cpp_distcheck() { build_cpp_distcheck() {
# Initialize any submodules.
git submodule update --init --recursive
./autogen.sh ./autogen.sh
./configure ./configure
make dist make dist

@ -0,0 +1 @@
Subproject commit c3bb0ee2a63279a803aaad956b9b26d74bf9e6e2
Loading…
Cancel
Save