forked from microsoft/verona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
150 lines (131 loc) · 4.73 KB
/
CMakeLists.txt
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
enable_testing()
find_program(DIFF_TOOL NAMES
diff)
if (DIFF_TOOL STREQUAL DIFF_TOOL-NOTFOUND)
set(DIFF_TOOL "")
endif()
set(DISABLED_TESTS)
set(GOLDEN_DIR_SUFFIX "_out")
set(VERONA_LOCAL_DIST ${CMAKE_BINARY_DIR}/dist)
message("Verona local dist: ${VERONA_LOCAL_DIST}")
function(subdirlist result curdir)
file(GLOB children LIST_DIRECTORIES true CONFIGURE_DEPENDS RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
list(APPEND dirlist ${child})
endif()
endforeach()
set(${result} ${dirlist} PARENT_SCOPE)
endfunction()
# Iterate each tool
subdirlist(TOOL_FOLDERS ${CMAKE_CURRENT_SOURCE_DIR})
set(UPDATE_DUMPS_TARGETS)
foreach(TOOL ${TOOL_FOLDERS})
if (TOOL MATCHES "deprecated")
continue()
endif()
set (test_set)
set(TOOL_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${TOOL})
# Grab specific settings for this tool
include(${CMAKE_CURRENT_LIST_DIR}/${TOOL}.cmake)
# Use transform to support multiple extension for tests,
# and find all the files with these extensions.
list(TRANSFORM TEST_EXTENSION PREPEND ${TOOL_FOLDER}/*.)
file(GLOB_RECURSE tests CONFIGURE_DEPENDS RELATIVE ${TOOL_FOLDER} ${TEST_EXTENSION})
foreach(test ${tests})
get_filename_component(test_name ${test} NAME_WE)
get_filename_component(test_file ${test} NAME)
get_filename_component(test_dir ${test} DIRECTORY)
if (test_dir STREQUAL "")
set (test_path ${TOOL}/${test_name})
else()
set (test_path ${TOOL}/${test_dir}/${test_name})
endif()
list (FIND DISABLED_TESTS ${test_path} INDEX)
if (NOT ${INDEX} EQUAL -1)
message("Test currently disabled ${test_path}")
continue()
endif()
# Create command to create the output for this test.
set (output_dir ${CMAKE_CURRENT_BINARY_DIR}/${test_path}${GOLDEN_DIR_SUFFIX})
set (test_output_cmd
${CMAKE_COMMAND}
-DTESTFILE=${test_file}
-DWORKING_DIR=${TOOL_FOLDER}/${test_dir}
-DTOOLNAME=${TOOL}
-DCMAKE_EXECUTABLE_SUFFIX=${CMAKE_EXECUTABLE_SUFFIX}
-DVERONA_LOCAL_DIST=${VERONA_LOCAL_DIST}
-DOUTPUT_DIR=${output_dir}
-P ${CMAKE_CURRENT_SOURCE_DIR}/run_command.cmake
)
# Add test that rebuilds the compiler output
add_test(NAME ${test_path}${GOLDEN_DIR_SUFFIX}
COMMAND ${test_output_cmd}
)
# Add command that rebuilts the compiler output for updating golden files.
add_custom_command(OUTPUT ${test_path}
COMMAND ${test_output_cmd}
)
set_source_files_properties(${test_path} PROPERTIES SYMBOLIC "true")
list(APPEND test_set ${test_path})
# Add output comparison for each golden / output file
set (golden_dir ${CMAKE_CURRENT_SOURCE_DIR}/${test_path}${GOLDEN_DIR_SUFFIX} )
file (GLOB_RECURSE results CONFIGURE_DEPENDS RELATIVE ${golden_dir} ${golden_dir}/*)
# Check if there are any files to compare for this test.
list(LENGTH results res_length)
if(res_length EQUAL 0)
message(WARNING "Test does not have results directory: ${golden_dir}\nRun `update-dump` to generate golden files.")
# Add to generate golden output target
add_custom_command(OUTPUT ${test_path}
COMMAND
${CMAKE_COMMAND}
-E make_directory
${golden_dir}
APPEND
)
add_custom_command(OUTPUT ${test_path}
COMMAND
${CMAKE_COMMAND}
-E copy_if_different
${output_dir}/*
${golden_dir}/
APPEND
)
else()
foreach (result ${results})
# Check each file is correct as a test target
add_test (NAME ${test_path}${GOLDEN_DIR_SUFFIX}/${result}
COMMAND
${CMAKE_COMMAND}
-Doriginal_file=${golden_dir}/${result}
-Dnew_file=${output_dir}/${result}
-Ddiff_tool=${DIFF_TOOL}
-P ${CMAKE_CURRENT_SOURCE_DIR}/compare.cmake
)
set_tests_properties(${test_path}${GOLDEN_DIR_SUFFIX}/${result} PROPERTIES DEPENDS ${test_path}${GOLDEN_DIR_SUFFIX})
# Override out of date files.
add_custom_command(OUTPUT ${test_path}
COMMAND
${CMAKE_COMMAND}
-E copy_if_different
${output_dir}/${result}
${golden_dir}/${result}
APPEND
)
endforeach()
# All tests require an error_code.
add_custom_command(OUTPUT ${test_path}
COMMAND
${CMAKE_COMMAND}
-E copy_if_different
${output_dir}/exit_code.txt
${golden_dir}/exit_code.txt
APPEND
)
endif()
endforeach()
add_custom_target("update-dump-${TOOL}" DEPENDS ${test_set})
list(APPEND UPDATE_DUMPS_TARGETS "update-dump-${TOOL}")
endforeach()
add_custom_target(update-dump DEPENDS ${UPDATE_DUMPS_TARGETS})