Skip to content

Commit

Permalink
Create a build with clang-tidy enabled. (googleapis#87)
Browse files Browse the repository at this point in the history
This fixes googleapis#22.  The clang-tidy build needs cmake >= 3.6 run at all, and cmake >= 3.8 to get the exit status used by the cmake builds.  Fedora 27 has all the right tools pre-built, so we use it there.  Also introduced a clang-tidy configuration that everybody can use in their own builds, and we can fine tune over time.
  • Loading branch information
coryan authored Dec 10, 2017
1 parent fbc267f commit 372b19e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 24 deletions.
21 changes: 21 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# Configure clang-tidy for this project.

# Disabled:
# -google-readability-namespace-comments the BIGTABLE_CLIENT_NS is a macro, and
# clang-tidy fails to match it against the initial value.
Checks: google-readability-*,modernize-*,readability-*,-google-readability-namespace-comments

# Enable most warnings as errors.
WarningsAsErrors: clang-*,google-*,modernize-*,readability-*,-readability-identifier-naming

CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ }
- { key: readability-identifier-naming.MacroDefinition, value: UPPER_CASE }
- { key: readability-identifier-naming.TemplateParameter, value: CamelCase }
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ matrix:
env: DISTRO=ubuntu DISTRO_VERSION=17.04 CHECK_STYLE=yes GENERATE_DOCS=yes
- os: linux
compiler: clang
env: DISTRO=ubuntu DISTRO_VERSION=16.04 SANITIZE_ADDRESS=yes BUILD_TYPE=Debug
env: DISTRO=ubuntu DISTRO_VERSION=16.04 BUILD_TYPE=Debug \
CMAKE_FLAGS=-DSANITIZE_ADDRESS=yes
- os: linux
compiler: clang
env: DISTRO=ubuntu DISTRO_VERSION=16.04 SANITIZE_UNDEFINED=yes BUILD_TYPE=Debug
env: DISTRO=ubuntu DISTRO_VERSION=16.04 BUILD_TYPE=Debug \
CMAKE_FLAGS=-DSANITIZE_UNDEFINED=yes
- os: linux
compiler: gcc
env: DISTRO=ubuntu DISTRO_VERSION=14.04 BUILD_TYPE=Coverage
Expand All @@ -38,6 +40,10 @@ matrix:
- os: osx
compiler: clang
if: type != pull_request
- os: linux
compiler: clang
env: DISTRO=fedora DISTRO_VERSION=27 BUILD_TYPE=Debug \
CMAKE_FLAGS=-DBIGTABLE_CLIENT_CLANG_TIDY=yes

script:
- ci/build-linux.sh
Expand Down
14 changes: 14 additions & 0 deletions bigtable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ endif()
# Include the functions to enable Clang sanitizers.
include(${PROJECT_SOURCE_DIR}/cmake/EnableSanitizers.cmake)

# Include support for clang-tidy if available
include(${PROJECT_SOURCE_DIR}/cmake/EnableClangTidy.cmake)

# We use abseil.io .
include_directories(${PROJECT_THIRD_PARTY_DIR}/abseil)

Expand Down Expand Up @@ -138,6 +141,17 @@ add_library(bigtable_data_api
target_link_libraries(bigtable_data_api googleapis ${GRPCPP_LIBRARIES}
${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES})

option(BIGTABLE_CLIENT_CLANG_TIDY
"If set compiles the Cloud Bigtable client with clang-tidy."
"")
if (CLANG_TIDY_EXE AND BIGTABLE_CLIENT_CLANG_TIDY)
message(STATUS "clang-tidy build enabled.")
set_target_properties(
bigtable_data_api PROPERTIES
CXX_CLANG_TIDY "${CLANG_TIDY_EXE}"
)
endif ()

# List the unit tests, then setup the targets and dependencies.
set(all_unit_tests
client/client_options_test.cc
Expand Down
7 changes: 2 additions & 5 deletions ci/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN dnf install -y \
automake \
c-ares-devel \
clang \
clang-tools-extra \
cmake \
curl \
dia \
Expand Down Expand Up @@ -54,11 +55,7 @@ ARG CC=gcc
ARG BUILD_TYPE=Debug
ARG CHECK_STYLE=""
ARG GENERATE_DOCS=""
ARG SANITIZE_ADDRESS=""
ARG SANITIZE_LEAKS=""
ARG SANITIZE_MEMORY=""
ARG SANITIZE_THREAD=""
ARG SANITIZE_UNDEFINED=""
ARG CMAKE_FLAGS=""

# We assume that this is running on a (clean-ish) checkout of
# google-cloud-cpp, including submodules, and copy the files to a
Expand Down
6 changes: 1 addition & 5 deletions ci/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ ARG CC=gcc
ARG BUILD_TYPE=Debug
ARG CHECK_STYLE=""
ARG GENERATE_DOCS=""
ARG SANITIZE_ADDRESS=""
ARG SANITIZE_LEAKS=""
ARG SANITIZE_MEMORY=""
ARG SANITIZE_THREAD=""
ARG SANITIZE_UNDEFINED=""
ARG CMAKE_FLAGS=""

# We assume that this is running on a (clean-ish) checkout of
# google-cloud-cpp, including submodules, and copy the files to a
Expand Down
8 changes: 1 addition & 7 deletions ci/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ set -eu
mkdir -p gccpp/build-output
cd gccpp/build-output

cmake -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
-DSANITIZE_ADDRESS="${SANITIZE_ADDRESS}" \
-DSANITIZE_LEAKS="${SANITIZE_LEAKS}" \
-DSANITIZE_MEMORY="${SANITIZE_MEMORY}" \
-DSANITIZE_THREAD="${SANITIZE_THREAD}" \
-DSANITIZE_UNDEFINED="${SANITIZE_UNDEFINED}" \
..
cmake -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${CMAKE_FLAGS:-} ..

make -j ${NCPU} all
make -j ${NCPU} test || ( cat Testing/Temporary/LastTest.log; exit 1 )
Expand Down
6 changes: 1 addition & 5 deletions ci/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,5 @@ sudo docker build -t "${IMAGE}:tip" \
--build-arg BUILD_TYPE="${BUILD_TYPE:-Release}" \
--build-arg CHECK_STYLE="${CHECK_STYLE:-}" \
--build-arg GENERATE_DOCS="${GENERATE_DOCS:-}" \
--build-arg SANITIZE_ADDRESS="${SANITIZE_ADDRESS:-}" \
--build-arg SANITIZE_LEAKS="${SANITIZE_LEAKS:-}" \
--build-arg SANITIZE_MEMORY="${SANITIZE_MEMORY:-}" \
--build-arg SANITIZE_THREAD="${SANITIZE_THREAD:-}" \
--build-arg SANITIZE_UNDEFINED="${SANITIZE_UNDEFINED:-}" \
--build-arg CMAKE_FLAGS="${CMAKE_FLAGS:-}" \
-f "ci/Dockerfile.${DISTRO}" .
32 changes: 32 additions & 0 deletions cmake/EnableClangTidy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if (${CMAKE_VERSION} VERSION_LESS "3.6")
message(STATUS "clang-tidy is not enabled because cmake version is too old")
else ()
if (${CMAKE_VERSION} VERSION_LESS "3.8")
message(WARNING "clang-tidy exit code ignored in this version of cmake")
endif ()
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)

if (NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else ()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
endif ()
endif ()

0 comments on commit 372b19e

Please sign in to comment.