Add Clang-tidy support

This commit is contained in:
asarium committed 2018-04-13 11:40:38 +02:00
1 parent 9f97ea909a
commit 7944eda1cb
19 files changed
+127 -47

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
---
Checks: 'bugprone-assert-side-effect'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
CheckOptions:
- key: bugprone-assert-side-effect.AssertMacros
value: 'assert,Assert,Assertion'
...
+12 -8
View File
@@ -3,7 +3,7 @@ sudo: required
dist: trusty
cache:
directories:
- $HOME/cmake
- $HOME/cmake-3.6
- $HOME/.ccache
addons:
apt:
@@ -86,15 +86,17 @@ matrix:
- g++-7
- *global_deps
- os: linux
env: CONFIGURATION="Debug" CC=clang-3.6 CXX=clang++-3.6
env: CONFIGURATION="Debug" CC=clang-4.0 CXX=clang++-4.0 CMAKE_OPTIONS="-DENABLE_CLANG_TIDY=ON -DCLANG_TIDY_EXE=/usr/bin/clang-tidy-4.0"
addons:
apt:
sources:
- llvm-toolchain-precise
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-4.0
- sourceline: 'ppa:beineri/opt-qt571-trusty'
packages:
- *global_deps
- clang-3.6
- clang-4.0
- clang-tidy-4.0
- libc++-dev
- os: osx
env: CONFIGURATION="Debug"
@@ -120,15 +122,17 @@ matrix:
- g++-7
- *global_deps
- os: linux
env: CONFIGURATION="Release" CC=clang-3.6 CXX=clang++-3.6
env: CONFIGURATION="Release" CC=clang-4.0 CXX=clang++-4.0 CMAKE_OPTIONS="-DENABLE_CLANG_TIDY=ON -DCLANG_TIDY_EXE=/usr/bin/clang-tidy-4.0"
addons:
apt:
sources:
- llvm-toolchain-precise
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-4.0
- sourceline: 'ppa:beineri/opt-qt571-trusty'
packages:
- *global_deps
- clang-3.6
- clang-4.0
- clang-tidy-4.0
- libc++-dev
- os: osx
env: CONFIGURATION="Release"
@@ -143,7 +147,7 @@ before_install:
- "./ci/travis/before_install.sh"
install:
- "./ci/travis/install.sh"
- export PATH=$HOME/cmake/bin:$PATH
- export PATH=$HOME/cmake-3.6/bin:$PATH
before_script:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then QT_ENV_SCRIPT=$(find /opt -name 'qt*-env.sh'); source $QT_ENV_SCRIPT; fi
- "./ci/travis/before_script.sh"
+2
View File
@@ -142,6 +142,8 @@ if(FSO_BUILD_APPIMAGE)
include(appimage)
endif()
include(clang-tidy)
# This includes source code for some tools, either used in the build or also for something else
ADD_SUBDIRECTORY(tools)
+2 -2
View File
@@ -20,7 +20,7 @@ if [ "$TRAVIS_OS_NAME" = "linux" ]; then
export CXXFLAGS
export CFLAGS
CMAKE="cmake -G Ninja -DFSO_FATAL_WARNINGS=ON"
CMAKE="cmake -G Ninja -DFSO_FATAL_WARNINGS=ON $CMAKE_OPTIONS"
if [ "$BUILD_DEPLOYMENT" = true ]; then
for config in $BUILD_CONFIGS
do
@@ -38,6 +38,6 @@ elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
if [ "$BUILD_DEPLOYMENT" = true ]; then
cmake -G "Xcode" -DFSO_FATAL_WARNINGS=ON -DFSO_INSTALL_DEBUG_FILES=ON -DCMAKE_INSTALL_PREFIX="/tmp/release" ..
else
cmake -G "Xcode" ..
cmake -G "Xcode" $CMAKE_OPTIONS ..
fi
fi
+5 -7
View File
@@ -4,16 +4,14 @@ set -ex
FILENAME=
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
if [ ! -d "$HOME/cmake/bin" ]; then
if [ ! -d "$HOME/cmake-3.6/bin" ]; then
# If the cache does not currently contain CMake then download and install it
FILENAME=cmake-3.4.3-Linux-x86_64
mkdir -p $HOME/cmake-3.6/
mkdir -p $HOME/cmake/
wget -O /tmp/cmake.tar.gz --no-check-certificate https://www.cmake.org/files/v3.4/$FILENAME.tar.gz
tar -xzf /tmp/cmake.tar.gz -C $HOME/cmake/ --strip-components=1
wget -O /tmp/cmake.tar.gz --no-check-certificate https://cmake.org/files/v3.6/cmake-3.6.0-Linux-x86_64.tar.gz
tar -xzf /tmp/cmake.tar.gz -C $HOME/cmake-3.6/ --strip-components=1
fi
export PATH=$HOME/cmake/bin:$PATH
export PATH=$HOME/cmake-3.6/bin:$PATH
cd $HOME
+37
View File
@@ -0,0 +1,37 @@
option(ENABLE_CLANG_TIDY "Enable source code checking using clang-tidy" OFF)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
function(enable_clang_tidy target)
# Not enabled in this configuration
endfunction()
if(NOT ENABLE_CLANG_TIDY)
return()
endif()
if(NOT EXISTS "${CLANG_TIDY_EXE}")
message(SEND_ERROR "clang-tidy: Could not find clang-tidy executable (value of variable is \"${CLANG_TIDY_EXE}\".")
return()
endif()
if(CMAKE_VERSION VERSION_LESS "3.6.0")
message(SEND_ERROR "Clang-tidy support requires CMake 3.6")
return()
endif()
message(STATUS "clang-tidy: Using \"${CLANG_TIDY_EXE}\"")
function(enable_clang_tidy target)
SET(TIDY_OPTIONS "${CLANG_TIDY_EXE}")
if(FSO_FATAL_WARNINGS)
set(TIDY_OPTIONS "${TIDY_OPTIONS};-warnings-as-errors=*")
endif()
set_target_properties(${target} PROPERTIES CXX_CLANG_TIDY "${TIDY_OPTIONS}")
endfunction()
+2
View File
@@ -37,6 +37,8 @@ TARGET_LINK_LIBRARIES(code PUBLIC compiler)
target_link_libraries(code PUBLIC md5)
enable_clang_tidy(code)
IF (FSO_USE_SPEECH)
find_package(Speech REQUIRED)
target_link_libraries(code PUBLIC speech)
+8
View File
@@ -75,3 +75,11 @@
#else
#define FALLTHROUGH
#endif
#ifndef CLANG_ANALYZER_NORETURN
#if __has_feature(attribute_analyzer_noreturn)
#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
#else
#define CLANG_ANALYZER_NORETURN
#endif
#endif
+5
View File
@@ -58,3 +58,8 @@
* Some compilers issue a warning if a fallthrough is detected. This define can be used to suppress that warning.
*/
#define FALLTHROUGH
/**
* @brief Specifies that an analyzer should consider this function as no-return
*/
#define CLANG_ANALYZER_NORETURN
+2
View File
@@ -72,3 +72,5 @@
#else
#define FALLTHROUGH
#endif
#define CLANG_ANALYZER_NORETURN
+2
View File
@@ -69,3 +69,5 @@
#else
#define FALLTHROUGH
#endif
#define CLANG_ANALYZER_NORETURN
+2
View File
@@ -87,3 +87,5 @@
#define USED_VARIABLE
#define FALLTHROUGH
#define CLANG_ANALYZER_NORETURN
+6 -4
View File
@@ -51,8 +51,9 @@ namespace os
* @param linenum The source code line number where this function was called
* @param format An optional message to display in addition to the specified text
*/
void AssertMessage(const char* text, const char* filename, int linenum,
SCP_FORMAT_STRING const char* format = nullptr, ...) SCP_FORMAT_STRING_ARGS(4, 5);
void AssertMessage(const char* text, const char* filename, int linenum, SCP_FORMAT_STRING
const char* format = nullptr, ...)
SCP_FORMAT_STRING_ARGS(4, 5) CLANG_ANALYZER_NORETURN;
/**
* @brief Shows a lua error.
@@ -72,7 +73,8 @@ namespace os
* @param line The source code line number where this function was called
* @param format The error message to display (a format string)
*/
void Error(const char* filename, int line, SCP_FORMAT_STRING const char* format, ...) SCP_FORMAT_STRING_ARGS(3, 4);
void Error(const char* filename, int line, SCP_FORMAT_STRING const char* format, ...)
SCP_FORMAT_STRING_ARGS(3, 4) CLANG_ANALYZER_NORETURN;
/**
* @brief Shows an error dialog.
@@ -80,7 +82,7 @@ namespace os
*
* @param text The text to display
*/
void Error(const char* text);
void Error(const char* text) CLANG_ANALYZER_NORETURN;;
/**
* @brief Shows a warning dialog.
+2
View File
@@ -180,6 +180,8 @@ TARGET_LINK_LIBRARIES(FRED2 PUBLIC "$<$<CONFIG:Release>:nafxcw.lib>")
target_link_libraries(FRED2 PUBLIC glad_wgl)
enable_clang_tidy(FRED2)
INSTALL(
TARGETS FRED2
RUNTIME DESTINATION ${BINARY_DESTINATION}
+2
View File
@@ -59,6 +59,8 @@ if (FSO_INSTALL_DEBUG_FILES)
endif()
endif()
enable_clang_tidy(Freespace2)
INCLUDE(util)
COPY_FILES_TO_TARGET(Freespace2)
+2
View File
@@ -68,6 +68,8 @@ INSTALL(
)
COPY_FILES_TO_TARGET(qtfred)
enable_clang_tidy(qtfred)
if (WIN32)
set(additional_dlls
)
-1
View File
@@ -83,7 +83,6 @@ int main(int argc, char* argv[]) {
SCP_mspdbcs_Initialise();
#endif
Q_INIT_RESOURCE(resources);
qInstallMessageHandler(fsoMessageOutput);
SDL_SetMainReady();
+2
View File
@@ -11,5 +11,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
FOLDER "Tools"
)
enable_clang_tidy(embedfile)
EXPORT(TARGETS embedfile FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake)
ENDIF(NOT CMAKE_CROSSCOMPILING)
+24 -25
View File
@@ -128,38 +128,37 @@ void do_text_content(std::ifstream& file_in, std::ofstream& file_out,
while (pos < file_content.length()) {
const char* found_ptr = strpbrk(str + pos, escapeCharacters);
if (!found_ptr) {
if (found_ptr == nullptr) {
file_out.write(str + pos, file_content.length() - pos);
break;
}
else {
size_t found_pos = (size_t) (found_ptr - str);
size_t delta = found_pos - pos;
size_t found_pos = (size_t) (found_ptr - str);
if (delta != 0) {
file_out.write(str + pos, delta);
}
size_t delta = found_pos - pos;
switch (str[found_pos]) {
case '\\':
file_out << "\\\\";
break;
case '\n':
file_out << "\\n\"" << std::endl << "\"";
break;
case '"':
file_out << "\\\"";
break;
case '\r':
// Discard this character, possibly breaks on mac but whatever...
break;
default:
std::cout << "ERROR: Invalid character encountered!" << std::endl;
}
pos = found_pos + 1;
if (delta != 0) {
file_out.write(str + pos, delta);
}
switch (str[found_pos]) {
case '\\':
file_out << "\\\\";
break;
case '\n':
file_out << "\\n\"" << std::endl << "\"";
break;
case '"':
file_out << "\\\"";
break;
case '\r':
// Discard this character, possibly breaks on mac but whatever...
break;
default:
std::cout << "ERROR: Invalid character encountered!" << std::endl;
}
pos = found_pos + 1;
}
file_out << "\";" << std::endl;