From def459a29d5d447a03ff228e3a4ccfa19725f6db Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 15 Jun 2018 07:11:17 -0400 Subject: [PATCH] [libcalamaresui] Read emergency setting from module.desc - Read setting from the module descriptor - Document optional settings - Add EMERGENCY keyword to the CMake helper functions --- CMakeModules/CalamaresAddPlugin.cmake | 6 +++++- src/libcalamaresui/modulesystem/Module.cpp | 6 ++++++ src/libcalamaresui/modulesystem/Module.h | 6 +++--- src/modules/README.md | 24 ++++++++++++++++++++-- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CMakeModules/CalamaresAddPlugin.cmake b/CMakeModules/CalamaresAddPlugin.cmake index e02102829..ade323689 100644 --- a/CMakeModules/CalamaresAddPlugin.cmake +++ b/CMakeModules/CalamaresAddPlugin.cmake @@ -38,6 +38,7 @@ # RESOURCES resource-file # [NO_INSTALL] # [SHARED_LIB] +# [EMERGENCY] # ) include( CMakeParseArguments ) @@ -47,7 +48,7 @@ include( CMakeColors ) function( calamares_add_plugin ) # parse arguments ( name needs to be saved before passing ARGN into the macro ) set( NAME ${ARGV0} ) - set( options NO_INSTALL SHARED_LIB ) + set( options NO_INSTALL SHARED_LIB EMERGENCY ) set( oneValueArgs NAME TYPE EXPORT_MACRO RESOURCES ) set( multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS ) cmake_parse_arguments( PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) @@ -132,6 +133,9 @@ function( calamares_add_plugin ) set( _type ${PLUGIN_TYPE} ) file( WRITE ${_file} "# AUTO-GENERATED metadata file\n# Syntax is YAML 1.2\n---\n" ) file( APPEND ${_file} "type: \"${_type}\"\nname: \"${PLUGIN_NAME}\"\ninterface: \"qtplugin\"\nload: \"lib${target}.so\"\n" ) + if ( PLUGIN_EMERGENCY ) + file( APPEND ${_file} "emergency: true\n" ) + endif() endif() install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_DESC_FILE} diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 2d0de8e55..d334fda17 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -290,6 +290,12 @@ void Module::initFrom( const QVariantMap& moduleDescriptor ) { m_name = moduleDescriptor.value( "name" ).toString(); + + auto em = QStringLiteral( "emergency" ); + if ( moduleDescriptor.contains( em ) ) + { + m_emergency = moduleDescriptor[ em ].toBool(); + } } } //ns diff --git a/src/libcalamaresui/modulesystem/Module.h b/src/libcalamaresui/modulesystem/Module.h index 9b481b157..219902b17 100644 --- a/src/libcalamaresui/modulesystem/Module.h +++ b/src/libcalamaresui/modulesystem/Module.h @@ -182,9 +182,11 @@ public: protected: explicit Module(); virtual void initFrom( const QVariantMap& moduleDescriptor ); - bool m_loaded; QVariantMap m_configurationMap; + bool m_loaded = false; + bool m_emergency = false; + private: void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception @@ -193,8 +195,6 @@ private: QString m_directory; QString m_instanceId; - bool m_emergency; - friend void ::operator>>( const QVariantMap& moduleDescriptor, Calamares::Module* m ); }; diff --git a/src/modules/README.md b/src/modules/README.md index a2ec06144..4b1d8ef2f 100644 --- a/src/modules/README.md +++ b/src/modules/README.md @@ -43,15 +43,21 @@ module's name, type, interface and possibly other properties. The name of the module as defined in `module.desc` must be the same as the name of the module's directory. -Module descriptors must have the following keys: +Module descriptors **must** have the following keys: - *name* (an identifier; must be the same as the directory name) - *type* ("job" or "view") - *interface* (see below for the different interfaces; generally we refer to the kinds of modules by their interface) +Module descriptors **may** have the following keys: +- *required* **unimplemented** (a list of modules which are required for this module + to operate properly) +- *emergency* (a boolean value, set to true to mark the module + as an emergency module) + ## Module-specific configuration -A Calamares module *may* read a module configuration file, +A Calamares module **may** read a module configuration file, named `.conf`. If such a file is present in the module's directory, it is shipped as a *default* configuration file. The module configuration file, if it exists, is a YAML 1.2 document @@ -125,3 +131,17 @@ while the module type must be "job" or "jobmodule". The key *command* should have a string as value, which is passed to the shell -- remember to quote it properly. +## Emergency Modules + +Only C++ modules and job modules may be emergency modules. If, during an +*exec* step in the sequence, a module fails, installation as a whole fails +and the install is aborted. If there are emergency modules in the **same** +exec block, those will be executed before the installation is aborted. +Non-emergency modules are not executed. + +If an emergency-module fails while processing emergency-modules for +another failed module, that failure is ignored and emergency-module +processing continues. + +Use the EMERGENCY keyword in the CMake description of a C++ module +to generate a suitable `module.desc`.