| 1 |
# === This file is part of Calamares - <https://calamares.io> === |
| 2 |
# |
| 3 |
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <[email protected]> |
| 4 |
# SPDX-FileCopyrightText: 2017 Adriaan de Groot <[email protected]> |
| 5 |
# SPDX-License-Identifier: BSD-2-Clause |
| 6 |
# |
| 7 |
# Calamares is Free Software: see the License-Identifier above. |
| 8 |
# |
| 9 |
### |
| 10 |
# |
| 11 |
# This module implements the "skip modules" part of configuring |
| 12 |
# the Calamares repository or an external-modules repository. |
| 13 |
# |
| 14 |
# It should not be necessary to include() this module explicitly, |
| 15 |
# since both AddPlugin and AddModuleSubdirectory do so implicitly. |
| 16 |
# |
| 17 |
# |
| 18 |
# # Usage |
| 19 |
# |
| 20 |
# The public API is two functions: |
| 21 |
# |
| 22 |
# - calamares_skip_module(reason) |
| 23 |
# A C++ module (or any that uses CMake) can call this macro to |
| 24 |
# add *reason* to the list of skipped modules. Typically a module |
| 25 |
# will pass in "modulename (why)" so that it is clear **which** |
| 26 |
# module is skipped. This macro should be called at the top-level |
| 27 |
# of a module's CMakeLists.txt and the module should then **not** |
| 28 |
# call calamares_add_plugin(). |
| 29 |
# - calamares_explain_skipped_modules(list...) |
| 30 |
# This will print out all the module reasons (see above) that have |
| 31 |
# been added to the given *listvar*. When AddModuleSubdirectory is |
| 32 |
# used as the mechanism to add all the subdirectories in the repository |
| 33 |
# that contain modules, with a consistent *listvar* setting, |
| 34 |
# this will show all the modules that have been skipped. |
| 35 |
# |
| 36 |
# The internal API is one function: |
| 37 |
# |
| 38 |
# - calamares_check_skip(modulename outvar) |
| 39 |
# Checks if the *modulename* has been listed in the global SKIP_MODULES |
| 40 |
# variable (to skip specifically-named modules) or if there is a USE_* |
| 41 |
# setting applicable to the module. If the module is skipped for this |
| 42 |
# reason, a suitable entry is added to *outvar* as if |
| 43 |
# calamares_skip_module() had been called. |
| 44 |
# |
| 45 |
# Best practice is to pick a variable to collect all of the skipped |
| 46 |
# modules, and to pass the name of that variable to AddModuleSubdirectory |
| 47 |
# in each call. After all subdirectories have been added, call |
| 48 |
# calamares_explain_skipped_modules() with the value of that variable. |
| 49 |
|
| 50 |
|
| 51 |
# Convenience function to indicate that a module has been skipped |
| 52 |
# (optionally also why). Call this in the module's CMakeLists.txt |
| 53 |
macro( calamares_skip_module ) |
| 54 |
set( SKIPPED_MODULES ${SKIPPED_MODULES} ${ARGV} PARENT_SCOPE ) |
| 55 |
endmacro() |
| 56 |
|
| 57 |
function( calamares_explain_skipped_modules ) |
| 58 |
if ( ARGN ) |
| 59 |
message( "${ColorReset}-- Skipped modules:" ) |
| 60 |
foreach( SUBDIRECTORY ${ARGN} ) |
| 61 |
message( "${ColorReset}-- Skipped ${BoldRed}${SUBDIRECTORY}${ColorReset}." ) |
| 62 |
endforeach() |
| 63 |
message( "" ) |
| 64 |
endif() |
| 65 |
endfunction() |
| 66 |
|
| 67 |
# Globally, SKIP_MODULES and USE_* affect what modules are built. |
| 68 |
# Check if *modulename* should be skipped, and if so, set *outvar* to |
| 69 |
# a human-readable reason for skipping it. |
| 70 |
function( _calamares_check_skip_impl modulename outvar ) |
| 71 |
# Globally-defined SKIP_MODULES may be space- or semicolon- separated |
| 72 |
# so convert it to a list-variable. |
| 73 |
string( REPLACE " " ";" SKIP_LIST "${SKIP_MODULES}" ) |
| 74 |
|
| 75 |
list( FIND SKIP_LIST "${modulename}" DO_SKIP ) |
| 76 |
if( NOT DO_SKIP EQUAL -1 ) |
| 77 |
set( ${outvar} "user request" PARENT_SCOPE ) |
| 78 |
return() |
| 79 |
endif() |
| 80 |
|
| 81 |
# Not skipped by the global check, see if it has an applicable USE_* |
| 82 |
if( "${modulename}" MATCHES "^[a-zA-Z0-9_]+-" ) |
| 83 |
# Split the name into <category>-<implementation> |
| 84 |
string( REGEX REPLACE "-.*" "" _category "${modulename}" ) |
| 85 |
string( REGEX REPLACE "^[^-]+-" "" _implementation "${modulename}" ) |
| 86 |
else() |
| 87 |
# Not a module to which USE_* applies |
| 88 |
return() |
| 89 |
endif() |
| 90 |
|
| 91 |
if( "${USE_${_category}}" STREQUAL "none" ) |
| 92 |
set( ${outvar} "category ${_category} disabled" PARENT_SCOPE ) |
| 93 |
return() |
| 94 |
elseif( "${USE_${_category}}" STREQUAL "" ) |
| 95 |
# Category not set at all or nonexistent |
| 96 |
return() |
| 97 |
endif() |
| 98 |
|
| 99 |
if ( "${USE_${_category}}" STREQUAL "${_implementation}" ) |
| 100 |
# Matches, so accept this module |
| 101 |
else() |
| 102 |
set( ${outvar} "category ${_category} selects ${USE_${_category}}" PARENT_SCOPE ) |
| 103 |
endif() |
| 104 |
endfunction() |
| 105 |
|
| 106 |
# This is the public API;it calls the _impl version so that there |
| 107 |
# is an extra intermediate scope for the subdirectory to write results into. |
| 108 |
function( calamares_check_skip modulename outvar ) |
| 109 |
set( _skip "" ) |
| 110 |
_calamares_check_skip_impl( "${modulename}" _skip ) |
| 111 |
if ( _skip ) |
| 112 |
message( "${ColorReset}-- Skipping module ${BoldRed}${modulename} (${_skip})${ColorReset}." ) |
| 113 |
message( "" ) |
| 114 |
set( ${outvar} "${modulename} (${_skip})" PARENT_SCOPE ) |
| 115 |
endif() |
| 116 |
endfunction() |