| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
include(TribitsGetPackageEnableStatus) |
| 11 |
|
| 12 |
|
| 13 |
# @FUNCTION: tribits_filter_package_list_from_var() |
| 14 |
# |
| 15 |
# Filter a list of packages based on several criteria including |
| 16 |
# internal/external, enable status (with empty or non-empty) |
| 17 |
# |
| 18 |
# Usage:: |
| 19 |
# |
| 20 |
# tribits_filter_package_list_from_var( <packageListVarName> |
| 21 |
# <internalOrExternal> <enabledFlag> <enableEmptyStatus> |
| 22 |
# <packageSublistOut> ) |
| 23 |
# |
| 24 |
# Where: |
| 25 |
# |
| 26 |
# * ``<packageListVarName>``: Name of input list var of packages |
| 27 |
# * ``<internalOrExternal>``: ``INTERNAL``, ``EXTERNAL`` or "" (i.e. both |
| 28 |
# INTERNAL and EXTERNAL packages) (matches |
| 29 |
# ``<Package>_PACKAGE_BUILD_STATUS``) |
| 30 |
# * ``<enabledFlag>``: ``ON`` for elements that match ``TRUE`` , ``OFF`` |
| 31 |
# for elements that match ``FALSE`` |
| 32 |
# * ``<enableEmptyStatus>``: Enable status is ``NONEMPTY`` (i.e. must have a |
| 33 |
# value) or ``INCLUDE_EMPTY`` (matches those with a value and with empty |
| 34 |
# ""). |
| 35 |
# * ``<packageSublistOut>``: The name of the var that will store the filtered |
| 36 |
# sublist of packages. |
| 37 |
# |
| 38 |
function(tribits_filter_package_list_from_var packageListVarName |
| 39 |
internalOrExternal enabledFlag enableEmptyStatus packageSublistOut |
| 40 |
) |
| 41 |
tribits_assert_include_empty_param(${enableEmptyStatus}) |
| 42 |
tribits_get_sublist_internal_external(${packageListVarName} "${internalOrExternal}" |
| 43 |
packageListTmp "") |
| 44 |
if (enabledFlag AND (enableEmptyStatus STREQUAL "NONEMPTY")) |
| 45 |
tribits_get_sublist_enabled(packageListTmp |
| 46 |
packageSublist "") |
| 47 |
elseif (enabledFlag AND (enableEmptyStatus STREQUAL "INCLUDE_EMPTY")) |
| 48 |
tribits_get_sublist_nondisabled(${packageListTmp} packageSublist "") |
| 49 |
elseif (NOT enabledFlag AND (enableEmptyStatus STREQUAL "NONEMPTY")) |
| 50 |
tribits_get_sublist_disabled(packageListTmp |
| 51 |
packageSublist "") |
| 52 |
elseif (NOT enabledFlag AND (enableEmptyStatus STREQUAL "INCLUDE_EMPTY")) |
| 53 |
tribits_get_sublist_nonenabled(packageListTmp |
| 54 |
packageSublist "") |
| 55 |
else() |
| 56 |
message(FATAL_ERROR "Should never get here!") |
| 57 |
endif() |
| 58 |
set(${packageSublistOut} ${packageSublist} PARENT_SCOPE) |
| 59 |
endfunction() |
| 60 |
|
| 61 |
|
| 62 |
# @FUNCTION: tribits_get_sublist_enabled() |
| 63 |
# |
| 64 |
# Get sub-list of enabled packages |
| 65 |
# |
| 66 |
# Usage:: |
| 67 |
# |
| 68 |
# tribits_get_sublist_enabled( <enableListName> |
| 69 |
# <enabledSublistNameOut> [<numEnabledVarOut>] ) |
| 70 |
# |
| 71 |
# On output, ``<enabledSublistNameOut>`` contains the sublist of entries in |
| 72 |
# ``<enableListName>`` which evaluate to ``TRUE`` in an ``if ()`` statement. |
| 73 |
# |
| 74 |
function(tribits_get_sublist_enabled enableListName |
| 75 |
enabledSublistNameOut numEnabledVarOut |
| 76 |
) |
| 77 |
set(enabledSublist) |
| 78 |
foreach(pkgName IN LISTS ${enableListName}) |
| 79 |
tribits_get_package_enable_status(${pkgName} enableVal "") |
| 80 |
if (enableVal) |
| 81 |
list(APPEND enabledSublist ${pkgName}) |
| 82 |
endif() |
| 83 |
endforeach() |
| 84 |
list(LENGTH enabledSublist numEnabled) |
| 85 |
set(${enabledSublistNameOut} ${enabledSublist} PARENT_SCOPE) |
| 86 |
if (numEnabledVarOut) |
| 87 |
set(${numEnabledVarOut} ${numEnabled} PARENT_SCOPE) |
| 88 |
endif() |
| 89 |
endfunction() |
| 90 |
|
| 91 |
|
| 92 |
# @FUNCTION: tribits_get_sublist_nondisabled() |
| 93 |
# |
| 94 |
# Get sub-list of non-disabled packages |
| 95 |
# |
| 96 |
# Usage:: |
| 97 |
# |
| 98 |
# tribits_get_sublist_nondisabled( <enableListName> |
| 99 |
# <nondisabledListNameOut> [<numNondisabledVarOut>] ) |
| 100 |
# |
| 101 |
# On output, ``<nondisabledListNameOut>`` contains the sublist of entries from |
| 102 |
# ``<enableListName>`` for which evaluate to ``TRUE`` or empty ``""`` in an |
| 103 |
# ``if ()`` statement. |
| 104 |
# |
| 105 |
function(tribits_get_sublist_nondisabled enableListName |
| 106 |
nondisabledListNameOut numNondisabledVarOut |
| 107 |
) |
| 108 |
set(nondisabledList "") |
| 109 |
foreach(pkgName IN LISTS ${enableListName}) |
| 110 |
tribits_get_package_enable_status(${pkgName} enableVal "") |
| 111 |
if (enableVal OR "${enableVal}" STREQUAL "") |
| 112 |
list(APPEND nondisabledList ${pkgName}) |
| 113 |
endif() |
| 114 |
endforeach() |
| 115 |
list(LENGTH nondisabledList numNondisabled) |
| 116 |
set(${nondisabledListNameOut} ${nondisabledList} PARENT_SCOPE) |
| 117 |
if (numNondisabledVarOut) |
| 118 |
set(${numNondisabledVarOut} ${numNondisabled} PARENT_SCOPE) |
| 119 |
endif() |
| 120 |
endfunction() |
| 121 |
|
| 122 |
|
| 123 |
# @FUNCTION: tribits_get_sublist_disabled() |
| 124 |
# |
| 125 |
# Get sub-list of disabled packages |
| 126 |
# |
| 127 |
# Usage:: |
| 128 |
# |
| 129 |
# tribits_get_sublist_disabled( <enableListName> |
| 130 |
# <disabledSublistNameOut> [<numDisabledVarOut>] ) |
| 131 |
# |
| 132 |
# On output, ``<disabledSublistNameOut>`` contains the sublist of entries |
| 133 |
# ``<enableListName>`` which evaluate to ``FALSE`` and is not empty ``""`` in |
| 134 |
# an ``if ()`` statement. |
| 135 |
# |
| 136 |
function(tribits_get_sublist_disabled enableListName |
| 137 |
disabledSublistNameOut numDisabledVarOut |
| 138 |
) |
| 139 |
set(disabledSublist "") |
| 140 |
foreach(pkgName IN LISTS ${enableListName}) |
| 141 |
tribits_get_package_enable_status(${pkgName} enableVal "") |
| 142 |
if ((NOT enableVal) AND (NOT "${enableVal}" STREQUAL "")) |
| 143 |
list(APPEND disabledSublist ${pkgName}) |
| 144 |
endif() |
| 145 |
endforeach() |
| 146 |
list(LENGTH disabledSublist numDisabled) |
| 147 |
set(${disabledSublistNameOut} ${disabledSublist} PARENT_SCOPE) |
| 148 |
if (numDisabledVarOut) |
| 149 |
set(${numDisabledVarOut} ${numDisabled} PARENT_SCOPE) |
| 150 |
endif() |
| 151 |
endfunction() |
| 152 |
|
| 153 |
|
| 154 |
# @FUNCTION: tribits_get_sublist_nonenabled() |
| 155 |
# |
| 156 |
# Get sub-list of non-enabled entries |
| 157 |
# |
| 158 |
# Usage:: |
| 159 |
# |
| 160 |
# tribits_get_sublist_nonenabled( <enableListName> |
| 161 |
# <nonenabledListNameOut> [<numNonenabledVarOut>] ) |
| 162 |
# |
| 163 |
# On output, ``<nonenabledListNameOut>`` contains the subset of entries in |
| 164 |
# ``<enableListName>`` that evaluate to ``FALSE`` (which can also be empty |
| 165 |
# ``""``) in an ``if ()`` statement. |
| 166 |
# |
| 167 |
function(tribits_get_sublist_nonenabled enableListName |
| 168 |
nonenabledListNameOut numNonenabledVarOut |
| 169 |
) |
| 170 |
set(nonenabledList "") |
| 171 |
foreach(pkgName IN LISTS ${enableListName}) |
| 172 |
tribits_get_package_enable_status(${pkgName} enableVal "") |
| 173 |
if (NOT enableVal) |
| 174 |
list(APPEND nonenabledList ${pkgName}) |
| 175 |
endif() |
| 176 |
endforeach() |
| 177 |
list(LENGTH nonenabledList numNonenabled) |
| 178 |
set(${nonenabledListNameOut} ${nonenabledList} PARENT_SCOPE) |
| 179 |
if (numNonenabledVarOut) |
| 180 |
set(${numNonenabledVarOut} ${numNonenabled} PARENT_SCOPE) |
| 181 |
endif() |
| 182 |
endfunction() |
| 183 |
|
| 184 |
|
| 185 |
# @FUNCTION: tribits_get_sublist_internal_external() |
| 186 |
# |
| 187 |
# Get sub-list of packages that are INTERNAL, EXTERNAL, or either. |
| 188 |
# |
| 189 |
# Usage:: |
| 190 |
# |
| 191 |
# tribits_get_sublist_internal_external( <inputPackageListName> <internalOrExternal> |
| 192 |
# <sublistNameOut> [<sizeSublistOut>] ) |
| 193 |
# |
| 194 |
# where: |
| 195 |
# |
| 196 |
# * `<internalOrExternal>` is either `INTERNAL`, `EXTERNAL` or empty "". |
| 197 |
# |
| 198 |
# On output, ``<sublistNameOut>`` contains the sublist of entries in |
| 199 |
# ``<inputPackageListName>`` which are either `INTERNAL` or `EXTERNAL` or both |
| 200 |
# (if `<internalOrExternal>` is "") based on `<Package>_PACKAGE_BUILD_STATUS` |
| 201 |
# for each element package name. |
| 202 |
# |
| 203 |
function(tribits_get_sublist_internal_external inputPackageListName internalOrExternal |
| 204 |
sublistNameOut sizeSublistOut |
| 205 |
) |
| 206 |
tribits_assert_internal_or_external_arg("${internalOrExternal}") |
| 207 |
if (NOT internalOrExternal STREQUAL "") |
| 208 |
set(sublist "") |
| 209 |
foreach(pkgName IN LISTS ${inputPackageListName}) |
| 210 |
if (${pkgName}_PACKAGE_BUILD_STATUS STREQUAL internalOrExternal) |
| 211 |
list(APPEND sublist ${pkgName}) |
| 212 |
endif() |
| 213 |
endforeach() |
| 214 |
else() |
| 215 |
set(sublist ${${inputPackageListName}}) |
| 216 |
endif() |
| 217 |
set(${sublistNameOut} ${sublist} PARENT_SCOPE) |
| 218 |
if (numEnabledVarOut) |
| 219 |
list(LENGTH sublist sizeSublist) |
| 220 |
set(${sizeSublistOut} ${sizeSublist} PARENT_SCOPE) |
| 221 |
endif() |
| 222 |
endfunction() |
| 223 |
|
| 224 |
|
| 225 |
function(tribits_assert_internal_or_external_arg internalOrExternal) |
| 226 |
set(allowedValuesList "INTERNAL" "EXTERNAL" "") |
| 227 |
if (NOT internalOrExternal IN_LIST allowedValuesList) |
| 228 |
message(FATAL_ERROR "ERROR, the argument internalOrExternal=" |
| 229 |
"'${internalOrExternal}' is not in the list of allowed values" |
| 230 |
${allowedValuesList} ) |
| 231 |
endif() |
| 232 |
endfunction() |
| 233 |
|
| 234 |
|
| 235 |
function(tribits_assert_include_empty_param enableEmptyStatus) |
| 236 |
if ((NOT enableEmptyStatus STREQUAL "NONEMPTY") AND |
| 237 |
(NOT enableEmptyStatus STREQUAL "INCLUDE_EMPTY") |
| 238 |
) |
| 239 |
message(FATAL_ERROR "Error, argument enableEmptyStatus='${enableEmptyStatus}'" |
| 240 |
" is invalid! Use 'NONEMPTY' or 'INCLUDE_EMPTY'.") |
| 241 |
endif() |
| 242 |
endfunction() |