Skip to content

Commit

Permalink
Feature adds iwyu (#27)
Browse files Browse the repository at this point in the history
* makes check rules compatible with clang debugger

* adds iwyu scripts

* update mapping for boost

* fix iwyu parsing
  • Loading branch information
psycofdj committed Sep 4, 2017
1 parent 7044d63 commit 29c713f
Show file tree
Hide file tree
Showing 26 changed files with 14,844 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/XTDMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/check")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/coverage")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/memcheck")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/codedup")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/iwyu")

include(CMakeParseArguments)
include(xtdmake_lang)
Expand All @@ -28,7 +29,7 @@ message(STATUS "Found module XTDMake : TRUE")

function(xtdmake_init project dir)
set(multiValueArgs )
set(oneValueArgs StaticShared DocRule DocCoverageRule CppcheckRule ClocRule Tracking Cppunit CheckRule CovRule MemcheckRule CodeDupRule Reports)
set(oneValueArgs StaticShared DocRule DocCoverageRule CppcheckRule ClocRule Tracking Cppunit CheckRule CovRule MemcheckRule CodeDupRule IwyuRule Reports)
set(options )
cmake_parse_arguments(__x
"${options}"
Expand Down
11 changes: 9 additions & 2 deletions src/check/FindCheckRule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ xtdmake_find_program(Xsltproc
URL "http://xmlsoft.org/"
VERSION_OPT " --version | head -n1 | cut -d' ' -f3 | sed 's/,//g'"
VERSION_POS "0"
REQUIRED CheckRule_FIND_REQUIRED)
REQUIRED ${CheckRule_FIND_REQUIRED})

if (NOT Xsltproc_FOUND)
set(CheckRule_FOUND 0)
Expand Down Expand Up @@ -189,8 +189,15 @@ function(add_check module)
add_custom_target(${module}-check-ut-${c_name_clean}
COMMAND ${CheckRule_ENV} ./${c_name_clean} ${CheckRule_ARGS}
DEPENDS ${c_name_clean})

if (USE_CLANG)
set(l_cmd ${CheckRule_ENV} lldb -o run ${c_name_clean} -- ${CheckRule_ARGS} ${CheckRule_DBG_ARGS})
else()
set(l_cmd ${CheckRule_ENV} gdb -ex run --args ${c_name_clean} ${CheckRule_ARGS} ${CheckRule_DBG_ARGS})
endif()

add_custom_target(${module}-check-ut-${c_name_clean}-gdb
COMMAND ${CheckRule_ENV} gdb -ex run --args ${c_name_clean} ${CheckRule_ARGS} ${CheckRule_DBG_ARGS}
COMMAND ${l_cmd}
DEPENDS ${c_name_clean})
add_custom_target(${module}-check-ut-${c_name_clean}-cmd
COMMAND echo ${CheckRule_ENV} ${CMAKE_CURRENT_BINARY_DIR}/${c_name_clean} ${CheckRule_ARGS})
Expand Down
4 changes: 2 additions & 2 deletions src/cloc/FindClocRule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ xtdmake_find_program(Cloc
URL "http://cloc.sourceforge.net/"
VERSION_OPT "--version"
VERSION_POS "0"
REQUIRED ClocRule_FIND_REQUIRED)
REQUIRED ${ClocRule_FIND_REQUIRED})

xtdmake_find_program(Xsltproc
NAMES xsltproc
DOC "rendering xslt stylehseets"
URL "http://xmlsoft.org/"
VERSION_OPT " --version | head -n1 | cut -d' ' -f3 | sed 's/,//g'"
VERSION_POS "0"
REQUIRED ClocRule_FIND_REQUIRED)
REQUIRED ${ClocRule_FIND_REQUIRED})

if (NOT Cloc_FOUND OR NOT Xsltproc_FOUND)
set(ClocRule_FOUND 0)
Expand Down
4 changes: 2 additions & 2 deletions src/coverage/FindCovRule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ xtdmake_find_program(Lcov
NAMES lcov
DOC "code coverage generation tool"
URL "http://ltp.sourceforge.net/coverage/lcov.php"
REQUIRED CovRule_FIND_REQUIRED
REQUIRED ${CovRule_FIND_REQUIRED}
VERSION_OPT "--version"
VERSION_POS 3)

xtdmake_find_program(Genhtml
NAMES genhtml
DOC "Html report generation tool"
URL "http://ltp.sourceforge.net/coverage/lcov.php"
REQUIRED CovRule_FIND_REQUIRED
REQUIRED ${CovRule_FIND_REQUIRED}
VERSION_OPT "--version"
VERSION_POS 3)

