Skip to content

Commit

Permalink
selfcheck.yml: also run unusedFunction selfcheck without CLI (curre…
Browse files Browse the repository at this point in the history
…ntly disabled) and GUI sources (danmar#6526)
  • Loading branch information
firewave committed Jun 20, 2024
1 parent 9044a17 commit 5c93df1
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 117 deletions.
49 changes: 48 additions & 1 deletion .github/workflows/selfcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
CC: clang-14
CXX: clang++-14

# unusedFunction - start
- name: CMake
run: |
cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DUSE_QT6=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On
Expand All @@ -79,8 +80,11 @@ jobs:
env:
DISABLE_VALUEFLOW: 1
UNUSEDFUNCTION_ONLY: 1
# unusedFunction - end

# the following steps are duplicated from above since setting up the build node in a parallel step takes longer than the actual steps

# unusedFunction notest - start
- name: CMake (no test)
run: |
cmake -S . -B cmake.output.notest -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DBUILD_GUI=ON -DUSE_QT6=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On
Expand All @@ -100,6 +104,49 @@ jobs:
env:
DISABLE_VALUEFLOW: 1
UNUSEDFUNCTION_ONLY: 1
# unusedFunction notest - end

# unusedFunction notest nogui - start
- name: CMake (no test / no gui)
run: |
cmake -S . -B cmake.output.notest_nogui -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DENABLE_CHECK_INTERNAL=On
- name: Generate dependencies (no test / no gui)
run: |
# make sure the precompiled headers exist
make -C cmake.output.notest_nogui lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
# TODO: find a way to report unmatched suppressions without need to add information checks
- name: Self check (unusedFunction / no test / no gui)
run: |
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
env:
DISABLE_VALUEFLOW: 1
UNUSEDFUNCTION_ONLY: 1
# unusedFunction notest nogui - end

# unusedFunction notest nocli - start
- name: CMake (no test / no cli)
run: |
cmake -S . -B cmake.output.notest_nocli -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DBUILD_CLI=Off -DBUILD_GUI=ON -DUSE_QT6=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On
- name: Generate dependencies (no test / no cli)
run: |
# make sure the precompiled headers exist
make -C cmake.output.notest_nocli lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
# make sure auto-generated GUI files exist
make -C cmake.output.notest_nocli autogen
make -C cmake.output.notest_nocli gui-build-deps
# TODO: find a way to report unmatched suppressions without need to add information checks
- name: Self check (unusedFunction / no test / no cli)
if: false # TODO: the findings are currently too intrusive
run: |
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest_nocli/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
env:
DISABLE_VALUEFLOW: 1
UNUSEDFUNCTION_ONLY: 1
# unusedFunction notest nocli - end

- name: Fetch corpus
run: |
Expand All @@ -113,7 +160,7 @@ jobs:
- name: Generate dependencies (corpus)
run: |
# make sure the precompiled headers exist
make -C cmake.output.notest lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
make -C cmake.output.corpus lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
# make sure auto-generated GUI files exist
make -C cmake.output.corpus autogen
make -C cmake.output.corpus gui-build-deps
Expand Down
149 changes: 76 additions & 73 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,86 +1,89 @@
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB mainfile "main.cpp")
list(REMOVE_ITEM srcs ${mainfile})
if (BUILD_CLI)

add_library(cli_objs OBJECT ${hdrs} ${srcs})
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_include_directories(cli_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(cli_objs PRIVATE precompiled.h)
endif()
if (BUILD_CORE_DLL)
target_compile_definitions(cli_objs PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
endif()
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB mainfile "main.cpp")
list(REMOVE_ITEM srcs ${mainfile})

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 13)
# false positive warning in Clang 13 - caused by FD_ZERO macro
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
endif()

list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs>)
if (NOT BUILD_CORE_DLL)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:cppcheck-core>)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:simplecpp_objs>)
add_library(cli_objs OBJECT ${hdrs} ${srcs})
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_include_directories(cli_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(cli_objs PRIVATE precompiled.h)
endif()
if (BUILD_CORE_DLL)
target_compile_definitions(cli_objs PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
endif()
endif()
if (WIN32)
list(APPEND cppcheck_SOURCES version.rc)
endif()

add_executable(cppcheck ${cppcheck_SOURCES})
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_include_directories(cppcheck SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (HAVE_RULES)
target_link_libraries(cppcheck ${PCRE_LIBRARY})
endif()
if (WIN32 AND NOT BORLAND)
if(NOT MINGW)
target_link_libraries(cppcheck Shlwapi.lib)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 13)
# false positive warning in Clang 13 - caused by FD_ZERO macro
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
endif()

list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs>)
if (NOT BUILD_CORE_DLL)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:cppcheck-core>)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
endif()
endif()
if (WIN32)
list(APPEND cppcheck_SOURCES version.rc)
endif()

