mirror of
https://github.com/siemens-mobile-hacks/llvm-c166-tests.git
synced 2026-11-25 18:37:11 +00:00
32 lines
1.1 KiB
CMake
32 lines
1.1 KiB
CMake
if(NOT DEFINED INPUT OR NOT DEFINED PATTERNS)
|
|
message(FATAL_ERROR "CheckPatterns.cmake requires INPUT and PATTERNS")
|
|
endif()
|
|
|
|
file(STRINGS "${INPUT}" input_lines)
|
|
file(STRINGS "${PATTERNS}" patterns)
|
|
string(ASCII 9 tab)
|
|
foreach(pattern IN LISTS patterns)
|
|
string(STRIP "${pattern}" pattern)
|
|
if(pattern STREQUAL "" OR pattern MATCHES "^#")
|
|
continue()
|
|
endif()
|
|
set(required_count 1)
|
|
if(pattern MATCHES "^@([0-9]+)[ \\t]+(.+)$")
|
|
set(required_count "${CMAKE_MATCH_1}")
|
|
set(pattern "${CMAKE_MATCH_2}")
|
|
endif()
|
|
string(REPLACE "[[:space:]]" "[ ${tab}]" match_pattern "${pattern}")
|
|
set(found_count 0)
|
|
foreach(line IN LISTS input_lines)
|
|
if(line MATCHES "${match_pattern}")
|
|
math(EXPR found_count "${found_count} + 1")
|
|
endif()
|
|
endforeach()
|
|
if(FORBID AND found_count GREATER 0)
|
|
message(FATAL_ERROR
|
|
"forbidden pattern '${pattern}' occurs ${found_count} times in ${INPUT}")
|
|
elseif(NOT FORBID AND found_count LESS required_count)
|
|
message(FATAL_ERROR
|
|
"pattern '${pattern}' occurs ${found_count} times in ${INPUT}; expected at least ${required_count}")
|
|
endif()
|
|
endforeach()
|