[libcalamares] Complete the generic module descriptor

- loads emergency, noconfig, requiredModules keys
- warns (and marks descriptor invalid) if there are unused / unknown
  keys left over in the descriptor data.
This commit is contained in:
Adriaan de Groot 2020-08-12 08:42:52 +02:00
parent e406ae1967
commit c8b96c278b
2 changed files with 41 additions and 5 deletions

View File

@ -8,6 +8,7 @@
#include "Descriptor.h" #include "Descriptor.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Variant.h"
namespace Calamares namespace Calamares
{ {
@ -57,9 +58,21 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc )
{ {
bool typeOk = false; bool typeOk = false;
Type t = typeNames().find( moduleDesc.value( "type" ).toString(), typeOk ); QString typeValue = moduleDesc.value( "type" ).toString();
Type t = typeNames().find( typeValue, typeOk );
if ( !typeOk )
{
cWarning() << "Module descriptor contains invalid *type*" << typeValue;
}
bool interfaceOk = false; bool interfaceOk = false;
Interface i = interfaceNames().find( moduleDesc.value( "interface" ).toString(), interfaceOk ); QString interfaceValue = moduleDesc.value( "interface" ).toString();
Interface i = interfaceNames().find( interfaceValue, interfaceOk );
if ( !interfaceOk )
{
cWarning() << "Module descriptor contains invalid *interface*" << interfaceValue;
}
d.m_name = moduleDesc.value( "name" ).toString(); d.m_name = moduleDesc.value( "name" ).toString();
if ( typeOk && interfaceOk && !d.m_name.isEmpty() ) if ( typeOk && interfaceOk && !d.m_name.isEmpty() )
{ {
@ -73,6 +86,26 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc )
return d; return d;
} }
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" );
QStringList consumedKeys { "type", "interface", "name", "emergency", "noconfig", "requiredModules" };
QStringList superfluousKeys;
for ( auto kv = moduleDesc.keyBegin(); kv != moduleDesc.keyEnd(); ++kv )
{
if ( !consumedKeys.contains( *kv ) )
{
superfluousKeys << *kv;
}
}
if ( !superfluousKeys.isEmpty() )
{
cWarning() << "Module descriptor contains extra keys:" << Logger::DebugList( superfluousKeys );
d.m_isValid = false;
}
return d; return d;
} }

View File

@ -78,14 +78,14 @@ public:
Type type() const { return m_type; } Type type() const { return m_type; }
Interface interface() const { return m_interface; } Interface interface() const { return m_interface; }
bool isEmergency() const { return false; } bool isEmergency() const { return m_isEmergeny; }
bool hasConfig() const { return true; } bool hasConfig() const { return m_hasConfig; }
/// @brief The directory where the module.desc lives /// @brief The directory where the module.desc lives
QString directory() const { return m_directory; } QString directory() const { return m_directory; }
void setDirectory( const QString& d ) { m_directory = d; } void setDirectory( const QString& d ) { m_directory = d; }
QStringList requiredModules() const { return QStringList {}; } const QStringList& requiredModules() const { return m_requiredModules; }
/** @section C++ Modules /** @section C++ Modules
* *
@ -121,9 +121,12 @@ public:
private: private:
QString m_name; QString m_name;
QString m_directory; QString m_directory;
QStringList m_requiredModules;
Type m_type; Type m_type;
Interface m_interface; Interface m_interface;
bool m_isValid = false; bool m_isValid = false;
bool m_isEmergeny = false;
bool m_hasConfig = true;
}; };
} // namespace ModuleSystem } // namespace ModuleSystem