blob: eebb2d1d41c509d3614b0c28e54116604468f0ce (
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
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
|
# SPDX-License-Identifier: GPL-3.0-or-later
foreach(Variable IN ITEMS RCC_TIDY_GIT RCC_TIDY_SOURCE_DIR RCC_TIDY_BINARY_DIR RCC_TIDY_BASE
RCC_TIDY_JOBS RCC_TIDY_DIFF)
if(NOT DEFINED ${Variable} OR "${${Variable}}" STREQUAL "")
message(FATAL_ERROR "${Variable} is required for incremental clang-tidy")
endif()
endforeach()
execute_process(
COMMAND "${RCC_TIDY_GIT}" -C "${RCC_TIDY_SOURCE_DIR}" rev-parse --show-toplevel
RESULT_VARIABLE GitRootResult
OUTPUT_VARIABLE GitRoot
ERROR_VARIABLE GitRootError
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GitRootResult EQUAL 0)
message(FATAL_ERROR "cannot locate the Git worktree: ${GitRootError}")
endif()
file(RELATIVE_PATH TidyPath "${GitRoot}" "${RCC_TIDY_SOURCE_DIR}")
if(TidyPath MATCHES "^\\.\\.")
message(FATAL_ERROR "backend source directory is outside its Git worktree")
endif()
set(DiffFile "${RCC_TIDY_BINARY_DIR}/CMakeFiles/rcc-backend-clang-tidy.diff")
execute_process(
COMMAND "${RCC_TIDY_GIT}" -C "${GitRoot}" diff --no-ext-diff --unified=0 --merge-base
"${RCC_TIDY_BASE}" -- "${TidyPath}"
RESULT_VARIABLE DiffResult
OUTPUT_FILE "${DiffFile}"
ERROR_VARIABLE DiffError
)
if(NOT DiffResult EQUAL 0)
message(FATAL_ERROR "cannot produce incremental clang-tidy diff: ${DiffError}")
endif()
# git diff does not include untracked source files. Add their ordinary Git diff form so
# LLVM's unchanged clang-tidy-diff.py driver checks new translation units before staging.
execute_process(
COMMAND "${RCC_TIDY_GIT}" -C "${GitRoot}" ls-files --others --exclude-standard -- "${TidyPath}"
RESULT_VARIABLE UntrackedResult
OUTPUT_VARIABLE UntrackedFiles
ERROR_VARIABLE UntrackedError
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT UntrackedResult EQUAL 0)
message(FATAL_ERROR "cannot list untracked clang-tidy files: ${UntrackedError}")
endif()
if(NOT UntrackedFiles STREQUAL "")
string(REPLACE "\n" ";" UntrackedFiles "${UntrackedFiles}")
foreach(UntrackedFile IN LISTS UntrackedFiles)
execute_process(
COMMAND "${RCC_TIDY_GIT}" -C "${GitRoot}" diff --no-index --no-ext-diff --unified=0 --
/dev/null "${UntrackedFile}"
RESULT_VARIABLE UntrackedDiffResult
OUTPUT_VARIABLE UntrackedDiff
ERROR_VARIABLE UntrackedDiffError
)
if(NOT UntrackedDiffResult EQUAL 0 AND NOT UntrackedDiffResult EQUAL 1)
message(FATAL_ERROR "cannot diff untracked file '${UntrackedFile}': ${UntrackedDiffError}")
endif()
file(APPEND "${DiffFile}" "${UntrackedDiff}")
endforeach()
endif()
execute_process(
COMMAND "${RCC_TIDY_DIFF}" -path "${RCC_TIDY_BINARY_DIR}" -p1 -quiet -j "${RCC_TIDY_JOBS}"
INPUT_FILE "${DiffFile}"
WORKING_DIRECTORY "${GitRoot}"
RESULT_VARIABLE TidyResult
OUTPUT_VARIABLE TidyOutput
ERROR_VARIABLE TidyError
)
set(TidyDiagnostics "${TidyOutput}\n${TidyError}")
string(REGEX REPLACE "[0-9]+ warnings generated\\." "" TidyDiagnostics "${TidyDiagnostics}")
string(STRIP "${TidyDiagnostics}" TidyDiagnostics)
if(TidyResult EQUAL 0 AND TidyDiagnostics STREQUAL "No relevant changes found.")
set(TidyDiagnostics "")
endif()
if(NOT TidyDiagnostics STREQUAL "")
message("${TidyDiagnostics}")
endif()
if(NOT TidyResult EQUAL 0 OR NOT TidyDiagnostics STREQUAL "")
message(FATAL_ERROR "incremental clang-tidy failed")
endif()
|