add_executable(cppcheck ${cppcheck_SOURCES})
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_link_libraries(cppcheck shlwapi)
target_include_directories(cppcheck SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (HAVE_RULES)
target_link_libraries(cppcheck ${PCRE_LIBRARY})
endif()
if (WIN32 AND NOT BORLAND)
if(NOT MINGW)
target_link_libraries(cppcheck Shlwapi.lib)
else()
target_link_libraries(cppcheck shlwapi)
endif()
endif()
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
endif()
target_link_libraries(cppcheck ${CMAKE_THREAD_LIBS_INIT})
if (BUILD_CORE_DLL)
target_link_libraries(cppcheck cppcheck-core)
endif()
endif()
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
endif()
target_link_libraries(cppcheck ${CMAKE_THREAD_LIBS_INIT})
if (BUILD_CORE_DLL)
target_link_libraries(cppcheck cppcheck-core)
endif()

add_dependencies(cppcheck copy_cfg)
add_dependencies(cppcheck copy_addons)
add_dependencies(cppcheck copy_platforms)
if (NOT DISABLE_DMAKE)
add_dependencies(cppcheck run-dmake)
endif()
add_dependencies(cppcheck copy_cfg)
add_dependencies(cppcheck copy_addons)
add_dependencies(cppcheck copy_platforms)
if (NOT DISABLE_DMAKE)
add_dependencies(cppcheck run-dmake)
endif()

install(TARGETS cppcheck
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
COMPONENT applications)
install(TARGETS cppcheck
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
COMPONENT applications)

install(FILES ${addons}
DESTINATION ${FILESDIR}/addons
COMPONENT headers)
install(FILES ${addons}
DESTINATION ${FILESDIR}/addons
COMPONENT headers)

install(FILES ${cfgs}
DESTINATION ${FILESDIR}/cfg
COMPONENT headers)
install(FILES ${cfgs}
DESTINATION ${FILESDIR}/cfg
COMPONENT headers)

install(FILES ${platforms}
DESTINATION ${FILESDIR}/platforms
COMPONENT headers)
install(FILES ${platforms}
DESTINATION ${FILESDIR}/platforms
COMPONENT headers)

endif()
2 changes: 2 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ option(ENABLE_CHECK_INTERNAL "Enable internal checks"
option(DISABLE_DMAKE "Disable run-dmake dependencies" OFF)
option(BUILD_MANPAGE "Enable man target to build manpage" OFF)

option(BUILD_CLI "Build the cli application" ON)

option(BUILD_GUI "Build the qt application" OFF)
option(WITH_QCHART "Enable QtCharts usage in the GUI" OFF)
option(USE_QT6 "Prefer Qt6 when available" OFF)
Expand Down
2 changes: 2 additions & 0 deletions cmake/printInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ message(STATUS "ENABLE_CHECK_INTERNAL = ${ENABLE_CHECK_INTERNAL}")
message(STATUS "DISABLE_DMAKE = ${DISABLE_DMAKE}")
message(STATUS "BUILD_MANPAGE = ${BUILD_MANPAGE}")
message(STATUS)
message(STATUS "BUILD_CLI = ${BUILD_CLI}")
message(STATUS)
message(STATUS "BUILD_GUI = ${BUILD_GUI}")
if(BUILD_GUI)
message(STATUS "REGISTER_GUI_TESTS = ${REGISTER_GUI_TESTS}")
Expand Down
41 changes: 0 additions & 41 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,47 +104,6 @@ static bool isVarTokComparison(const Token * tok, const Token ** vartok,

//---------------------------------------------------------------------------

void VarInfo::print()
{
std::cout << "size=" << alloctype.size() << std::endl;
for (std::map<int, AllocInfo>::const_iterator it = alloctype.cbegin(); it != alloctype.cend(); ++it) {
std::string strusage;
const auto use = possibleUsage.find(it->first);
if (use != possibleUsage.end())
strusage = use->second.first->str();

std::string status;
switch (it->second.status) {
case OWNED:
status = "owned";
break;
case DEALLOC:
status = "dealloc";
break;
case ALLOC:
status = "alloc";
break;
case NOALLOC:
status = "noalloc";
break;
case REALLOC:
status = "realloc";
break;
default:
status = "?";
break;
}

std::cout << "status=" << status << " "
<< "alloctype='" << it->second.type << "' "
<< "possibleUsage='" << strusage << "' "
<< "conditionalAlloc=" << (conditionalAlloc.find(it->first) != conditionalAlloc.end() ? "yes" : "no") << " "
<< "referenced=" << (referenced.find(it->first) != referenced.end() ? "yes" : "no") << " "
<< "reallocedFrom=" << it->second.reallocedFromType
<< std::endl;
}
}

void VarInfo::possibleUsageAll(const std::pair<const Token*, Usage>& functionUsage)
{
possibleUsage.clear();
Expand Down
2 changes: 0 additions & 2 deletions lib/checkleakautovar.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class CPPCHECKLIB VarInfo {

/** set possible usage for all variables */
void possibleUsageAll(const std::pair<const Token*, Usage>& functionUsage);

void print();
};


Expand Down
1 change: 1 addition & 0 deletions lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class CPPCHECKLIB ErrorMessage {
}

/** Verbose message (may be the same as the short message) */
// cppcheck-suppress unusedFunction - used by GUI only
const std::string &verboseMessage() const {
return mVerboseMessage;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ void ImportProject::selectOneVsConfig(Platform::Type platform)
}
}

// cppcheck-suppress unusedFunction - used by GUI only
void ImportProject::selectVsConfigurations(Platform::Type platform, const std::vector<std::string> &configurations)
{
for (std::list<FileSettings>::iterator it = fileSettings.begin(); it != fileSettings.end();) {
Expand All @@ -1348,6 +1349,7 @@ void ImportProject::selectVsConfigurations(Platform::Type platform, const std::v
}
}

// cppcheck-suppress unusedFunction - used by GUI only
std::list<std::string> ImportProject::getVSConfigs()
{
return std::list<std::string>(mAllVSConfigs.cbegin(), mAllVSConfigs.cend());
Expand Down
1 change: 1 addition & 0 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage &
return true;
}

// cppcheck-suppress unusedFunction - used by GUI only
std::string SuppressionList::Suppression::getText() const
{
std::string ret;
Expand Down
1 change: 1 addition & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(xmlverinvalid);
TEST_CASE(doc);
TEST_CASE(docExclusive);
TEST_CASE(showtimeSummary);
TEST_CASE(showtimeFile);
TEST_CASE(showtimeFileTotal);
TEST_CASE(showtimeTop5);
Expand Down

0 comments on commit 5c93df1

Please sign in to comment.