forked from luooofan/miniob-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclang_check.cmake
111 lines (97 loc) · 4.27 KB
/
clang_check.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
set(MINIOB_BUILD_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/build_support")
set(MINIOB_CLANG_SEARCH_PATH "/usr/local/bin" "/usr/bin" "/usr/local/opt/llvm/bin" "/usr/local/opt/llvm@10/bin")
######################################################################################################################
# DEPENDENCIES
######################################################################################################################
# clang-format
if (NOT DEFINED CLANG_FORMAT_BIN)
# attempt to find the binary if user did not specify
find_program(CLANG_FORMAT_BIN
NAMES clang-format clang-format-10
HINTS ${MINIOB_CLANG_SEARCH_PATH})
endif()
if ("${CLANG_FORMAT_BIN}" STREQUAL "CLANG_FORMAT_BIN-NOTFOUND")
message(WARNING "MiniOb/main couldn't find clang-format.")
else()
message(STATUS "MiniOb/main found clang-format at ${CLANG_FORMAT_BIN}")
endif()
# clang-tidy
if (NOT DEFINED CLANG_TIDY_BIN)
# attempt to find the binary if user did not specify
find_program(CLANG_TIDY_BIN
NAMES clang-tidy clang-tidy-10
HINTS ${MINIOB_CLANG_SEARCH_PATH})
endif()
if ("${CLANG_TIDY_BIN}" STREQUAL "CLANG_TIDY_BIN-NOTFOUND")
message(WARNING "MiniOb/main couldn't find clang-tidy.")
else()
# Output compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
message(STATUS "MiniOb/main found clang-tidy at ${CLANG_TIDY_BIN}")
endif()
# cpplint
find_program(CPPLINT_BIN
NAMES cpplint cpplint.py
HINTS "${MINIOB_BUILD_SUPPORT_DIR}")
if ("${CPPLINT_BIN}" STREQUAL "CPPLINT_BIN-NOTFOUND")
message(WARNING "MiniOb/main couldn't find cpplint.")
else()
message(STATUS "MiniOb/main found cpplint at ${CPPLINT_BIN}")
endif()
######################################################################################################################
# MAKE TARGETS
######################################################################################################################
##########################################
# "make format"
# "make check-format"
##########################################
string(CONCAT MINIOB_FORMAT_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}/src,"
"${CMAKE_CURRENT_SOURCE_DIR}/test,"
"${CMAKE_CURRENT_SOURCE_DIR}/unittest,"
)
# runs clang format and updates files in place.
add_custom_target(format ${MINIOB_BUILD_SUPPORT_DIR}/run_clang_format.py
${CLANG_FORMAT_BIN}
${MINIOB_BUILD_SUPPORT_DIR}/clang_format_exclusions.txt
--source_dirs
${MINIOB_FORMAT_DIRS}
--fix
--quiet
)
# runs clang format and exits with a non-zero exit code if any files need to be reformatted
add_custom_target(check-format ${MINIOB_BUILD_SUPPORT_DIR}/run_clang_format.py
${CLANG_FORMAT_BIN}
${MINIOB_BUILD_SUPPORT_DIR}/clang_format_exclusions.txt
--source_dirs
${MINIOB_FORMAT_DIRS}
--quiet
)
##########################################
# "make check-lint"
##########################################
file(GLOB_RECURSE MINIOB_LINT_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp"
)
# Balancing act: cpplint.py takes a non-trivial time to launch,
# so process 12 files per invocation, while still ensuring parallelism
add_custom_target(check-lint echo '${MINIOB_LINT_FILES}' | xargs -n12 -P8
${CPPLINT_BIN}
--verbose=2 --quiet
--linelength=120
--filter=-legal/copyright,-build/header_guard
)
###########################################################
# "make check-clang-tidy" target
###########################################################
# runs clang-tidy and exits with a non-zero exit code if any errors are found.
# note that clang-tidy automatically looks for a .clang-tidy file in parent directories
add_custom_target(check-clang-tidy
${MINIOB_BUILD_SUPPORT_DIR}/run_clang_tidy.py # run LLVM's clang-tidy script
-clang-tidy-binary ${CLANG_TIDY_BIN} # using our clang-tidy binary
-p ${CMAKE_BINARY_DIR} # using cmake's generated compile commands
'.*/src/observer/sql/.*?/\(?!\(lex|yacc\)\).*cpp'
)