Skip to content

Commit 48c92af

Browse files
authored
Enable scan build (#157)
Run Clang static analyzer against installed gRPC. Compiling with the Clang static analyzer is fairly slow, and can take longer than the maximum time allowed by Travis if gRPC is part of the build. In this change we compile and install gRPC first, and then compile the code against it. That seems to be the only way to stop cmake from using the static analyzer everywhere. And frankly it is a good thing that we test the "package" version of gRPC too. I think this could be a fix for #10, but I will let @mbrukman decide.
1 parent 579d2fb commit 48c92af

12 files changed

Lines changed: 145 additions & 63 deletions

.travis.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ matrix:
3939
env: DISTRO=fedora DISTRO_VERSION=27
4040
- os: osx
4141
compiler: clang
42+
script: ci/build-macosx.sh
4243
if: type != pull_request
4344
- os: linux
4445
compiler: clang
@@ -47,15 +48,23 @@ matrix:
4748
- os: linux
4849
compiler: gcc
4950
env: DISTRO=centos DISTRO_VERSION=7 BUILD_TYPE=Release
51+
- # This is a fairly specialized entry in the matrix. It builds the clients
52+
# using a pre-installed gRPC package. To do so, it builds the normal
53+
# Docker image with all the build tools, and uses that image to build and
54+
# install gRPC.
55+
os: linux
56+
compiler: clang
57+
env: DISTRO=ubuntu-with-grpc DISTRO_VERSION=16.04 BUILD_TYPE=Release \
58+
SCAN_BUILD=yes CMAKE_FLAGS=-DGOOGLE_CLOUD_CPP_GRPC_PROVIDER=package
59+
install:
60+
- DISTRO=ubuntu DISTRO_VERSION=16.04 SCAN_BUILD=no ./ci/install-linux.sh
61+
- ./ci/install-linux.sh
62+
if: type != pull_request
5063

5164
script:
5265
- ci/build-linux.sh
53-
- ci/build-macosx.sh
5466

5567
install:
56-
# Restore the Docker image from the cached directory. That way we
57-
# can reuse the steps in the Docker image that install
58-
# pre-requisites and build dependencies.
5968
- ci/install-linux.sh
6069

6170
after_success:

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ elseif ("${GOOGLE_CLOUD_CPP_GRPC_PROVIDER}" STREQUAL "package")
7979
include(FindPkgConfig)
8080
pkg_check_modules(GRPCPP REQUIRED grpc++>=1.4.1)
8181
pkg_check_modules(GRPC REQUIRED grpc>=4.0)
82-
pkg_check_modules(PROTOBUF REQUIRED protobuf>=3.0)
82+
pkg_check_modules(PROTOBUF REQUIRED protobuf>=3.4)
8383
link_directories(${GRPCPP_LIBRARY_DIRS} ${GRPC_LIBRARY_DIRS} ${PROTOBUF_LIBRARY_DIRS})
8484
endif ()
8585
# ... discover protoc and friends ...
@@ -100,8 +100,6 @@ elseif ("${GOOGLE_CLOUD_CPP_GRPC_PROVIDER}" STREQUAL "package")
100100
${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug
101101
)
102102
mark_as_advanced(PROTOC_GRPCPP_PLUGIN_EXECUTABLE)
103-
# googletest
104-
add_subdirectory(googletest EXCLUDE_FROM_ALL)
105103
endif ()
106104

107105
# Enable testing in this directory so we can do a top-level `make test`.

bigtable/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,21 @@ target_link_libraries(admin_integration_test
249249
bigtable_admin_client bigtable_client bigtable_protos absl::strings
250250
${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES})
251251
add_dependencies(tests-local admin_integration_test)
252+
253+
# Define the install target
254+
get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
255+
if ("${LIB64}" STREQUAL "TRUE")
256+
set(LIBSUFFIX 64)
257+
else()
258+
set(LIBSUFFIX "")
259+
endif()
260+
set(INSTALL_LIB_DIR lib${LIBSUFFIX} CACHE PATH "Installation directory for libraries")
261+
install(TARGETS bigtable_admin_client bigtable_client bigtable_protos
262+
RUNTIME DESTINATION bin
263+
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
264+
ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
265+
install(DIRECTORY client/ DESTINATION include/bigtable/client FILES_MATCHING PATTERN "*.h")
266+
install(DIRECTORY admin/ DESTINATION include/bigtable/admin FILES_MATCHING PATTERN "*.h")
267+
install(DIRECTORY ../third_party/abseil/absl DESTINATION include/bigtable FILES_MATCHING PATTERN "*.h")
268+
install(DIRECTORY ../third_party/abseil/absl DESTINATION include/bigtable FILES_MATCHING PATTERN "*.inc")
269+
install(DIRECTORY ${CMAKE_BINARY_DIR}/bigtable/google/ DESTINATION include/bigtable/google FILES_MATCHING PATTERN "*.h")

ci/Dockerfile.ubuntu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ FROM ubuntu:${DISTRO_VERSION}
1717
MAINTAINER "Carlos O'Ryan <coryan@google.com>"
1818

1919
RUN apt-get update && apt-get install -y \
20+
automake \
2021
build-essential \
2122
clang \
2223
cmake \
@@ -30,6 +31,7 @@ RUN apt-get update && apt-get install -y \
3031
graphviz \
3132
clang \
3233
cmake \
34+
libtool \
3335
lsb-release \
3436
make \
3537
tar \

ci/Dockerfile.ubuntu-with-grpc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2017 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG DISTRO=ubuntu
16+
ARG DISTRO_VERSION=16.04
17+
FROM cached-${DISTRO}-${DISTRO_VERSION}:tip AS staging
18+
MAINTAINER "Carlos O'Ryan <coryan@google.com>"
19+
20+
ARG NCPU=2
21+
ARG CXX=clang++
22+
ARG CC=clang
23+
24+
WORKDIR /var/tmp/build/
25+
RUN git clone --depth 50 https://github.com/grpc/grpc.git
26+
WORKDIR /var/tmp/build/grpc
27+
RUN git submodule update --init --recursive
28+
RUN (make -j "${NCPU}" HAS_SYSTEM_PROTOBUF=false && make install && \
29+
cd third_party/protobuf && make install)
30+
31+
FROM cached-${DISTRO}-${DISTRO_VERSION}:tip
32+
COPY --from=staging /usr/local/include /usr/local/include
33+
COPY --from=staging /usr/local/bin /usr/local/bin
34+
COPY --from=staging /usr/local/lib /usr/local/lib

ci/build-docker.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ fi
9797

9898
# If document generation is enabled, run it now.
9999
if [ "${GENERATE_DOCS}" = "yes" ]; then
100+
echo
101+
echo "Generating documentation from source files"
100102
(cd /v/bigtable ; doxygen doc/Doxyfile)
101103
fi
102104

@@ -108,6 +110,7 @@ if [ "${SCAN_BUILD:-}" = "yes" ]; then
108110
fi
109111
if [ -r scan-build-output/index.html ]; then
110112
cat <<_EOF_;
113+
111114
${COLOR_RED}
112115
scan-build detected errors. Please read the log for details. To
113116
run scan-build locally and examine the HTML output install and configure Docker,
@@ -120,6 +123,7 @@ ${COLOR_RESET}
120123
_EOF_
121124
exit 1
122125
else
126+
echo
123127
echo "${COLOR_GREEN}scan-build completed without errors.${COLOR_RESET}"
124128
fi
125129
fi

ci/build-linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ sudo docker run -it \
3232
--env CHECK_STYLE="${CHECK_STYLE:-}" \
3333
--env SCAN_BUILD="${SCAN_BUILD:-}" \
3434
--env GENERATE_DOCS="${GENERATE_DOCS:-}" \
35+
--env TEST_INSTALL="${TEST_INSTALL:-}" \
3536
--env CMAKE_FLAGS="${CMAKE_FLAGS:-}" \
3637
--env GOPATH=/var/tmp/build/cbt \
3738
--env TERM=${TERM:-dumb} \

ci/install-linux.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,4 @@ fi
3131
readonly IMAGE="cached-${DISTRO}-${DISTRO_VERSION}"
3232
sudo docker build -t "${IMAGE}:tip" \
3333
--build-arg DISTRO_VERSION="${DISTRO_VERSION}" \
34-
--build-arg CXX="${CXX}" \
35-
--build-arg CC="${CC}" \
36-
--build-arg NCPU="${NCPU:-2}" \
37-
--build-arg BUILD_TYPE="${BUILD_TYPE:-Release}" \
38-
--build-arg CHECK_STYLE="${CHECK_STYLE:-}" \
39-
--build-arg SCAN_BUILD="${SCAN_BUILD:-}" \
40-
--build-arg GENERATE_DOCS="${GENERATE_DOCS:-}" \
41-
--build-arg CMAKE_FLAGS="${CMAKE_FLAGS:-}" \
4234
-f "ci/Dockerfile.${DISTRO}" ci

cmake/IncludeAbseil.cmake

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,18 @@
1515
include(${PROJECT_SOURCE_DIR}/cmake/IncludeCctz.cmake)
1616
include(${PROJECT_SOURCE_DIR}/cmake/IncludeGMock.cmake)
1717

18-
set(GOOGLE_CLOUD_CPP_ABSEIL_PROVIDER "module" CACHE STRING "How to find the abseil libraries")
19-
set_property(CACHE GOOGLE_CLOUD_CPP_ABSEIL_PROVIDER PROPERTY STRINGS "module" "package")
18+
# Depending on how gRPC is used (module vs. package), the gtest target may be
19+
# already defined; if it is, we cannot redefine it.
20+
if (NOT TARGET gtest)
21+
include(${PROJECT_SOURCE_DIR}/cmake/IncludeGTest.cmake)
22+
endif ()
2023

21-
if ("${GOOGLE_CLOUD_CPP_ABSEIL_PROVIDER}" STREQUAL "module")
22-
if (NOT ABSEIL_ROOT_DIR)
23-
set(ABSEIL_ROOT_DIR ${PROJECT_SOURCE_DIR}/third_party/abseil)
24-
endif ()
25-
if (NOT EXISTS "${ABSEIL_ROOT_DIR}/CMakeLists.txt")
26-
message(ERROR "GOOGLE_CLOUD_CPP_ABSEIL_PROVIDER is \"module\" but ABSEIL_ROOT_DIR is wrong")
27-
endif ()
28-
add_subdirectory(${ABSEIL_ROOT_DIR} third_party/abseil EXCLUDE_FROM_ALL)
29-
set(ABSEIL_LIBRARIES abseil)
30-
set(ABSEIL_INCLUDE_DIRS ${ABSEIL_ROOT_DIR})
31-
elseif ("${GOOGLE_CLOUD_CPP_ABSEIL_PROVIDER}" STREQUAL "package")
32-
if (WIN32)
33-
# On Windows we will probably use the vcpkg port (github.com/Microsoft/vcpkg).
34-
message(ERROR "TODO() - configure abseil under Windows")
35-
else ()
36-
# Use pkg-config on Unix and macOS.
37-
include(FindPkgConfig)
38-
pkg_check_modules(ABSEIL REQUIRED abseil)
39-
link_directories(${ABSEIL_LIBRARY_DIRS})
40-
endif ()
24+
if (NOT ABSEIL_ROOT_DIR)
25+
set(ABSEIL_ROOT_DIR ${PROJECT_SOURCE_DIR}/third_party/abseil)
26+
endif ()
27+
if (NOT EXISTS "${ABSEIL_ROOT_DIR}/CMakeLists.txt")
28+
message(ERROR "expected a CMakeLists.txt in ABSEIL_ROOT_DIR.")
4129
endif ()
30+
add_subdirectory(${ABSEIL_ROOT_DIR} third_party/abseil EXCLUDE_FROM_ALL)
31+
set(ABSEIL_LIBRARIES abseil)
32+
set(ABSEIL_INCLUDE_DIRS ${ABSEIL_ROOT_DIR})

cmake/IncludeCctz.cmake

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,24 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
set(GOOGLE_CLOUD_CPP_CCTZ_PROVIDER "module" CACHE STRING "How to find the cctz libraries")
16-
set_property(CACHE GOOGLE_CLOUD_CPP_CCTZ_PROVIDER PROPERTY STRINGS "module" "package")
15+
# While the documentation is not clear as to whether cctz can be used as an
16+
# installed library, we only use it as part of Abseil, which is supposed to
17+
# be included as a module.
1718

18-
if ("${GOOGLE_CLOUD_CPP_CCTZ_PROVIDER}" STREQUAL "module")
19-
if (NOT CCTZ_ROOT_DIR)
20-
set(CCTZ_ROOT_DIR ${PROJECT_SOURCE_DIR}/third_party/cctz)
21-
endif ()
22-
if (NOT EXISTS "${CCTZ_ROOT_DIR}/CMakeLists.txt")
23-
message(ERROR "GOOGLE_CLOUD_CPP_CCTZ_PROVIDER is \"module\" but CCTZ_ROOT_DIR is wrong")
24-
endif ()
25-
# cctz will include the `CTest` module and always compile the cctz tests, we want to disable that. The only way is
26-
# to include the module first, disable the tests, and then include the cctz CMakeLists.txt files.
27-
include(CTest)
28-
set(BUILD_TESTING OFF)
29-
add_subdirectory(${CCTZ_ROOT_DIR} third_party/cctz EXCLUDE_FROM_ALL)
30-
set(CCTZ_LIBRARIES cctz)
31-
set(CCTZ_INCLUDE_DIRS ${CCTZ_ROOT_DIR}/absl)
32-
elseif ("${GOOGLE_CLOUD_CPP_CCTZ_PROVIDER}" STREQUAL "package")
33-
if (WIN32)
34-
# On Windows we will probably use the vcpkg port (github.com/Microsoft/vcpkg).
35-
message(ERROR "TODO() - configure cctz under Windows")
36-
else ()
37-
# Use pkg-config on Unix and macOS.
38-
include(FindPkgConfig)
39-
pkg_check_modules(CCTZ REQUIRED cctz)
40-
link_directories(${CCTZ_LIBRARY_DIRS})
41-
endif ()
19+
if (NOT CCTZ_ROOT_DIR)
20+
set(CCTZ_ROOT_DIR ${PROJECT_SOURCE_DIR}/third_party/cctz)
4221
endif ()
22+
23+
if (NOT EXISTS "${CCTZ_ROOT_DIR}/CMakeLists.txt")
24+
message(ERROR "expected a CMakeLists.txt in CCTZ_ROOT_DIR")
25+
endif ()
26+
27+
# cctz will include the `CTest` module and always compile the cctz tests, we
28+
# want to disable that. The only way is to include the module first, disable
29+
# the tests, and then include the cctz CMakeLists.txt files.
30+
include(CTest)
31+
set(BUILD_TESTING OFF)
32+
33+
add_subdirectory(${CCTZ_ROOT_DIR} third_party/cctz EXCLUDE_FROM_ALL)
34+
set(CCTZ_LIBRARIES cctz)
35+
set(CCTZ_INCLUDE_DIRS ${CCTZ_ROOT_DIR}/absl)

0 commit comments

Comments
 (0)