Expand Down
4 changes: 2 additions & 2 deletions src/cppcheck/FindCppcheckRule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ xtdmake_find_program(Cppcheck
NAMES cppcheck
DOC "cppcheck static code anylyser tool"
URL "http://cppcheck.sourceforge.net/"
REQUIRED CppcheckRule_FIND_REQUIRED
REQUIRED ${CppcheckRule_FIND_REQUIRED}
VERSION_OPT "--version"
VERSION_POS 1)

Expand All @@ -15,7 +15,7 @@ xtdmake_find_program(Xsltproc
URL "http://xmlsoft.org/"
VERSION_OPT " --version | head -n1 | cut -d' ' -f3 | sed 's/,//g'"
VERSION_POS "0"
REQUIRED CppcheckRule_FIND_REQUIRED)
REQUIRED ${CppcheckRule_FIND_REQUIRED})

if (NOT Xsltproc_FOUND)
set(CppcheckRule_FOUND 0)
Expand Down
4 changes: 2 additions & 2 deletions src/doc-coverage/FindDocCoverageRule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ xtdmake_find_program(Genhtml
NAMES genhtml
DOC "Html report generation tool"
URL "http://ltp.sourceforge.net/coverage/lcov.php"
REQUIRED DocCoverageRule_FIND_REQUIRED
REQUIRED ${DocCoverageRule_FIND_REQUIRED}
VERSION_OPT "--version"
VERSION_POS 3)

Expand All @@ -14,7 +14,7 @@ xtdmake_find_python_module(Coverxygen
INTERPRETERS python3 python
DOC "Tool to generate coverage report from Doxygen documentation"
URL "https://github.com/psycofdj/coverxygen"
REQUIRED DocCoverageRule_FIND_REQUIRED
REQUIRED ${DocCoverageRule_FIND_REQUIRED}
VERSION_MEMBER "__version__"
VERSION_POS 0)

Expand Down
11 changes: 11 additions & 0 deletions src/interface/FindReports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ if (CodeDupRule_FOUND)
VERBATIM)
endif()

if (IwyuRule_FOUND)
add_custom_command(TARGET iwyu
POST_BUILD
COMMAND $(MAKE) reports-update
VERBATIM)
add_custom_command(TARGET iwyu-clean
POST_BUILD
COMMAND $(MAKE) reports-update
VERBATIM)
endif()


if (CheckRule_FOUND)
add_custom_command(TARGET check
Expand Down
134 changes: 134 additions & 0 deletions src/iwyu/FindIwyuRule.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
add_custom_target(iwyu)
add_custom_target(iwyu-clean)

xtdmake_find_program(Iwyu
NAMES include-what-you-use
DOC "Include-what-you-use header analyzer"
URL "https://include-what-you-use.org/"
REQUIRED ${IwyuRule_FIND_REQUIRED}
VERSION_OPT "--version | cut -d' ' -f2"
VERSION_POS 0)

xtdmake_find_python_module(Mako
NAME mako
INTERPRETERS python3 python
DOC "Library to generate template in python"
URL "http://www.makotemplates.org/"
REQUIRED ${IwyuRule_FIND_REQUIRED}
VERSION_MEMBER "__version__"
VERSION_POS 0)


set(IwyuRule_FOUND 0)
if (NOT CMAKE_EXPORT_COMPILE_COMMANDS)
message(STATUS "Found module IwyuRule_FOUND : FALSE (CMAKE_EXPORT_COMPILE_COMMANDS is mandatory)")
if (IwyuRule_FIND_REQUIRED)
message(FATAL_ERROR "Unable to find compile commands")
endif()
endif()
set(IwyuRule_FOUND 1)

set(IwyuRule_DEFAULT_EXCLUDE_PATTERN "\${CMAKE_CURRENT_SOURCE_DIR}/unit/*" CACHE STRING "IwyuRule default pattern to exclude source from analysis")
set(IwyuRule_DEFAULT_JOBS "4" CACHE STRING "IwyuRule default number of concurrent jobs")
set(IwyuRule_DEFAULT_MAPPING "\${XTDMake_HOME}/iwyu/mapping.imp" CACHE STRING "IwyuRule default mapping file")
set(IwyuRule_DEFAULT_VERBOSE "FALSE" CACHE STRING "IwyuRule default verbose status")
set(IwyuRule_DEFAULT_COMMENTS "FALSE" CACHE STRING "IwyuRule default comments status")

if (NOT IwyuRule_FOUND)
function(add_iwyu module)
add_custom_target(${module}-iwyu
COMMAND echo "warning: iwyu rule is disabled due to missing dependencies")
add_custom_target(${module}-iwyu-clean
COMMAND echo "warning: iwyu rule is disabled due to missing dependencies")
add_dependencies(iwyu ${module}-iwyu)
add_dependencies(iwyu-clean ${module}-iwyu-clean)
endfunction()
else()
function(add_iwyu module)
set(multiValueArgs DEPENDS)
set(oneValueArgs EXCLUDE_PATTERN JOBS MAPPING)
set(options VERBOSE COMMENTS)
cmake_parse_arguments(IwyuRule
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN})

