-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New #9
New #9
Changes from 9 commits
40dbddb
f3702e9
30cb8b0
ec8ad1d
795ba9a
2ba6a7b
bbe0a0d
248608f
750322c
b68cf37
247e091
3082ea7
50a1be7
5a954c1
087b3d0
867c514
c262811
2c5a7d3
dd7bcab
2b544d8
6ca0dac
8012e75
207270c
8dfd636
c0605c6
1b8082f
8aa72e4
84c7ef1
96b7dc8
df60ab7
b59d312
6abfea9
086b632
61383af
a5fee9d
ee4e891
c35c97c
55caf7e
f922e1a
0748849
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
oclint | ||
build | ||
.oclint | ||
compile_commands.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 2.13.4) | ||
PROJECT(OCLINT_EXTENSIONS) | ||
|
||
SET(LLVM_ROOT ${CMAKE_SOURCE_DIR}/oclint/build/llvm-install) | ||
|
||
SET(CMAKE_DISABLE_SOURCE_CHANGES ON) | ||
SET(CMAKE_DISABLE_IN_SOURCE_BUILD ON) | ||
set(CMAKE_MACOSX_RPATH ON) | ||
SET(CMAKE_BUILD_TYPE None) | ||
|
||
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
SET(CMAKE_CXX_FLAGS "-fcolor-diagnostics") | ||
ENDIF() | ||
SET(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_LINKER_FLAGS} -fno-rtti -fPIC ${CMAKE_CXX_FLAGS}") | ||
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_LINKER_FLAGS} -fno-rtti") | ||
|
||
IF(OCLINT_BUILD_TYPE STREQUAL "Release") | ||
SET(CMAKE_CXX_FLAGS "-O3 -DNDEBUG ${CMAKE_CXX_FLAGS}") | ||
SET(CMAKE_SHARED_LINKER_FLAGS "-s ${CMAKE_SHARED_LINKER_FLAGS}") | ||
ELSE() | ||
SET(CMAKE_CXX_FLAGS "-O0 -g ${CMAKE_CXX_FLAGS}") | ||
SET(CMAKE_SHARED_LINKER_FLAGS "-g ${CMAKE_SHARED_LINKER_FLAGS}") | ||
ENDIF() | ||
|
||
SET(OCLINT_VERSION_RELEASE "22.02") | ||
|
||
IF(NOT EXISTS ${LLVM_ROOT}/include/llvm) | ||
MESSAGE(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install. Could not find ${LLVM_ROOT}/include/llvm") | ||
ENDIF() | ||
MESSAGE("LLVM_ROOT: ${LLVM_ROOT}") | ||
IF(EXISTS ${LLVM_ROOT}/lib/cmake/llvm) | ||
SET(LLVM_DIR ${LLVM_ROOT}/lib/cmake/llvm) | ||
ELSE() | ||
SET(LLVM_DIR ${LLVM_ROOT}/share/llvm/cmake) | ||
ENDIF() | ||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_DIR}") | ||
INCLUDE(LLVMConfig) | ||
|
||
INCLUDE_DIRECTORIES( ${LLVM_INCLUDE_DIRS} ) | ||
LINK_DIRECTORIES( ${LLVM_LIBRARY_DIRS} ) | ||
ADD_DEFINITIONS( ${LLVM_DEFINITIONS} ) | ||
|
||
STRING(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLVM_VERSION_RELEASE ${LLVM_PACKAGE_VERSION}) | ||
|
||
MESSAGE(STATUS "Found LLVM LLVM_PACKAGE_VERSION: ${LLVM_PACKAGE_VERSION} - LLVM_VERSION_RELEASE: ${LLVM_VERSION_RELEASE}") | ||
MESSAGE(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") | ||
LLVM_MAP_COMPONENTS_TO_LIBNAMES(REQ_LLVM_LIBRARIES asmparser bitreader instrumentation mcparser option support frontendopenmp) | ||
|
||
SET(CLANG_LIBRARIES | ||
clangToolingCore | ||
clangTooling | ||
clangFrontend | ||
clangDriver | ||
clangSerialization | ||
clangParse | ||
clangSema | ||
clangAnalysis | ||
clangEdit | ||
clangASTMatchers | ||
clangAST | ||
clangLex | ||
clangBasic) | ||
|
||
IF(TEST_BUILD) | ||
ENABLE_TESTING() | ||
IF(NOT APPLE) | ||
ADD_DEFINITIONS( | ||
--coverage | ||
) | ||
ENDIF() | ||
|
||
INCLUDE_DIRECTORIES( | ||
${GOOGLETEST_SRC}/googlemock/include | ||
${GOOGLETEST_SRC}/googletest/include | ||
) | ||
LINK_DIRECTORIES( | ||
${GOOGLETEST_BUILD} | ||
${GOOGLETEST_BUILD}/lib | ||
) | ||
SET(GTEST_LIBS gmock gtest) | ||
|
||
# Find CUDA | ||
FIND_PROGRAM(NVIDIA_NVCC_BIN "nvcc") | ||
IF (NVIDIA_NVCC_BIN) | ||
MESSAGE(STATUS "Enable tests for CUDA rules.") | ||
SET(TEST_CUDA TRUE) | ||
ELSE() | ||
SET(TEST_CUDA FALSE) | ||
ENDIF() | ||
|
||
# Setup the path for profile_rt library | ||
STRING(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_SYSTEM_NAME) | ||
LINK_DIRECTORIES(${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_RELEASE}/lib/${COMPILER_RT_SYSTEM_NAME}) | ||
IF(APPLE) | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") | ||
ELSEIF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") | ||
SET(PROFILE_RT_LIBS clang_rt.profile-aarch64 --coverage) | ||
ELSE() | ||
SET(PROFILE_RT_LIBS clang_rt.profile-x86_64 --coverage) | ||
ENDIF() | ||
ENDIF() | ||
|
||
IF(DOC_GEN_BUILD) | ||
SET(CMAKE_CXX_FLAGS "-DDOCGEN ${CMAKE_CXX_FLAGS}") | ||
ENDIF() | ||
|
||
|
||
|
||
|
||
INCLUDE_DIRECTORIES( | ||
${CMAKE_SOURCE_DIR}/oclint/oclint-core/include | ||
${CMAKE_SOURCE_DIR}/oclint/oclint-metrics/include | ||
${CMAKE_SOURCE_DIR}/oclint/oclint-rules/include | ||
${CMAKE_SOURCE_DIR}/oclint/oclint-rules | ||
) | ||
LINK_DIRECTORIES( | ||
${CMAKE_SOURCE_DIR}/oclint/build/oclint-core/lib | ||
${CMAKE_SOURCE_DIR}/oclint/build/oclint-metrics/lib | ||
${CMAKE_SOURCE_DIR}/oclint/build/oclint-rules/lib/helper | ||
${CMAKE_SOURCE_DIR}/oclint/build/oclint-rules/lib/util | ||
${CMAKE_SOURCE_DIR}/oclint/build/oclint-rules/lib | ||
) | ||
|
||
MACRO(build_dynamic_rule name) | ||
ADD_LIBRARY(${name}Rule SHARED ${CMAKE_SOURCE_DIR}/rules/${name}Rule.cpp) | ||
|
||
#SET_TARGET_PROPERTIES(${name}Rule | ||
# PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build | ||
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build | ||
# ) | ||
|
||
TARGET_LINK_LIBRARIES(${name}Rule OCLintAbstractRule) | ||
|
||
TARGET_LINK_LIBRARIES(${name}Rule | ||
clangASTMatchers | ||
) | ||
|
||
TARGET_LINK_LIBRARIES(${name}Rule | ||
OCLintMetric | ||
OCLintHelper | ||
OCLintUtil | ||
OCLintCore | ||
) | ||
install(TARGETS ${name}Rule DESTINATION lib/oclint/rules) | ||
ENDMACRO(build_dynamic_rule) | ||
|
||
BUILD_DYNAMIC_RULE(TooLongIfSequence) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,3 @@ | ||
# oclint_extensions | ||
|
||
## Что это? | ||
|
||
Кастомные правила для oclint. Список реализованных правил: | ||
* слишком много последовательных конструкций if (TooManyConsecutiveIfStatementsRule) | ||
|
||
## Установка, сборка и использование | ||
|
||
### Создание заготовок для новых правил внутри репозитория oclint | ||
|
||
Для начала склонируйте куда-нибудь [репозиторий oclint](https://github.com/oclint/oclint). | ||
|
||
Далее необходимо добавить "заготовки" для новых правил. Другими словами, необходимо создать исходники для новых правил и внести их в CMakeLists oclint'а. Новые правила относятся к группе "etu". Для этого выполните следующее: | ||
|
||
```bash | ||
cd oclint-scripts | ||
./scaffoldRule -t ASTVisitor -c etu -n"too many consecutive if statements" -p 2 TooManyConsecutiveIfStatementsRule | ||
``` | ||
|
||
### Копирование исходников с новыми правилами в репозиторий oclint | ||
|
||
Из репозитория oclint_extensions выполните: | ||
|
||
```bash | ||
cp -r ./oclint-rules YOUR_OCLINT_DIRECTORY_GOES_HERE | ||
``` | ||
|
||
### Сборка и установка | ||
|
||
Вернитесь в репозиторий oclint. Выполните следующее: | ||
```bash | ||
cd oclint-scripts | ||
./make -release # этот скрипт начнет скачивание oclint-json-compilation-database размером в 514 МБ. имейте в виду | ||
|
||
cd .. | ||
cd build/oclint-release | ||
sudo cp ./bin/oclint* /usr/local/bin/ | ||
sudo cp -rp ./lib/* /usr/local/lib/ | ||
``` | ||
|
||
### Использование | ||
|
||
``` | ||
oclint --rule=TooManyConsecutiveIfStatements examples/ex*.c | ||
``` | ||
|
||
## P.S. | ||
|
||
Очень странный способ установки всего этого. В теории можно сделать форк oclint'а, ноооооо сомнительно. Должен же быть какой-то более простой способ. | ||
Критикуйте, предлагайте. | ||
Вся информация в wiki. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
if [ ! -d oclint ]; then | ||
git clone https://github.com/oclint/oclint.git oclint | ||
cd oclint | ||
git reset --hard d776db51c8574df406b2b0dc1b43b0b9b2d86d34 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хэш коммита вынести в отдельную переменную |
||
cd .. | ||
fi | ||
|
||
cd oclint/oclint-scripts | ||
./make |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int x = 0; | ||
cin >> x; | ||
|
||
if (x == 0) { | ||
cout << "Zero"; | ||
} | ||
else if (x == 1) { | ||
cout << "One"; | ||
} | ||
else if (x == 2) { | ||
cout << "Two"; | ||
} | ||
else if (x == 3) { | ||
cout << "Three"; | ||
} | ||
if (x == 4) { | ||
cout << "Four"; | ||
} | ||
else if (x == 5) { | ||
cout << "Five"; | ||
} | ||
if (x == 6) { | ||
cout << "Six"; | ||
} | ||
if (x == 7) { | ||
cout << "Seven"; | ||
} | ||
else if (x == 8) { | ||
cout << "Eight"; | ||
} | ||
else if (x == 9) { | ||
cout << "Nine"; | ||
} | ||
else { | ||
cout << "Something else"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.PHONY: all | ||
|
||
all: prog | ||
|
||
prog: stuff.o main.o | ||
gcc stuff.o main.o | ||
|
||
stuff.o: src/stuff.c include/obfuscation.h include/stuff.h | ||
gcc -c -I ./include src/stuff.c | ||
|
||
main.o: src/main.c include/stuff.h | ||
gcc -c -I ./include src/main.c |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include <stdio.h> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef TEST_STUFF_H | ||
#define TEST_STUFF_H | ||
|
||
void do_stuff(int x); | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
#include "stuff.h" | ||
|
||
int main() | ||
{ | ||
int x = 0; | ||
scanf("%d", &x); | ||
|
||
do_stuff(x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
printf("OK!!!!\n"); | ||
return 0; | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cp -r oclint/build/oclint-release/lib/* /usr/local/lib/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно добавить аргумент -- куда конкретно устанавливать There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Заодно нужно это добавить в |
This file was deleted.
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тесты надо оставить, это хорошая практика, позволяет проверять, что ничего из работающего раньше не сломалось |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В README нужно хотя бы оставить простейшую инструкцию (без деталей) как собрать и запустить. Для деталей можно оставить ссылку на конкретные страницы на вики