Skip to content

Commit

Permalink
Include googletest as a submodule (#3993)
Browse files Browse the repository at this point in the history
Add googletest as a submodule in third_party/googletest.
  • Loading branch information
coryan authored and xfxyjwf committed Mar 26, 2018
1 parent 1156ee7 commit 3c5442a
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 120 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ m4/lt~obsolete.m4
autom4te.cache

# downloaded files
gmock
./gmock

# in-tree configure-generated files
Makefile
Expand Down Expand Up @@ -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/
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
15 changes: 7 additions & 8 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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"; \
Expand Down Expand Up @@ -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 \
Expand Down
13 changes: 6 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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(
Expand Down
10 changes: 1 addition & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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.
Expand Down
19 changes: 4 additions & 15 deletions cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
20 changes: 11 additions & 9 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 0 additions & 28 deletions gmock.BUILD

This file was deleted.

3 changes: 3 additions & 0 deletions jenkins/pull_request_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions kokoro/linux/pull_request_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 27 additions & 23 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 = \
Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,6 +56,8 @@ build_cpp() {
}

build_cpp_distcheck() {
# Initialize any submodules.
git submodule update --init --recursive
./autogen.sh
./configure
make dist
Expand Down
1 change: 1 addition & 0 deletions third_party/googletest
Submodule googletest added at c3bb0e

0 comments on commit 3c5442a

Please sign in to comment.