xtdmake_set_default(IwyuRule EXCLUDE_PATTERN)
xtdmake_set_default(IwyuRule JOBS)
xtdmake_set_default(IwyuRule VERBOSE)
xtdmake_set_default(IwyuRule MAPPING)
xtdmake_set_default(IwyuRule COMMENTS)

set(IwyuRule_OUTPUT "${PROJECT_BINARY_DIR}/reports/iwyu/${module}")
set(IwyuRule_DEPENDS ${IwyuRule_DEPENDS})
set(l_args "")

if ("${IwyuRule_VERBOSE}" STREQUAL "TRUE" OR "${IwyuRule_DEFAULT_VERBOSE}" STREQUAL "TRUE")
list(APPEND l_args "--verbose")
endif()

if ("${IwyuRule_COMMENTS}" STREQUAL "FALSE" AND "${IwyuRule_DEFAULT_COMMENTS}" STREQUAL "FALSE")
list(APPEND l_args "-Xiwyu")
list(APPEND l_args "--no_comments")
else()
list(APPEND l_args "-Xiwyu")
list(APPEND l_args "--max_line_length=300")
endif()

if (NOT "${IwyuRule_MAPPING}" STREQUAL "")
list(APPEND l_args "-Xiwyu")
list(APPEND l_args "--mapping_file=${IwyuRule_MAPPING}")
list(APPEND IwyuRule_DEPENDS "${IwyuRule_MAPPING}")
endif()

add_custom_command(
COMMENT "Generating ${module} iwyu JSON reports"
OUTPUT
${IwyuRule_OUTPUT}/iwyu.json
DEPENDS
${IwyuRule_DEPENDS}
${XTDMake_HOME}/iwyu/analyze.py
${XTDMake_HOME}/iwyu/FindIwyuRule.cmake

COMMAND mkdir -p ${IwyuRule_OUTPUT}
COMMAND ${XTDMake_HOME}/iwyu/analyze.py
--build-dir "${CMAKE_CURRENT_BINARY_DIR}"
--commands "${CMAKE_BINARY_DIR}/compile_commands.json"
--iwyu-bin "${Iwyu_EXECUTABLE}"
--exclude "${IwyuRule_EXCLUDE_PATTERN}"
--jobs "${IwyuRule_JOBS}"
--output-file "${IwyuRule_OUTPUT}/iwyu.json"
${l_args}
VERBATIM)

add_custom_command(
COMMENT "Generating ${module} iwyu HTML reports"
OUTPUT
${IwyuRule_OUTPUT}/index.html
${IwyuRule_OUTPUT}/status.json
DEPENDS
${IwyuRule_OUTPUT}/iwyu.json
${XTDMake_HOME}/iwyu/FindIwyuRule.cmake
${XTDMake_HOME}/iwyu/status.py
${XTDMake_HOME}/iwyu/index.tpl
COMMAND ${Mako_INTERPRETER} ${XTDMake_HOME}/iwyu/status.py
--module "${module}"
--input-file "${IwyuRule_OUTPUT}/iwyu.json"
--output-status "${IwyuRule_OUTPUT}/status.json"
--output-html "${IwyuRule_OUTPUT}/index.html"
VERBATIM)

add_custom_target(${module}-iwyu
DEPENDS
${IwyuRule_OUTPUT}/index.html
${IwyuRule_OUTPUT}/iwyu.json
${IwyuRule_OUTPUT}/status.json)

add_custom_target(${module}-iwyu-clean
COMMAND rm -rf ${IwyuRule_OUTPUT})

add_dependencies(iwyu ${module}-iwyu)
add_dependencies(iwyu-clean ${module}-iwyu-clean)
endfunction()
endif()

0 comments on commit 29c713f

Please sign in to comment.