viva64 / pvs-studio-cmake-examples Goto Github PK
View Code? Open in Web Editor NEWExamples of PVS-Studio integration in CMake (CLion/QtCreator)
License: Apache License 2.0
Examples of PVS-Studio integration in CMake (CLion/QtCreator)
License: Apache License 2.0
Скорее ошибка связана с pvs-studio-analyzer, но для pvs-studio-analyzer я не нашел баг-треккера, и в этом репозитории есть пример pvs-studio.pvsconfig.
OS: Linux
Verrsion: PVS-Studio 7.18.59866.202
Создал простейший проект (Код доступен на github ):
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(test main.cpp)
main.cpp
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* Flacon - audio File Encoder
* https://github.com/flacon/flacon
*
* Copyright: 2012-2015
* Alexander Sokoloff <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
pvs-studio.pvsconfig
//-V::1042
Запускаю PVS
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=On . && make
pvs-studio-analyzer analyze -R rules.pvsconfig -o PVS.log
plog-converter -t tasklist -o PVS.tasks PVS.log
В файле PVS.tasks присутствует строка
main.cpp 2 err V1042 This file is marked with copyleft license, which requires you to open the derived source code.
Может я что-то делаю ни так, но выглядит так, что pvs-studio-analyzer игнорирует опцию -R. Например, если я указываю несуществующий файл правил, программа не ругается, а молча пропускает это.
For open source projects, such warnings like V1042 | This file is marked with copyleft license, which requires you to open the derived source code
doesn't make sense, so it would be nice to provide some argument allowing to disable warnings by comma separated, for example:
-DSUPPRESS_WARNINGS=V559,V1042
Hello.
Which is the PVS-Studio.cmake
licensing? Could I distribute it with a LGPLv3 project?!
Thank you!
Hello. I tried example 1 on Windows with msvc from QtCreator but it failed.
Version 7.14.50440
[1/5 6.9/sec] Building CXX object CMakeFiles\pvs-studio-cmake-example-1.dir\main.cpp.obj
[2/5 2.7/sec] Linking CXX executable pvs-studio-cmake-example-1.exe
[3/5 1.2/sec] Analyzing CXX file main.cpp
FAILED: PVS-Studio/main.cpp.plog C:/Users/user/source/repos/pvs-studio-cmake-examples/build-example-1-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/PVS-Studio/main.cpp.plog
cmd.exe /C "cd /D C:\Users\user\source\repos\pvs-studio-cmake-examples\build-example-1-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug && "C:\Program Files\CMake\bin\cmake.exe" -E make_directory C:/Users/user/source/repos/pvs-studio-cmake-examples/build-example-1-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/PVS-Studio && "C:\Program Files\CMake\bin\cmake.exe" -E remove_directory C:/Users/user/source/repos/pvs-studio-cmake-examples/build-example-1-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/PVS-Studio/main.cpp.plog && "C:\Program Files\CMake\bin\cmake.exe" -D PVS_STUDIO_AS_SCRIPT=TRUE -D "PVS_STUDIO_COMMAND=C:/Program Files (x86)/PVS-Studio/CompilerCommandsAnalyzer.exe;analyze;--output-file;C:/Users/user/source/repos/pvs-studio-cmake-examples/build-example-1-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/PVS-Studio/main.cpp.plog;--source-file;C:/Users/user/source/repos/pvs-studio-cmake-examples/example-1/main.cpp;--dep-file;C:/Users/user/source/repos/pvs-studio-cmake-examples/build-example-1-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/PVS-Studio/main.cpp.plog.d;--dep-file-target;PVS-Studio/main.cpp.plog;--platform;x64;--preprocessor;visualcpp;--cxx;C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe;--cc;C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe;-a;GA;--cl-params;;;;-DPVS_STUDIO;C:/Users/user/source/repos/pvs-studio-cmake-examples/example-1/main.cpp" -P C:/Users/user/source/repos/pvs-studio-cmake-examples/PVS-Studio.cmake"
CMake Error at C:/Users/user/source/repos/pvs-studio-cmake-examples/PVS-Studio.cmake:47 (message):
ninja: build stopped: subcommand failed.
What i did wrong?
CompilerCommandsAnalyzer.exe
is unable to parse this compile_command.json
generated on Windows using CMake + Ninja build:
{
"directory": "E:/workingfolder/my-project/build",
"command": "C:\\PROGRA~2\\MICROS~1\\2017\\COMMUN~1\\VC\\Tools\\MSVC\\1416~1.270\\bin\\Hostx64\\x64\\cl.exe /nologo /TP -DLOGGING_LIBRARY -DQTILITIESCORE_LIBRARY -DQTILITIES_CORE_GUI_LIBRARY -DQTILITIES_NO_HELP -DQTILITIES_VERSION_MAJOR=1 -DQTILITIES_VERSION_MINOR=5 -DQTILITIES_VERSION_REVISION=0 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_XML_LIB -DQtilities_EXPORTS -DWIN32_LEAN_AND_MEAN -D_SCL_SECURE_NO_WARNINGS -D_WIN32_WINNT=0x0601 -IQtilities\\Qtilities_autogen\\include -I..\\Qtilities\\include -I..\\Qtilities\\include\\QtilitiesCore -I..\\Qtilities\\include\\QtilitiesCoreGui -I..\\Qtilities\\include\\QtilitiesLogging -IE:\\DevTools\\Qt\\5.12.0\\msvc2017_64\\include -IE:\\DevTools\\Qt\\5.12.0\\msvc2017_64\\include\\QtXml -IE:\\DevTools\\Qt\\5.12.0\\msvc2017_64\\include\\QtCore -IE:\\DevTools\\Qt\\5.12.0\\msvc2017_64\\.\\mkspecs\\win32-msvc -IE:\\DevTools\\Qt\\5.12.0\\msvc2017_64\\include\\QtWidgets -IE:\\DevTools\\Qt\\5.12.0\\msvc2017_64\\include\\QtGui -IE:\\DevTools\\Qt\\5.12.0\\msvc2017_64\\include\\QtANGLE -IE:\\DevTools\\Qt\\5.12.0\\msvc2017_64\\include\\QtPrintSupport /DWIN32 /D_WINDOWS /W3 /GR /EHsc /bigobj /std:c++17 /MDd /Z7 /Ob0 /Od /RTC1 /FoQtilities\\CMakeFiles\\Qtilities.dir\\Qtilities_autogen\\mocs_compilation.cpp.obj /FdTARGET_COMPILE_PDB /FS -c E:\\workingfolder\\my-project\\build\\Qtilities\\Qtilities_autogen\\mocs_compilation.cpp",
"file": "E:/workingfolder/my-project/build/Qtilities/Qtilities_autogen/mocs_compilation.cpp"
},
...
I tried running it with --verbose
flag and I discovered that the problem lies in the \\
in the paths, which get replaced to empty and the paths become invalid.
If I replace all \\
with /
in compile_command.json
, CompilerCommandsAnalyzer.exe
works correctly and finds both the cl.exe
compiler and the source files.
Приветствую, столкнулся с такой проблемой как ограничить анализ только моим кодом? Просто у меня в проекте анализ идет еще и в c:\mingw\include использую такие настройки.
cmake_minimum_required(VERSION 3.15)
project(untitled1)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
set(SOURCE_FILES main.cpp)
add_executable(untitled1 ${SOURCE_FILES})
include(PVS-Studio.cmake)
pvs_studio_add_target(TARGET analyze ALL
OUTPUT FORMAT errorfile
ANALYZE ${PROJECT_NAME}
MODE GA:1,2 OP
LOG target.err)
==============================
Вывод
Build | analyze | Debug
"C:\Program Files\JetBrains\CLion 2019.3.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\admin3\CLionProjects\untitled1\cmake-build-debug --target analyze -- -j 2
Scanning dependencies of target untitled1
[ 20%] Building CXX object CMakeFiles/untitled1.dir/main.cpp.obj
[ 40%] Linking CXX executable untitled1.exe
[ 40%] Built target untitled1
Scanning dependencies of target analyze
[ 60%] Analyzing CXX file main.cpp
[ 80%] Generating target.err
Analyzer log conversion tool.
Copyright (c) 2008-2020 OOO "Program Verification Systems"
PVS-Studio is a static code analyzer and SAST (static application security
testing) tool that is available for C and C++ desktop and embedded development,
C# and Java under Windows, Linux and macOS.
Total messages: 573
Filtered messages: 45
www.viva64.com/en/w:1:1: error: Help: The documentation for all analyzer warnings is available here: https://www.viva64.com/en/w/.
c:\mingw\lib\gcc\mingw32\9.2.0\include\stddef.h:350:1: warning: V677 Custom declaration of a standard 'wint_t' type. The declaration from system header files should be used instead.
c:\mingw\include\wctype.h:89:1: warning: V677 Custom declaration of a standard 'wctype_t' type. The declaration from system header files should be used instead.
c:\mingw\include\wctype.h:191:1: warning: V677 Custom declaration of a standard 'wctrans_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:67:1: warning: V677 Custom declaration of a standard '_off_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:75:1: warning: V677 Custom declaration of a standard 'off_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:139:1: warning: V677 Custom declaration of a standard '__time32_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:140:1: warning: V677 Custom declaration of a standard '__time64_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:149:1: warning: V677 Custom declaration of a standard 'time_t' type. The declaration from system header files should be used instead.
c:\mingw\lib\gcc\mingw32\9.2.0\include\stddef.h:143:1: warning: V677 Custom declaration of a standard 'ptrdiff_t' type. The declaration from system header files should be used instead.
c:\mingw\lib\gcc\mingw32\9.2.0\include\stddef.h:209:1: warning: V677 Custom declaration of a standard 'size_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:184:1: warning: V677 Custom declaration of a standard '_dev_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:195:1: warning: V677 Custom declaration of a standard '_ino_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:207:1: warning: V677 Custom declaration of a standard 'dev_t' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\types.h:208:1: warning: V677 Custom declaration of a standard 'ino_t' type. The declaration from system header files should be used instead.
c:\mingw\include\stdio.h:220:1: warning: V677 Custom declaration of a standard 'FILE' type. The declaration from system header files should be used instead.
c:\mingw\include\sys\stat.h:173:1: warning: V795 Please note that the size of the 'time_t' type is not 64 bits. After year 2038, the program will work incorrectly.
c:\mingw\include\sys\stat.h:180:1: warning: V795 Please note that the size of the 'time_t' type is not 64 bits. After year 2038, the program will work incorrectly.
c:\mingw\include\sys\stat.h:188:1: warning: V795 Please note that the size of the 'time_t' type is not 64 bits. After year 2038, the program will work incorrectly.
c:\mingw\include\stdint.h:108:1: warning: V677 Custom declaration of a standard 'intptr_t' type. The declaration from system header files should be used instead.
c:\mingw\include\io.h:105:1: warning: V677 Custom declaration of a standard '_fsize_t' type. The declaration from system header files should be used instead.
c:\mingw\include\io.h:342:1: warning: V795 Please note that the size of the 'time_t' type is not 64 bits. After year 2038, the program will work incorrectly.
c:\mingw\include\io.h:343:1: warning: V795 Please note that the size of the 'time_t' type is not 64 bits. After year 2038, the program will work incorrectly.
c:\mingw\include\time.h:508:1: warning: V795 Please note that the size of the 'time_t' type is not 64 bits. After year 2038, the program will work incorrectly.
c:\mingw\include\wchar.h:530:1: warning: V677 Custom declaration of a standard 'mbstate_t' type. The declaration from system header files should be used instead.
c:\mingw\include\stdint.h:120:1: warning: V677 Custom declaration of a standard 'uintptr_t' type. The declaration from system header files should be used instead.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:527:1: error: V769 The '__s' pointer in the '__s + npos' expression equals nullptr. The resulting value is senseless and it should not be used.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:734:1: warning: V794 The assignment operator should be protected from the case of 'this == &__str'.
c:\mingw\include\stdlib.h:598:1: warning: V677 Custom declaration of a standard 'div_t' type. The declaration from system header files should be used instead.
c:\mingw\include\stdlib.h:599:1: warning: V677 Custom declaration of a standard 'ldiv_t' type. The declaration from system header files should be used instead.
c:\mingw\include\stdlib.h:631:1: warning: V677 Custom declaration of a standard '_onexit_t' type. The declaration from system header files should be used instead.
c:\mingw\include\stdio.h:821:1: warning: V677 Custom declaration of a standard 'fpos_t' type. The declaration from system header files should be used instead.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.tcc:1309:1: error: V797 The 'find' function is used as if it returned a bool type. The return value of the function should probably be compared with std::string::npos.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.tcc:1325:1: error: V797 The 'find' function is used as if it returned a bool type. The return value of the function should probably be compared with std::string::npos.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.tcc:1355:1: error: V797 The 'find' function is used as if it returned a bool type. The return value of the function should probably be compared with std::string::npos.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.tcc:1558:1: note: V807 Decreased performance. Consider creating a pointer to avoid using the '__in.rdbuf()' expression repeatedly.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\locale_classes.h:522:1: warning: V690 The copy assignment operator is declared as private in the 'locale::_Impl' class, but the default copy constructor will still be generated by compiler. It is dangerous to use such a class.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_bvector.h:72:1: warning: V690 The '_Bit_reference' class implements the copy assignment operator, but lacks a copy constructor. It is dangerous to use such a class.
C:\Users\admin3\CLionProjects\untitled1\main.cpp:11:1: error: V501 There are identical sub-expressions to the left and to the right of the '==' operator: x == x
C:\Users\admin3\CLionProjects\untitled1\main.cpp:9:1: error: V808 'a' object of 'vector' type was created but was not utilized.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:448:1: warning: V730 It is possible that not all members of a class are initialized inside the constructor. Consider inspecting: _M_string_length.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_string.h:579:1: warning: V730 It is possible that not all members of a class are initialized inside the constructor. Consider inspecting: _M_string_length.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\locale_classes.h:514:1: warning: V730 Not all members of a class are initialized inside the constructor. Consider inspecting: _M_index.
c:\mingw\include_mingw.h:33:1: error: V1040 Possible typo in the spelling of a pre-defined macro name. The '__MINGW_H' macro is similar to 'MINGW'.
c:\mingw\include\msvcrtver.h:77:1: error: V1040 Possible typo in the spelling of a pre-defined macro name. The '__MINGW_H' macro is similar to 'MINGW'.
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:7:1: error: V1042 This file is marked with copyleft license, which requires you to open the derived source code.
[100%] Built target analyze
Build finished
fullhtml generates directory, not file.
>------ Clean All started: Project: <...>, Configuration: x64-Debug ------
[1/1] "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe" -t clean
FAILED: clean
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe" -t clean
Cleaning... 16 files.
C:\Users\<...>\source\repos\ninja : error : remove(PVS-Studio.log): Permission denied
ninja: build stopped: subcommand failed.
Clean All failed.
Приветсвую коллег. Возникла интересная ситуация с вашим файлом для интеграции PVS в cmake.
В файле PVS-Studio.cmake есть функция pvs_studio_add_target(...). У нее есть параметр для формирования своего *.cfg - CFG_TEXT. Мне нужно добавить фильтрацию для обработки файлов через опцию exclude-path. Данный параметр, как я понял, принимает только один путь за раз, но самих опций exclude-path можно задать несколько. Получился вот такой вот вызов:
pvs_studio_add_target(TARGET ${PVS_TARGET} ALL
OUTPUT RECURSIVE FORMAT errorfile
ANALYZE ${SOME_TARGET}
MODE GA:1,2 OP
LOG target.err
CFG_TEXT "exclude-path=*/Path_1/*
exclude-path=*/Path_2/*"
)
При таком вызове сборка таргета с pvs падает с ошибкой следующего вида:
CMakeFiles/pvs_analyze.dir/build.make:281: *** missing separator. Stop.
gmake[2]: *** [CMakeFiles/Makefile2:74: CMakeFiles/pvs_analyze.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/pvs_analyze.dir/rule] Error 2
При чем, эту ошибку при текущей реализации генерации cfg файла никак не обойти, ни экранированием, ни добавлением спецсимволов типа "\n". В тоже время, если перенос строки не делать, то фильтрация не отрабатывает ни на один из заданных путей. Я пробовал следующие способы задания этого параметра:
CFG_TEXT "exclude-path=*/Path_1/* \n exclude-path=*/Path_2/*"
CFG_TEXT "exclude-path=*/Path_1/* \
exclude-path=*/Path_2/*"
CFG_TEXT "\"exclude-path=*/Path_1/*
exclude-path=*/Path_2/*\""
В любом случае получаем либо ошибку, либо не отрабатывает фильтр. Порылся в исходниках вашего cmake файла и нашем корень проблемы (начиная с 379 строки):
if (PVS_STUDIO_EMPTY_CONFIG)
set(PVS_STUDIO_CONFIG_COMMAND "${CMAKE_COMMAND}" -E echo "${PVS_STUDIO_CFG_TEXT}" > "${PVS_STUDIO_CONFIG}")
else ()
set(PVS_STUDIO_CONFIG_COMMAND "${CMAKE_COMMAND}" -E touch "${PVS_STUDIO_CONFIG}")
endif ()
add_custom_command(OUTPUT "${PVS_STUDIO_CONFIG}"
COMMAND ${PVS_STUDIO_CONFIG_COMMAND}
WORKING_DIRECTORY "${BINARY_DIR}"
COMMENT "Generating PVS-Studio.cfg")
Вот здесь и происходить некорректная генерация команды. На выходе cmake выплевывает файл, содержащий строку ввида:
PVS-Studio.cfg:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=... --progress-num=$(CMAKE_PROGRESS_25) "Generating PVS-Studio.cfg"
.../cmake -E echo exclude-path=*/Path_1/*
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exclude-path=*/Path_2/* > .../cmake-build-debug-intel/PVS-Studio.cfg
Я смог это починить заменой выше представленного кода строкой вида:
file(GENERATE OUTPUT ${PVS_STUDIO_CONFIG} CONTENT ${PVS_STUDIO_CFG_TEXT})
После чего файл PVS-Studio.cfg стал генерироваться корректно. Это временный фикс, там нужно посерьезней порыться и добавить проверок, но этот вариант рабочий. Одно но - он для более новых версий cmake, кажется начиная с 3.10. Может есть другое решение? Или может я где-то не увидил другой способ задания данного параметра?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.