From 3ed6f13fa8d293201dc616357230e12bcc67ce47 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 15 Jun 2018 09:32:19 -0400 Subject: [PATCH] [libcalamaresui] Adjust the emergency-ness of modules A potentially emergency module is one that has EMERGENCY (in CMake) or emergency: true (in module.desc) set. Any such module must also set emergency: true in the configuration of the module. This is to allow for instances of a module that **don't** run as emergency modules, alongside actual emergency ones. --- src/libcalamaresui/modulesystem/Module.cpp | 10 +++++++--- src/libcalamaresui/modulesystem/Module.h | 3 ++- src/modules/README.md | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index d334fda17..d131c9f13 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -52,6 +52,8 @@ name: "foo" #the module name. must be unique and same as the parent di interface: "qtplugin" #can be: qtplugin, python, process, ... */ +static const char EMERGENCY[] = "emergency"; + namespace Calamares { @@ -198,6 +200,9 @@ Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Ex } m_configurationMap = CalamaresUtils::yamlMapToVariant( doc ).toMap(); + m_emergency = m_maybe_emergency + && m_configurationMap.contains( EMERGENCY ) + && m_configurationMap[ EMERGENCY ].toBool(); return; } else @@ -291,10 +296,9 @@ Module::initFrom( const QVariantMap& moduleDescriptor ) { m_name = moduleDescriptor.value( "name" ).toString(); - auto em = QStringLiteral( "emergency" ); - if ( moduleDescriptor.contains( em ) ) + if ( moduleDescriptor.contains( EMERGENCY ) ) { - m_emergency = moduleDescriptor[ em ].toBool(); + m_maybe_emergency = moduleDescriptor[ EMERGENCY ].toBool(); } } diff --git a/src/libcalamaresui/modulesystem/Module.h b/src/libcalamaresui/modulesystem/Module.h index 219902b17..4fd0020f8 100644 --- a/src/libcalamaresui/modulesystem/Module.h +++ b/src/libcalamaresui/modulesystem/Module.h @@ -185,7 +185,8 @@ protected: QVariantMap m_configurationMap; bool m_loaded = false; - bool m_emergency = false; + bool m_emergency = false; // Based on module and local config + bool m_maybe_emergency = false; // Based on the module.desc private: void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception diff --git a/src/modules/README.md b/src/modules/README.md index 4b1d8ef2f..bd6cd4e37 100644 --- a/src/modules/README.md +++ b/src/modules/README.md @@ -145,3 +145,9 @@ processing continues. Use the EMERGENCY keyword in the CMake description of a C++ module to generate a suitable `module.desc`. + +A module that is marked as an emergency module in its module.desc +must **also** set the *emergency* key to *true* in its configuration file. +If it does not, the module is not considered to be an emergency module +after all (this is so that you can have modules that have several +instances, only some of which are actually needed for emergencies.