Skip to content

Commit 5c93df1

Browse files
authored
selfcheck.yml: also run unusedFunction selfcheck without CLI (currently disabled) and GUI sources (danmar#6526)
1 parent 9044a17 commit 5c93df1

File tree

10 files changed

+133
-117
lines changed

10 files changed

+133
-117
lines changed

.github/workflows/selfcheck.yml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
CC: clang-14
5959
CXX: clang++-14
6060

61+
# unusedFunction - start
6162
- name: CMake
6263
run: |
6364
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
@@ -79,8 +80,11 @@ jobs:
7980
env:
8081
DISABLE_VALUEFLOW: 1
8182
UNUSEDFUNCTION_ONLY: 1
83+
# unusedFunction - end
8284

8385
# the following steps are duplicated from above since setting up the build node in a parallel step takes longer than the actual steps
86+
87+
# unusedFunction notest - start
8488
- name: CMake (no test)
8589
run: |
8690
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
@@ -100,6 +104,49 @@ jobs:
100104
env:
101105
DISABLE_VALUEFLOW: 1
102106
UNUSEDFUNCTION_ONLY: 1
107+
# unusedFunction notest - end
108+
109+
# unusedFunction notest nogui - start
110+
- name: CMake (no test / no gui)
111+
run: |
112+
cmake -S . -B cmake.output.notest_nogui -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DENABLE_CHECK_INTERNAL=On
113+
114+
- name: Generate dependencies (no test / no gui)
115+
run: |
116+
# make sure the precompiled headers exist
117+
make -C cmake.output.notest_nogui lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
118+
119+
# TODO: find a way to report unmatched suppressions without need to add information checks
120+
- name: Self check (unusedFunction / no test / no gui)
121+
run: |
122+
./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
123+
env:
124+
DISABLE_VALUEFLOW: 1
125+
UNUSEDFUNCTION_ONLY: 1
126+
# unusedFunction notest nogui - end
127+
128+
# unusedFunction notest nocli - start
129+
- name: CMake (no test / no cli)
130+
run: |
131+
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
132+
133+
- name: Generate dependencies (no test / no cli)
134+
run: |
135+
# make sure the precompiled headers exist
136+
make -C cmake.output.notest_nocli lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
137+
# make sure auto-generated GUI files exist
138+
make -C cmake.output.notest_nocli autogen
139+
make -C cmake.output.notest_nocli gui-build-deps
140+
141+
# TODO: find a way to report unmatched suppressions without need to add information checks
142+
- name: Self check (unusedFunction / no test / no cli)
143+
if: false # TODO: the findings are currently too intrusive
144+
run: |
145+
./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
146+
env:
147+
DISABLE_VALUEFLOW: 1
148+
UNUSEDFUNCTION_ONLY: 1
149+
# unusedFunction notest nocli - end
103150

104151
- name: Fetch corpus
105152
run: |
@@ -113,7 +160,7 @@ jobs:
113160
- name: Generate dependencies (corpus)
114161
run: |
115162
# make sure the precompiled headers exist
116-
make -C cmake.output.notest lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
163+
make -C cmake.output.corpus lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
117164
# make sure auto-generated GUI files exist
118165
make -C cmake.output.corpus autogen
119166
make -C cmake.output.corpus gui-build-deps

cli/CMakeLists.txt

Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,89 @@
1-
file(GLOB hdrs "*.h")
2-
file(GLOB srcs "*.cpp")
3-
file(GLOB mainfile "main.cpp")
4-
list(REMOVE_ITEM srcs ${mainfile})
1+
if (BUILD_CLI)
52

6-
add_library(cli_objs OBJECT ${hdrs} ${srcs})
7-
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
8-
if(USE_BUNDLED_TINYXML2)
9-
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
10-
else()
11-
target_include_directories(cli_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
12-
endif()
13-
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
14-
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
15-
target_precompile_headers(cli_objs PRIVATE precompiled.h)
16-
endif()
17-
if (BUILD_CORE_DLL)
18-
target_compile_definitions(cli_objs PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
19-
endif()
3+
file(GLOB hdrs "*.h")
4+
file(GLOB srcs "*.cpp")
5+
file(GLOB mainfile "main.cpp")
6+
list(REMOVE_ITEM srcs ${mainfile})
207

21-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 13)
22-
# false positive warning in Clang 13 - caused by FD_ZERO macro
23-
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
24-
endif()
25-
26-
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs>)
27-
if (NOT BUILD_CORE_DLL)
28-
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:cppcheck-core>)
29-
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:simplecpp_objs>)
8+
add_library(cli_objs OBJECT ${hdrs} ${srcs})
9+
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
3010
if(USE_BUNDLED_TINYXML2)
31-
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
11+
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
12+
else()
13+
target_include_directories(cli_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
14+
endif()
15+
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
16+
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
17+
target_precompile_headers(cli_objs PRIVATE precompiled.h)
18+
endif()
19+
if (BUILD_CORE_DLL)
20+
target_compile_definitions(cli_objs PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
3221
endif()
33-
endif()
34-
if (WIN32)
35-
list(APPEND cppcheck_SOURCES version.rc)
36-
endif()
3722

38-
add_executable(cppcheck ${cppcheck_SOURCES})
39-
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
40-
if(USE_BUNDLED_TINYXML2)
41-
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
42-
else()
43-
target_include_directories(cppcheck SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
44-
endif()
45-
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
46-
if (HAVE_RULES)
47-
target_link_libraries(cppcheck ${PCRE_LIBRARY})
48-
endif()
49-
if (WIN32 AND NOT BORLAND)
50-
if(NOT MINGW)
51-
target_link_libraries(cppcheck Shlwapi.lib)
23+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 13)
24+
# false positive warning in Clang 13 - caused by FD_ZERO macro
25+
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
26+
endif()
27+
28+
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs>)
29+
if (NOT BUILD_CORE_DLL)
30+
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:cppcheck-core>)
31+
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:simplecpp_objs>)
32+
if(USE_BUNDLED_TINYXML2)
33+
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
34+
endif()
35+
endif()
36+
if (WIN32)
37+
list(APPEND cppcheck_SOURCES version.rc)
38+
endif()
39+
40+
add_executable(cppcheck ${cppcheck_SOURCES})
41+
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
42+
if(USE_BUNDLED_TINYXML2)
43+
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
5244
else()
53-
target_link_libraries(cppcheck shlwapi)
45+
target_include_directories(cppcheck SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
46+
endif()
47+
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
48+
if (HAVE_RULES)
49+
target_link_libraries(cppcheck ${PCRE_LIBRARY})
50+
endif()
51+
if (WIN32 AND NOT BORLAND)
52+
if(NOT MINGW)
53+
target_link_libraries(cppcheck Shlwapi.lib)
54+
else()
55+
target_link_libraries(cppcheck shlwapi)
56+
endif()
57+
endif()
58+
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
59+
target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
60+
endif()
61+
target_link_libraries(cppcheck ${CMAKE_THREAD_LIBS_INIT})
62+
if (BUILD_CORE_DLL)
63+
target_link_libraries(cppcheck cppcheck-core)
5464
endif()
55-
endif()
56-
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
57-
target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
58-
endif()
59-
target_link_libraries(cppcheck ${CMAKE_THREAD_LIBS_INIT})
60-
if (BUILD_CORE_DLL)
61-
target_link_libraries(cppcheck cppcheck-core)
62-
endif()
6365

64-
add_dependencies(cppcheck copy_cfg)
65-
add_dependencies(cppcheck copy_addons)
66-
add_dependencies(cppcheck copy_platforms)
67-
if (NOT DISABLE_DMAKE)
68-
add_dependencies(cppcheck run-dmake)
69-
endif()
66+
add_dependencies(cppcheck copy_cfg)
67+
add_dependencies(cppcheck copy_addons)
68+
add_dependencies(cppcheck copy_platforms)
69+
if (NOT DISABLE_DMAKE)
70+
add_dependencies(cppcheck run-dmake)
71+
endif()
7072

71-
install(TARGETS cppcheck
72-
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
73-
COMPONENT applications)
73+
install(TARGETS cppcheck
74+
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
75+
COMPONENT applications)
7476

75-
install(FILES ${addons}
76-
DESTINATION ${FILESDIR}/addons
77-
COMPONENT headers)
77+
install(FILES ${addons}
78+
DESTINATION ${FILESDIR}/addons
79+
COMPONENT headers)
7880

79-
install(FILES ${cfgs}
80-
DESTINATION ${FILESDIR}/cfg
81-
COMPONENT headers)
81+
install(FILES ${cfgs}
82+
DESTINATION ${FILESDIR}/cfg
83+
COMPONENT headers)
8284

83-
install(FILES ${platforms}
84-
DESTINATION ${FILESDIR}/platforms
85-
COMPONENT headers)
85+
install(FILES ${platforms}
86+
DESTINATION ${FILESDIR}/platforms
87+
COMPONENT headers)
8688

89+
endif()

cmake/options.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ option(ENABLE_CHECK_INTERNAL "Enable internal checks"
5151
option(DISABLE_DMAKE "Disable run-dmake dependencies" OFF)
5252
option(BUILD_MANPAGE "Enable man target to build manpage" OFF)
5353

54+
option(BUILD_CLI "Build the cli application" ON)
55+
5456
option(BUILD_GUI "Build the qt application" OFF)
5557
option(WITH_QCHART "Enable QtCharts usage in the GUI" OFF)
5658
option(USE_QT6 "Prefer Qt6 when available" OFF)

cmake/printInfo.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ message(STATUS "ENABLE_CHECK_INTERNAL = ${ENABLE_CHECK_INTERNAL}")
5858
message(STATUS "DISABLE_DMAKE = ${DISABLE_DMAKE}")
5959
message(STATUS "BUILD_MANPAGE = ${BUILD_MANPAGE}")
6060
message(STATUS)
61+
message(STATUS "BUILD_CLI = ${BUILD_CLI}")
62+
message(STATUS)
6163
message(STATUS "BUILD_GUI = ${BUILD_GUI}")
6264
if(BUILD_GUI)
6365
message(STATUS "REGISTER_GUI_TESTS = ${REGISTER_GUI_TESTS}")

lib/checkleakautovar.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -104,47 +104,6 @@ static bool isVarTokComparison(const Token * tok, const Token ** vartok,
104104

105105
//---------------------------------------------------------------------------
106106

107-
void VarInfo::print()
108-
{
109-
std::cout << "size=" << alloctype.size() << std::endl;
110-
for (std::map<int, AllocInfo>::const_iterator it = alloctype.cbegin(); it != alloctype.cend(); ++it) {
111-
std::string strusage;
112-
const auto use = possibleUsage.find(it->first);
113-
if (use != possibleUsage.end())
114-
strusage = use->second.first->str();
115-
116-
std::string status;
117-
switch (it->second.status) {
118-
case OWNED:
119-
status = "owned";
120-
break;
121-
case DEALLOC:
122-
status = "dealloc";
123-
break;
124-
case ALLOC:
125-
status = "alloc";
126-
break;
127-
case NOALLOC:
128-
status = "noalloc";
129-
break;
130-
case REALLOC:
131-
status = "realloc";
132-
break;
133-
default:
134-
status = "?";
135-
break;
136-
}
137-
138-
std::cout << "status=" << status << " "
139-
<< "alloctype='" << it->second.type << "' "
140-
<< "possibleUsage='" << strusage << "' "
141-
<< "conditionalAlloc=" << (conditionalAlloc.find(it->first) != conditionalAlloc.end() ? "yes" : "no") << " "
142-
<< "referenced=" << (referenced.find(it->first) != referenced.end() ? "yes" : "no") << " "
143-
<< "reallocedFrom=" << it->second.reallocedFromType
144-
<< std::endl;
145-
}
146-
}
147-
148107
void VarInfo::possibleUsageAll(const std::pair<const Token*, Usage>& functionUsage)
149108
{
150109
possibleUsage.clear();

lib/checkleakautovar.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class CPPCHECKLIB VarInfo {
9494

9595
/** set possible usage for all variables */
9696
void possibleUsageAll(const std::pair<const Token*, Usage>& functionUsage);
97-
98-
void print();
9997
};
10098

10199

lib/errorlogger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class CPPCHECKLIB ErrorMessage {
186186
}
187187

188188
/** Verbose message (may be the same as the short message) */
189+
// cppcheck-suppress unusedFunction - used by GUI only
189190
const std::string &verboseMessage() const {
190191
return mVerboseMessage;
191192
}

lib/importproject.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ void ImportProject::selectOneVsConfig(Platform::Type platform)
13241324
}
13251325
}
13261326

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

1352+
// cppcheck-suppress unusedFunction - used by GUI only
13511353
std::list<std::string> ImportProject::getVSConfigs()
13521354
{
13531355
return std::list<std::string>(mAllVSConfigs.cbegin(), mAllVSConfigs.cend());

lib/suppressions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage &
390390
return true;
391391
}
392392

393+
// cppcheck-suppress unusedFunction - used by GUI only
393394
std::string SuppressionList::Suppression::getText() const
394395
{
395396
std::string ret;

test/testcmdlineparser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ class TestCmdlineParser : public TestFixture {
268268
TEST_CASE(xmlverinvalid);
269269
TEST_CASE(doc);
270270
TEST_CASE(docExclusive);
271+
TEST_CASE(showtimeSummary);
271272
TEST_CASE(showtimeFile);
272273
TEST_CASE(showtimeFileTotal);
273274
TEST_CASE(showtimeTop5);

0 commit comments

Comments
 (0)