blob: 9713f576c8a71039880773b38f8b8d1ef2a6b77a (
plain)
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
|
file(GLOB_RECURSE PROJECT_C_SOURCES
"${SOURCE_DIR}/src/*.c"
"${SOURCE_DIR}/src/*.h"
)
foreach(source IN LISTS PROJECT_C_SOURCES)
file(READ "${source}" contents)
if(contents MATCHES "(^|[^A-Za-z0-9_])goto([^A-Za-z0-9_]|$)")
message(FATAL_ERROR "goto is forbidden in project source: ${source}")
endif()
if(contents MATCHES "#define[ \t]+static" OR contents MATCHES "#include[ \t]+\"[^\"]+\\.c\"")
message(FATAL_ERROR "test-only source visibility hack found: ${source}")
endif()
string(FIND "${source}" "/src/sys/" sys_position)
if(sys_position EQUAL -1 AND
contents MATCHES "windows\\.h|GetFullPathNameW|CreateFileW|ReadFile|WriteFile|MoveFileExW|BCryptGenRandom")
message(FATAL_ERROR "OS-specific API reference outside src/sys: ${source}")
endif()
endforeach()
if(NOT CLANG_FORMAT_EXECUTABLE STREQUAL "")
execute_process(
COMMAND "${CLANG_FORMAT_EXECUTABLE}" --dry-run --Werror ${PROJECT_C_SOURCES}
RESULT_VARIABLE format_result
OUTPUT_VARIABLE format_output
ERROR_VARIABLE format_error
)
if(NOT format_result EQUAL 0)
message(FATAL_ERROR "clang-format check failed:\n${format_output}${format_error}")
endif()
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" diff --check
WORKING_DIRECTORY "${SOURCE_DIR}"
RESULT_VARIABLE diff_result
OUTPUT_VARIABLE diff_output
ERROR_VARIABLE diff_error
)
if(NOT diff_result EQUAL 0)
message(FATAL_ERROR "git diff --check failed:\n${diff_output}${diff_error}")
endif()
|