From c19866f887b01a74f48157d750b3f5b086579ec6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Aug 2020 15:59:42 +0200 Subject: [PATCH] [libcalamares] Add a module-weight to the module descriptor --- CMakeModules/CalamaresAddPlugin.cmake | 9 ++++++- src/libcalamares/modulesystem/Descriptor.cpp | 27 +++++++++++++++----- src/libcalamares/modulesystem/Descriptor.h | 4 +++ src/modules/README.md | 12 +++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/CMakeModules/CalamaresAddPlugin.cmake b/CMakeModules/CalamaresAddPlugin.cmake index ee3c63acb..a90e6df63 100644 --- a/CMakeModules/CalamaresAddPlugin.cmake +++ b/CMakeModules/CalamaresAddPlugin.cmake @@ -41,6 +41,7 @@ # [NO_CONFIG] # [SHARED_LIB] # [EMERGENCY] +# [WEIGHT w] # ) # # Function parameters: @@ -63,6 +64,9 @@ # - EMERGENCY # If this is set, the module is marked as an *emergency* module in the # descriptor. See *Emergency Modules* in the module documentation. +# - WEIGHT +# If this is set, writes an explicit weight into the module.desc; +# module weights are used in progress reporting. # include( CMakeParseArguments ) @@ -73,7 +77,7 @@ function( calamares_add_plugin ) # parse arguments ( name needs to be saved before passing ARGN into the macro ) set( NAME ${ARGV0} ) set( options NO_CONFIG NO_INSTALL SHARED_LIB EMERGENCY ) - set( oneValueArgs NAME TYPE EXPORT_MACRO RESOURCES ) + set( oneValueArgs NAME TYPE EXPORT_MACRO RESOURCES WEIGHT ) set( multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS REQUIRES ) cmake_parse_arguments( PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) set( PLUGIN_NAME ${NAME} ) @@ -181,6 +185,9 @@ function( calamares_add_plugin ) if ( PLUGIN_NO_CONFIG ) file( APPEND ${_file} "noconfig: true\n" ) endif() + if ( PLUGIN_WEIGHT ) + file( APPEND ${_file} "weight: ${PLUGIN_WEIGHT}\n" ) + endif() endif() if ( NOT PLUGIN_NO_INSTALL ) diff --git a/src/libcalamares/modulesystem/Descriptor.cpp b/src/libcalamares/modulesystem/Descriptor.cpp index 1ac4dc6c0..9b3e48b6e 100644 --- a/src/libcalamares/modulesystem/Descriptor.cpp +++ b/src/libcalamares/modulesystem/Descriptor.cpp @@ -87,8 +87,9 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc ) d.m_isEmergeny = CalamaresUtils::getBool( moduleDesc, "emergency", false ); d.m_hasConfig = !CalamaresUtils::getBool( moduleDesc, "noconfig", false ); // Inverted logic during load d.m_requiredModules = CalamaresUtils::getStringList( moduleDesc, "requiredModules" ); + d.m_weight = int( CalamaresUtils::getInteger( moduleDesc, "weight", -1 ) ); - QStringList consumedKeys { "type", "interface", "name", "emergency", "noconfig", "requiredModules" }; + QStringList consumedKeys { "type", "interface", "name", "emergency", "noconfig", "requiredModules", "weight" }; switch ( d.interface() ) { @@ -99,23 +100,37 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc ) case Interface::Python: case Interface::PythonQt: d.m_script = CalamaresUtils::getString( moduleDesc, "script" ); + if ( d.m_script.isEmpty() ) + { + cWarning() << "Module descriptor contains no *script*" << d.name(); + d.m_isValid = false; + } consumedKeys << "script"; break; case Interface::Process: d.m_script = CalamaresUtils::getString( moduleDesc, "command" ); - d.m_processTimeout = CalamaresUtils::getInteger( moduleDesc, "timeout", 30 ); + d.m_processTimeout = int( CalamaresUtils::getInteger( moduleDesc, "timeout", 30 ) ); d.m_processChroot = CalamaresUtils::getBool( moduleDesc, "chroot", false ); - consumedKeys << "command" - << "timeout" - << "chroot"; - if ( d.m_processTimeout < 0 ) { d.m_processTimeout = 0; } + if ( d.m_script.isEmpty() ) + { + cWarning() << "Module descriptor contains no *script*" << d.name(); + d.m_isValid = false; + } + consumedKeys << "command" + << "timeout" + << "chroot"; break; } + if ( !d.m_isValid ) + { + return d; + } + QStringList superfluousKeys; for ( auto kv = moduleDesc.keyBegin(); kv != moduleDesc.keyEnd(); ++kv ) { diff --git a/src/libcalamares/modulesystem/Descriptor.h b/src/libcalamares/modulesystem/Descriptor.h index 8166f9869..a94c0574d 100644 --- a/src/libcalamares/modulesystem/Descriptor.h +++ b/src/libcalamares/modulesystem/Descriptor.h @@ -80,6 +80,9 @@ public: bool isEmergency() const { return m_isEmergeny; } bool hasConfig() const { return m_hasConfig; } + int weight() const { return m_weight < 1 ? 1 : m_weight; } + bool explicitWeight() const { return m_weight > 0; } + /// @brief The directory where the module.desc lives QString directory() const { return m_directory; } @@ -125,6 +128,7 @@ private: QString m_name; QString m_directory; QStringList m_requiredModules; + int m_weight = -1; Type m_type; Interface m_interface; bool m_isValid = false; diff --git a/src/modules/README.md b/src/modules/README.md index ee6e378d2..1220c7398 100644 --- a/src/modules/README.md +++ b/src/modules/README.md @@ -46,9 +46,19 @@ Module descriptors **must** have the following keys: - *interface* (see below for the different interfaces; generally we refer to the kinds of modules by their interface) +Module descriptors for C++ modules **may** have the following key: +- *load* (the name of the shared library to load; if empty, uses a + standard library name derived from the module name) + Module descriptors for Python modules **must** have the following key: - *script* (the name of the Python script to load, nearly always `main.py`) +Module descriptors for process modules **must** have the following key: +- *command* (the command to run) +Module descriptors for process modules **may** have the following keys: +- *timeout* (how long, in seconds, to wait for the command to run) +- *chroos* (if true, run the command in the target system rather than the host) + Module descriptors **may** have the following keys: - *emergency* (a boolean value, set to true to mark the module as an emergency module) @@ -56,6 +66,8 @@ Module descriptors **may** have the following keys: has no configuration file; defaults to false) - *requiredModules* (a list of modules which are required for this module to operate properly) +- *weight* (a relative module weight, used to scale progress reporting) + ### Required Modules