forked from josephsnyder/VistA-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonFunctions.cmake
176 lines (169 loc) · 7.41 KB
/
CommonFunctions.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#---------------------------------------------------------------------------
# Copyright 2011-2012 The Open Source Electronic Health Record Agent
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Define a function for parsing and reporting XINDEX output results
function(ReportXINDEXResult PACKAGE_NAME PACKAGES_DIR VENDOR_NAME GREP_EXEC OUTPUT USE_XINDEX_WARNINGS_AS_FAILURES TEST_VISTA_XINDEX_IGNORE_EXCEPTIONS)
if(USE_XINDEX_WARNINGS_AS_FAILURES)
set(FAILURE_CONDITION "F -|W -")
else()
set(FAILURE_CONDITION "F -")
endif()
set(test_passed TRUE)
if(ARGC GREATER 7)
set(source_flag TRUE)
endif()
string(REPLACE "_" " " PACKAGE_NAME ${PACKAGE_NAME})
foreach (line ${OUTPUT})
# the XINDEX will always check the integrity of the routine using checksum
if(line MATCHES "^[A-Za-z0-9%][^ ]+ +\\* \\* .*[cC]hecksum:.*")
string(REGEX MATCH "^[A-Za-z0-9%]+[^ ]" routine_name "${line}")
elseif(line MATCHES ${FAILURE_CONDITION})
# also assume the file name is ${PACKAGE_NAME}.${routinename}
set(ExceptionFound FALSE)
if (EXISTS ${PACKAGES_DIR}/${PACKAGE_NAME}/XINDEXException/${VENDOR_NAME}.${routine_name} AND NOT TEST_VISTA_XINDEX_IGNORE_EXCEPTIONS)
file(STRINGS ${PACKAGES_DIR}/${PACKAGE_NAME}/XINDEXException/${VENDOR_NAME}.${routine_name} ExceptionList)
foreach (Exception ${ExceptionList})
string(STRIP "${line}" newline)
# this is quite stricty to ensure the text is the exactly the same
if ("${Exception}" STREQUAL "${newline}")
set(ExceptionFound TRUE)
break()
endif()
endforeach()
endif()
if (NOT ExceptionFound)
string(REGEX MATCH ^\ \ \ [A-Z0-9]+ tag ${line})
message("${routine_name} in package ${PACKAGE_NAME}:\n${line}")
if(tag AND GREP_EXEC AND source_flag)
string(REGEX MATCH "\\+[0-9]+" position ${line})
string(STRIP ${tag} tag)
execute_process(COMMAND ${GREP_EXEC} -n -h ^${tag}
"${ARGV7}/Packages/${PACKAGE_NAME}/Routines/${routine_name}.m"
OUTPUT_VARIABLE linematch)
if(linematch)
string(REGEX MATCH ^[0-9]+ linenumber ${linematch})
math(EXPR errorposition ${linenumber}${position})
message("Error is found in ${routine_name}.m on line: ${errorposition}\n")
endif()
endif()
set(test_passed FALSE)
endif()
endif()
endforeach()
if(test_passed)
string(REPLACE ";" "\n" OUTPUT "${OUTPUT}")
message("${PACKAGE_NAME} Passed:\n${OUTPUT}")
else()
message(FATAL_ERROR "${PACKAGE_NAME} has XINDEX Errors")
endif()
endfunction()
# Define a function for parsing and reporting munit output results
function(ReportUnitTestResult PACKAGE_NAME DIRNAME OUTPUT)
set(test_passed TRUE)
set(routine_name "NONE")
foreach (line ${OUTPUT})
# Matches the command that runs the test, keeps the routine name
if(line MATCHES ">D [A-Z0-9]*\\^[%a-zA-Z0-9]+")
string(REGEX MATCH "[%a-zA-Z0-9]+$" routine_name "${line}")
# Captures and prints the failure message
elseif(line MATCHES "^ ?[^\\^]+\\^${routine_name}+")
message("${routine_name}: ${line}")
if(NOT ${line} MATCHES [iI]ntentional)
set(test_passed FALSE)
endif()
# Matches the second part of the results line, checking for errors
elseif(line MATCHES "encountered [1-9]+ error")
message("M Error(s) encountered in ${routine_name} in package ${PACKAGE_NAME}")
set(test_passed FALSE)
endif()
endforeach()
if(test_passed)
string(REPLACE ";" "\n" OUTPUT "${OUTPUT}")
message("${PACKAGE_NAME} Passed:\n${OUTPUT}")
else()
message(FATAL_ERROR "${PACKAGE_NAME} unit test Errors")
endif()
endfunction()
function(FindPackages SOURCE_DIR)
file(STRINGS "${SOURCE_DIR}/Packages.csv" packages_csv)
list(REMOVE_AT packages_csv 0) # skip column label row
foreach(packages_csv_output IN LISTS packages_csv)
if(packages_csv_output MATCHES "^[^,]+,([^,]+),([^,]+),")
# Finds each package line to capture Package names and the default namespace
set(package_directory_name "${CMAKE_MATCH_1}")
string(REPLACE " " "_" package_directory_name_clean "${package_directory_name}")
list(APPEND packages_tmp ${package_directory_name_clean})
string(FIND ${CMAKE_MATCH_0} "," stringIndex)
string(SUBSTRING ${CMAKE_MATCH_0} 0 ${stringIndex} INTERNALNAME)
list(APPEND package_internal "${INTERNALNAME}")
# Captures each additional namespace from each line in the CSV file
elseif(packages_csv_output MATCHES "^,,([^,]+)")
endif()
endforeach()
set(PACKAGES ${packages_tmp} PARENT_SCOPE)
set(PACKAGES_INTERNAL ${package_internal} PARENT_SCOPE)
endfunction()
function(findPackageInfo SOURCE_DIR PACKAGE_NAME)
file(STRINGS "${SOURCE_DIR}/Packages.csv" packages_csv)
list(REMOVE_AT packages_csv 0) # skip column label row
message("Finding package information for: ${PACKAGE_NAME}")
foreach(packages_csv_output IN LISTS packages_csv)
if(packages_csv_output MATCHES "^[^,]+,([^,]+),([^,]+),([^,]+)")
# Finds each package line to capture Package names and the default namespace
if (${PACKAGE_NAME} STREQUAL ${CMAKE_MATCH_1})
set(IN_TARGET ON)
else()
set(IN_TARGET OFF)
endif()
if(IN_TARGET)
list(APPEND package_nmspc ${CMAKE_MATCH_2})
endif()
# Captures each additional namespace from each line in the CSV file
elseif(packages_csv_output MATCHES "^,,([^,]+)*,([^,]+)")
if(IN_TARGET)
if(CMAKE_MATCH_1)
list(APPEND package_nmspc ${CMAKE_MATCH_1})
endif()
if(CMAKE_MATCH_2)
list(APPEND package_fileNo ${CMAKE_MATCH_2})
endif()
endif()
endif()
endforeach()
set(PACKAGE_NAMESPACE ${package_nmspc} PARENT_SCOPE)
set(PACKAGE_FILE_NOS ${package_fileNo} PARENT_SCOPE)
endfunction()
function(SetVendorArgsConfig VendorArg VendorName Namespace Instance UserName Password)
set(vendor_args "")
if(VendorName STREQUAL "Cache")
list(APPEND vendor_args -S 1 -CN ${Namespace} -CI ${Instance})
string(STRIP "${UserName}" cacheusr)
string(LENGTH "${cacheusr}" userLen)
if(userLen)
list(APPEND vendor_args -CU "${UserName}" -CP "${Password}")
endif()
elseif(VendorName STREQUAL "GTM")
list(APPEND vendor_args -S 2)
endif()
set(${VendorArg} "${vendor_args}" PARENT_SCOPE)
endfunction()
function(SetVendorArgs VendorArg)
set(vendor_args "")
SetVendorArgsConfig(vendor_args "${VENDOR_NAME}" "${VISTA_CACHE_NAMESPACE}"
"${VISTA_CACHE_INSTANCE}" "${VISTA_CACHE_USERNAME}"
"${VISTA_CACHE_PASSWORD}")
set(${VendorArg} "${vendor_args}" PARENT_SCOPE)
endfunction()