Skip to content

Commit

Permalink
Merge support iwyu and clang-tidy
Browse files Browse the repository at this point in the history
Add support for clang-tidy [1] and iwyu [2] tools.

### Overview
These tools allow to statically find potential programming issues and include
issues, respectively. They are able to find a lot of potential issues (both bugs
or style problems), so they are a useful addition for contributors. For now, no
specific configuration is included but it is possible to give a style file which
would control what we consider to be errors and what are not.

The use of the tools is controlled through the respective `GINKGO_WITH_CLANG_TIDY`
and `GINKGO_WITH_IWYU` variables. They are turned off by default, but their
availability is highlighted in the main `README.md`

[1]: https://clang.llvm.org/extra/clang-tidy/
[2]: https://include-what-you-use.org/

### Details
+ Fix some unrelated link problems in the main `README.md`.
+ The two programs are found through CMake `find_program`. This means that the path can be directly given for `iwyu` and `clang-tidy` through the variables `GINKGO_IWYU_PATH=/path/to/iwyu` and `GINKGO_CLANG_TIDY_PATH=/path/to/clang-tidy`, respectively.
+ Adapt containers to bundle a correct version of `iwyu` and `clang-tidy`. There are often problems with standard C headers for these tools and this can be fixed either through adding symlinks or through correct compilation. See [this link for more information](include-what-you-use/include-what-you-use#679).
+ Add CI steps which gather the full `iwyu` and `clang-tidy` output


### Related PR: #298
  • Loading branch information
tcojean committed May 6, 2019
2 parents 75806c2 + 9ce23ab commit 2d3f031
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 12 deletions.
24 changes: 24 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,30 @@ no-circular-deps:
dependencies: []
allow_failure: no

# Run clang-tidy and iwyu
clang-tidy:
<<: *default_build
stage: code_quality
image: localhost:5000/gko-cuda100-gnu7-llvm60
variables:
<<: *default_variables
BUILD_OMP: "ON"
BUILD_CUDA: "ON"
EXTRA_CMAKE_FLAGS: '-DGINKGO_WITH_CLANG_TIDY=ON'
dependencies: []
allow_failure: yes

iwyu:
<<: *default_build
stage: code_quality
image: localhost:5000/gko-cuda100-gnu7-llvm60
variables:
<<: *default_variables
BUILD_OMP: "ON"
BUILD_CUDA: "ON"
EXTRA_CMAKE_FLAGS: '-DGINKGO_WITH_IWYU=ON'
dependencies: []
allow_failure: yes

# Deploy documentation to github-pages
gh-pages:
Expand Down
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ include(cmake/create_test.cmake)
include(cmake/install_helpers.cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

include(cmake/build_type_helpers.cmake)

# Ginkgo configuration options
option(GINKGO_DEVEL_TOOLS "Add development tools to the build system" ON)
option(GINKGO_BUILD_TESTS "Generate build files for unit tests" ON)
Expand All @@ -26,6 +24,8 @@ option(GINKGO_SKIP_DEPENDENCY_UPDATE
option(GINKGO_EXPORT_BUILD_DIR
"Make Ginkgo export its build directory to the CMake package registry."
OFF)
option(GINKGO_WITH_CLANG_TIDY "Make Ginkgo call `clang-tidy` to find programming issues." OFF)
option(GINKGO_WITH_IWYU "Make Ginkgo call `iwyu` (Include What You Use) to find include issues." OFF)
set(GINKGO_VERBOSE_LEVEL "1" CACHE STRING
"Verbosity level. Put 0 to turn off. 1 activates a few important messages.")
set(GINKGO_COMPILER_FLAGS "-Wpedantic" CACHE STRING
Expand All @@ -49,7 +49,7 @@ endif()

# Ensure we have a debug postfix
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_DEBUG_POSTFIX "d")
endif()

if(GINKGO_BUILD_TESTS)
Expand All @@ -62,6 +62,17 @@ if(GINKGO_BUILD_TESTS)
include(CTest)
endif()

if (GINKGO_WITH_CLANG_TIDY)
find_program(GINKGO_CLANG_TIDY_PATH clang-tidy)
endif()

if (GINKGO_WITH_IWYU)
find_program(GINKGO_IWYU_PATH iwyu)
endif()


include(cmake/build_type_helpers.cmake)


# Find important header files, store the definitions in include/ginkgo/config.h.in
# For details, see https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-To-Write-Platform-Checks
Expand Down
6 changes: 6 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ Ginkgo adds the following additional switches to control what is being built:
Ginkgo's documentation. The default is `OFF`.
* `-DGINKGO_EXPORT_BUILD_DIR={ON, OFF}` adds the Ginkgo build directory to the
CMake package registry. The default is `OFF`.
* `-DGINKGO_WITH_CLANG_TIDY={ON, OFF}` makes Ginkgo call `clang-tidy` to find
programming issues. The path can be manually controlled with the CMake
variable `-DGINKGO_CLANG_TIDY_PATH=<path>`.
* `-DGINKGO_WITH_IWYU={ON, OFF}` makes Ginkgo call `iwyu` to find include
issues. The path can be manually controlled with the CMake variable
`-DGINKGO_IWYU_PATH=<path>`.
* `-DGINKGO_VERBOSE_LEVEL=integer` sets the verbosity of Ginkgo.
* `0` disables all output in the main libraries,
* `1` enables a few important messages related to unexpected behavior (default).
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Coverage](https://codecov.io/gh/ginkgo-project/ginkgo/branch/develop/graph/badge.svg)](https://codecov.io/gh/ginkgo-project/ginkgo)
[![CDash dashboard](https://img.shields.io/badge/CDash-Access-blue.svg)](http://my.cdash.org/index.php?project=Ginkgo+Project)
[![Documentation](https://img.shields.io/badge/Documentation-latest-blue.svg)](https://ginkgo-project.github.io/ginkgo/doc/develop/)
[![License](https://img.shields.io/github/license/ginkgo-project/ginkgo.svg)](LICENSE)
[![License](https://img.shields.io/github/license/ginkgo-project/ginkgo.svg)](./LICENSE)
[![c++ standard](https://img.shields.io/badge/c%2B%2B-11-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization)

Ginkgo is a high-performance linear algebra library for manycore systems, with a
Expand Down Expand Up @@ -48,6 +48,8 @@ In addition, if you want to contribute code to Ginkgo, you will also need the
following:

* _clang-format 5.0.1+_ (ships as part of _clang_)
* _clang-tidy_ (optional, when setting the flag `-DGINKGO_WITH_CLANG_TIDY=ON`)
* _iwyu_ (Include What You Use, optional, when setting the flag `-DGINKGO_WITH_IWYU=ON`)

### Windows

Expand Down Expand Up @@ -91,7 +93,7 @@ Ginkgo does comprehensive unit tests using Google Tests. These tests are enabled
A unique feature of Ginkgo is the ability to run benchmarks and view your results
with the help of the [Ginkgo Performance Explorer (GPE)](https://ginkgo-project.github.io/gpe/).

More details about this can be found in the [documentation](https://ginkgo-project.github.io/ginkgo/doc/master/)
More details about this can be found in the [BENCHMARKING.md page](./BENCHMARKING.md)

Contributing to Ginkgo
---------------------------
Expand All @@ -103,7 +105,7 @@ external contributors like in the example below.

#### Contributors
I hereby place all my contributions in this codebase under a BSD-3-Clause
license, as specified in the repository's [LICENSE](LICENSE) file.
license, as specified in the repository's [LICENSE](./LICENSE) file.

Name Surname <email@domain> Institution(s)

Expand Down
5 changes: 5 additions & 0 deletions cmake/GinkgoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ set(GINKGO_SKIP_DEPENDENCY_UPDATE @GINKGO_SKIP_DEPENDENCY_UPDATE@)
set(GINKGO_EXPORT_BUILD_DIR @GINKGO_EXPORT_BUILD_DIR@)
set(GINKGO_VERBOSE_LEVEL @GINKGO_VERBOSE_LEVEL@)

set(GINKGO_WITH_CLANG_TIDY @GINKGO_WITH_CLANG_TIDY@)
set(GINKGO_WITH_IWYU @GINKGO_WITH_IWYU@)
set(GINKGO_CLANG_TIDY_PATH @GINKGO_CLANG_TIDY_PATH@)
set(GINKGO_IWYU_PATH @GINKGO_IWYU_PATH@)

set(GINKGO_JACOBI_FULL_OPTIMIZATIONS @GINKGO_JACOBI_FULL_OPTIMIZATIONS@)

set(GINKGO_CUDA_ARCHITECTURES @GINKGO_CUDA_ARCHITECTURES@)
Expand Down
6 changes: 6 additions & 0 deletions cmake/build_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ endfunction()

function(ginkgo_compile_features name)
target_compile_features("${name}" PUBLIC cxx_std_11)
if(GINKGO_WITH_CLANG_TIDY AND GINKGO_CLANG_TIDY_PATH)
set_property(TARGET "${name}" PROPERTY CXX_CLANG_TIDY "${GINKGO_CLANG_TIDY_PATH};-checks=*")
endif()
if(GINKGO_WITH_IWYU AND GINKGO_IWYU_PATH)
set_property(TARGET "${name}" PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${GINKGO_IWYU_PATH})
endif()
endfunction()
Binary file added dev_tools/containers/bin/include-what-you-use
Binary file not shown.
17 changes: 16 additions & 1 deletion dev_tools/containers/ginkgo-cuda-base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
Contents:
CUDA version set by the user
GNU compilers version set by the user
LLVM/Clang version set by the user
LLVM/Clang clang-tidy version set by the user
OpenMP latest apt version for Clang+OpenMP
Python 2 and 3 (upstream)
cmake (upstream)
git, openssh, doxygen, curl, valgrind, graphviz latest apt version
iwyu precompiled version 6.0
"""
# pylint: disable=invalid-name, undefined-variable, used-before-assignment

import os

cuda_version = USERARG.get('cuda', '10.0')

image = 'nvidia/cuda:{}-devel-ubuntu16.04'.format(cuda_version)
Expand All @@ -21,6 +24,7 @@
Stage0 += python()
Stage0 += cmake(eula=True)
Stage0 += apt_get(ospackages=['git', 'openssh-client', 'doxygen', 'curl', 'valgrind', 'graphviz'])
Stage0 += apt_get(ospackages=['iwyu'])

# GNU compilers
gnu_version = USERARG.get('gnu', '7')
Expand All @@ -31,6 +35,17 @@
Stage0 += llvm(version=llvm_version, extra_repository=True)
Stage0 += apt_get(ospackages=['libomp-dev']) #required for openmp+clang

# clang-tidy
clangtidy = ['clang-tidy-{}'.format(llvm_version)]
Stage0 += packages(apt_ppas=['ppa:xorg-edgers/ppa'], apt=clangtidy)
clangtidyln = ['ln -s /usr/bin/clang-tidy-{} /usr/bin/clang-tidy'.format(llvm_version)]
Stage0 += shell(commands=clangtidyln)

# IWYU
if os.path.isdir('bin/'):
Stage0 += copy(src='bin/*', dest='/usr/bin/')


# Correctly set the LIBRARY_PATH
Stage0 += environment(variables={'LIBRARY_PATH': '/usr/local/cuda/lib64/stubs'})
Stage0 += environment(variables={'LD_LIBRARY_PATH': '/usr/local/cuda/lib64/stubs'})
Expand Down
2 changes: 2 additions & 0 deletions dev_tools/containers/ginkgo-nocuda-base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
build-essential, git, openssh, doxygen, curl, valgrind latest apt version
graphviz, ghostscript, texlive, texlive-latex-extra, latest apt version
texlive-science, texlive-fonts-extra, texlive-publishers latest apt version
clang-tidy, iwyu: latest apt version
papi: adds package libpfm4, and copy precompiled papi headers and files
from a directory called 'papi'
"""
Expand All @@ -25,6 +26,7 @@
Stage0 += apt_get(ospackages=['build-essential', 'git', 'openssh-client', 'doxygen', 'curl', 'valgrind'])
Stage0 += apt_get(ospackages=['graphviz', 'ghostscript', 'texlive', 'texlive-latex-extra'])
Stage0 += apt_get(ospackages=['texlive-science', 'texlive-fonts-extra', 'texlive-publishers'])
Stage0 += apt_get(ospackages=['clang-tidy', 'iwyu'])

# GNU compilers
gnu_version = USERARG.get('gnu', '8')
Expand Down
17 changes: 17 additions & 0 deletions dev_tools/containers/gko-cuda100-gnu7-llvm60.baseimage
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ RUN apt-get update -y && \
graphviz && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
iwyu && \
rm -rf /var/lib/apt/lists/*

# GNU compiler
RUN apt-get update -y && \
apt-get install -y --no-install-recommends software-properties-common && \
Expand Down Expand Up @@ -53,6 +58,18 @@ RUN apt-get update -y && \
libomp-dev && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update -y && \
apt-get install -y --no-install-recommends software-properties-common && \
apt-add-repository ppa:xorg-edgers/ppa -y && \
apt-get update -y && \
apt-get install -y --no-install-recommends \
clang-tidy-6.0 && \
rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/clang-tidy-6.0 /usr/bin/clang-tidy

COPY bin/* /usr/bin/

ENV LIBRARY_PATH=/usr/local/cuda/lib64/stubs

ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64/stubs
Expand Down
17 changes: 17 additions & 0 deletions dev_tools/containers/gko-cuda90-gnu5-llvm39.baseimage
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ RUN apt-get update -y && \
graphviz && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
iwyu && \
rm -rf /var/lib/apt/lists/*

# GNU compiler
RUN apt-get update -y && \
apt-get install -y --no-install-recommends software-properties-common && \
Expand Down Expand Up @@ -53,6 +58,18 @@ RUN apt-get update -y && \
libomp-dev && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update -y && \
apt-get install -y --no-install-recommends software-properties-common && \
apt-add-repository ppa:xorg-edgers/ppa -y && \
apt-get update -y && \
apt-get install -y --no-install-recommends \
clang-tidy-3.9 && \
rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/clang-tidy-3.9 /usr/bin/clang-tidy

COPY bin/* /usr/bin/

ENV LIBRARY_PATH=/usr/local/cuda/lib64/stubs

ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64/stubs
Expand Down
17 changes: 17 additions & 0 deletions dev_tools/containers/gko-cuda91-gnu6-llvm40.baseimage
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ RUN apt-get update -y && \
graphviz && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
iwyu && \
rm -rf /var/lib/apt/lists/*

# GNU compiler
RUN apt-get update -y && \
apt-get install -y --no-install-recommends software-properties-common && \
Expand Down Expand Up @@ -53,6 +58,18 @@ RUN apt-get update -y && \
libomp-dev && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update -y && \
apt-get install -y --no-install-recommends software-properties-common && \
apt-add-repository ppa:xorg-edgers/ppa -y && \
apt-get update -y && \
apt-get install -y --no-install-recommends \
clang-tidy-4.0 && \
rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/clang-tidy-4.0 /usr/bin/clang-tidy

COPY bin/* /usr/bin/

ENV LIBRARY_PATH=/usr/local/cuda/lib64/stubs

ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64/stubs
Expand Down
17 changes: 17 additions & 0 deletions dev_tools/containers/gko-cuda92-gnu7-llvm50.baseimage
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ RUN apt-get update -y && \
graphviz && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
iwyu && \
rm -rf /var/lib/apt/lists/*

# GNU compiler
RUN apt-get update -y && \
apt-get install -y --no-install-recommends software-properties-common && \
Expand Down Expand Up @@ -53,6 +58,18 @@ RUN apt-get update -y && \
libomp-dev && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update -y && \
apt-get install -y --no-install-recommends software-properties-common && \
apt-add-repository ppa:xorg-edgers/ppa -y && \
apt-get update -y && \
apt-get install -y --no-install-recommends \
clang-tidy-5.0 && \
rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/clang-tidy-5.0 /usr/bin/clang-tidy

COPY bin/* /usr/bin/

ENV LIBRARY_PATH=/usr/local/cuda/lib64/stubs

ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64/stubs
Expand Down
7 changes: 2 additions & 5 deletions dev_tools/containers/gko-nocuda-gnu8-llvm70.baseimage
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ RUN apt-get update -y && \

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
texlive \
texlive-latex-extra \
texlive-science \
texlive-fonts-extra \
texlive-publishers && \
clang-tidy \
iwyu && \
rm -rf /var/lib/apt/lists/*

# GNU compiler
Expand Down

0 comments on commit 2d3f031

Please sign in to comment.