From 1678a03cb3fc4f87a3f4fd8e0b04b7483fe2afd9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 20 Mar 2020 21:25:42 +0100 Subject: [PATCH 1/5] [libcalamares] Tighten up types - If we're converting a YAML map to a QVariant (Map), may as well express that in the types. This makes the return from, say, `yamlMapToVariant()` cheaper, but incurs conversion in `yamlToVariant()` .. previously the place for costs was swapped around. - For those cases that want-and-expect a Map, or List, this makes the calls slightly cheaper. For the generic case, the costs move around internally. --- src/libcalamares/utils/Yaml.cpp | 4 ++-- src/libcalamares/utils/Yaml.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libcalamares/utils/Yaml.cpp b/src/libcalamares/utils/Yaml.cpp index 164c17a21..c986588be 100644 --- a/src/libcalamares/utils/Yaml.cpp +++ b/src/libcalamares/utils/Yaml.cpp @@ -89,7 +89,7 @@ yamlScalarToVariant( const YAML::Node& scalarNode ) } -QVariant +QVariantList yamlSequenceToVariant( const YAML::Node& sequenceNode ) { QVariantList vl; @@ -101,7 +101,7 @@ yamlSequenceToVariant( const YAML::Node& sequenceNode ) } -QVariant +QVariantMap yamlMapToVariant( const YAML::Node& mapNode ) { QVariantMap vm; diff --git a/src/libcalamares/utils/Yaml.h b/src/libcalamares/utils/Yaml.h index fd6537be6..a976136e1 100644 --- a/src/libcalamares/utils/Yaml.h +++ b/src/libcalamares/utils/Yaml.h @@ -22,6 +22,8 @@ #include #include +#include +#include class QByteArray; class QFileInfo; @@ -60,8 +62,8 @@ QVariantMap loadYaml( const QFileInfo&, bool* ok = nullptr ); QVariant yamlToVariant( const YAML::Node& node ); QVariant yamlScalarToVariant( const YAML::Node& scalarNode ); -QVariant yamlSequenceToVariant( const YAML::Node& sequenceNode ); -QVariant yamlMapToVariant( const YAML::Node& mapNode ); +QVariantList yamlSequenceToVariant( const YAML::Node& sequenceNode ); +QVariantMap yamlMapToVariant( const YAML::Node& mapNode ); /// @brief Returns all the elements of @p listNode in a StringList QStringList yamlToStringList( const YAML::Node& listNode ); From 3b0c0435bc8f2075e4b0e61ce968de23f76e3f99 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 20 Mar 2020 21:55:03 +0100 Subject: [PATCH 2/5] [libcalamaresui] Chase API change in Yaml - We can drop a bunch of calls to toMap() now. --- src/libcalamaresui/Branding.cpp | 2 +- src/libcalamaresui/modulesystem/Module.cpp | 2 +- src/modules/contextualprocess/Tests.cpp | 6 +++--- src/modules/shellprocess/Tests.cpp | 18 ++++++++---------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 34ba23436..5c41f5ea2 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -123,7 +123,7 @@ loadStrings( QMap< QString, QString >& map, throw YAML::Exception( YAML::Mark(), std::string( "Branding configuration is not a map: " ) + key ); } - const auto& config = CalamaresUtils::yamlMapToVariant( doc[ key ] ).toMap(); + const auto& config = CalamaresUtils::yamlMapToVariant( doc[ key ] ); map.clear(); for ( auto it = config.constBegin(); it != config.constEnd(); ++it ) diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 8fe3f2ac6..35b1508f1 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -237,7 +237,7 @@ void Module::loadConfigurationFile( const QString& configFileName ) //throws YA } cDebug() << "Loaded module configuration" << path; - m_configurationMap = CalamaresUtils::yamlMapToVariant( doc ).toMap(); + m_configurationMap = CalamaresUtils::yamlMapToVariant( doc ); m_emergency = m_maybe_emergency && m_configurationMap.contains( EMERGENCY ) && m_configurationMap[ EMERGENCY ].toBool(); return; diff --git a/src/modules/contextualprocess/Tests.cpp b/src/modules/contextualprocess/Tests.cpp index a0071328a..50ce9f400 100644 --- a/src/modules/contextualprocess/Tests.cpp +++ b/src/modules/contextualprocess/Tests.cpp @@ -79,14 +79,15 @@ ContextualProcessTests::testProcessListSampleConfig() } ContextualProcessJob job; - job.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc ).toMap() ); + job.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc ) ); QCOMPARE( job.count(), 2 ); // Only "firmwareType" and "branding.shortVersion" QCOMPARE( job.count( "firmwareType" ), 4 ); QCOMPARE( job.count( "branding.shortVersion" ), 2 ); // in the example config } -void ContextualProcessTests::testFetch() +void +ContextualProcessTests::testFetch() { Logger::setupLogLevel( Logger::LOGVERBOSE ); @@ -187,5 +188,4 @@ void ContextualProcessTests::testFetch() QCOMPARE( s, QString() ); QVERIFY( s.isEmpty() ); } - } diff --git a/src/modules/shellprocess/Tests.cpp b/src/modules/shellprocess/Tests.cpp index e991973db..caf9800c9 100644 --- a/src/modules/shellprocess/Tests.cpp +++ b/src/modules/shellprocess/Tests.cpp @@ -62,7 +62,7 @@ ShellProcessTests::testProcessListSampleConfig() } } - CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) ); + CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) ); QVERIFY( !cl.isEmpty() ); QCOMPARE( cl.count(), 3 ); @@ -79,7 +79,7 @@ script: - "ls /nonexistent" - "/bin/false" )" ); - CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) ); + CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) ); QVERIFY( !cl.isEmpty() ); QCOMPARE( cl.count(), 3 ); @@ -90,7 +90,7 @@ script: - false - "ls /nonexistent" )" ); - CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) ); + CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) ); QVERIFY( !cl1.isEmpty() ); QCOMPARE( cl1.count(), 2 ); // One element ignored } @@ -101,7 +101,7 @@ ShellProcessTests::testProcessListFromString() YAML::Node doc = YAML::Load( R"(--- script: "ls /tmp" )" ); - CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) ); + CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) ); QVERIFY( !cl.isEmpty() ); QCOMPARE( cl.count(), 1 ); @@ -112,7 +112,7 @@ script: "ls /tmp" doc = YAML::Load( R"(--- script: false )" ); - CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) ); + CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) ); QVERIFY( cl1.isEmpty() ); QCOMPARE( cl1.count(), 0 ); } @@ -125,7 +125,7 @@ script: command: "ls /tmp" timeout: 20 )" ); - CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) ); + CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) ); QVERIFY( !cl.isEmpty() ); QCOMPARE( cl.count(), 1 ); @@ -142,7 +142,7 @@ script: timeout: 12 - "-/bin/false" )" ); - CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) ); + CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) ); QVERIFY( !cl.isEmpty() ); QCOMPARE( cl.count(), 2 ); QCOMPARE( cl.at( 0 ).timeout(), 12s ); @@ -157,12 +157,11 @@ ShellProcessTests::testRootSubstitution() script: - "ls /tmp" )" ); - QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ); + QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).value( "script" ); QVariant rootScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(--- script: - "ls @@ROOT@@" )" ) ) - .toMap() .value( "script" ); QVariant userScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(--- script: @@ -170,7 +169,6 @@ script: - "chown @@USER@@ @@ROOT@@/calatest*" - rm -rf @@ROOT@@/calatest* )" ) ) - .toMap() .value( "script" ); if ( !Calamares::JobQueue::instance() ) From cba4d2e93b488c8efe301809718760f1be92b449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Wed, 18 Mar 2020 17:11:05 -0400 Subject: [PATCH 3/5] [partition] Name partition using filesystem label --- src/modules/partition/core/PartitionLayout.cpp | 1 + src/modules/partition/partition.conf | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index 23332f3f5..7d2c70159 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -237,6 +237,7 @@ PartitionLayout::execute( Device* dev, PartitionInfo::setMountPoint( currentPartition, part.partMountPoint ); if ( !part.partLabel.isEmpty() ) { + currentPartition->setLabel( part.partLabel ); currentPartition->fileSystem().setLabel( part.partLabel ); } // Some buggy (legacy) BIOSes test if the bootflag of at least one partition is set. diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index 6fbb44cb4..08c7c75d1 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -112,7 +112,9 @@ defaultFileSystemType: "ext4" # size: 100% # # There can be any number of partitions, each entry having the following attributes: -# - name: partition label +# - name: filesystem label +# and +# partition name (gpt only; since KPMCore 4.2.0) # - filesystem: filesystem type # - mountPoint: partition mount point # - size: partition size in bytes (append 'K', 'M' or 'G' for KiB, MiB or GiB) From 15cce29a5159dd81bb3dc1d923af5ab5fb0ea3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Mon, 16 Mar 2020 17:25:55 -0400 Subject: [PATCH 4/5] [partition] Add support for filesystem-specific features --- src/libcalamares/CMakeLists.txt | 7 ++++++- src/modules/fsresizer/CMakeLists.txt | 4 +++- src/modules/partition/CMakeLists.txt | 3 +++ src/modules/partition/core/PartitionCoreModule.cpp | 2 ++ src/modules/partition/core/PartitionLayout.cpp | 11 +++++++++++ src/modules/partition/core/PartitionLayout.h | 3 +++ src/modules/partition/partition.conf | 8 ++++++++ 7 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 156ab2cc6..608768a97 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -128,7 +128,12 @@ if ( KPMcore_FOUND ) find_package( Qt5 REQUIRED DBus ) # Needed for KPMCore find_package( KF5 REQUIRED I18n WidgetsAddons ) # Needed for KPMCore - if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0" ) + if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.2" ) + add_definitions( + -DWITH_KPMCORE42API + -DWITH_KPMCORE4API + ) # kpmcore 4.2 with new API + elseif( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0" ) add_definitions( -DWITH_KPMCORE4API ) # kpmcore 4 with new API elseif( KPMcore_VERSION VERSION_GREATER "3.3.70" ) message( FATAL_ERROR "KPMCore beta versions ${KPMcore_VERSION} not supported" ) diff --git a/src/modules/fsresizer/CMakeLists.txt b/src/modules/fsresizer/CMakeLists.txt index 1f4260518..6808f1bea 100644 --- a/src/modules/fsresizer/CMakeLists.txt +++ b/src/modules/fsresizer/CMakeLists.txt @@ -8,7 +8,9 @@ set( _partition_defs "" ) if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND ) include_directories( ${KPMCORE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/modules/partition ) - if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0" ) + if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.2" ) + list( APPEND _partition_defs WITH_KPMCORE42API WITH_KPMCORE4API ) # kpmcore 4.2 with new API + elseif( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0" ) list( APPEND _partition_defs WITH_KPMCORE4API ) # kpmcore 4 with new API elseif( KPMcore_VERSION VERSION_GREATER "3.3.70" ) message( FATAL_ERROR "KPMCore beta versions ${KPMcore_VERSION} are not supported" ) diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 2ac926346..2f9474a29 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -33,6 +33,9 @@ if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND if ( KPMcore_VERSION VERSION_GREATER "3.90") list( APPEND _partition_defs WITH_KPMCORE4API) # kpmcore 4 with new API endif() + if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.2" ) + list( APPEND _partition_defs WITH_KPMCORE42API) # kpmcore 4.2 with new API + endif() include_directories( ${KPMCORE_INCLUDE_DIR} ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 5d4d8f3cd..e05f43d3d 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -834,6 +834,7 @@ PartitionCoreModule::initLayout() void PartitionCoreModule::initLayout( const QVariantList& config ) { + bool ok; QString sizeString; QString minSizeString; QString maxSizeString; @@ -884,6 +885,7 @@ PartitionCoreModule::initLayout( const QVariantList& config ) if ( !m_partLayout->addEntry( CalamaresUtils::getString( pentry, "name" ), CalamaresUtils::getString( pentry, "mountPoint" ), CalamaresUtils::getString( pentry, "filesystem" ), + CalamaresUtils::getSubMap( pentry, "features", ok ), sizeString, minSizeString, maxSizeString ) ) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index 23332f3f5..4f1086d19 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -120,6 +120,7 @@ bool PartitionLayout::addEntry( const QString& label, const QString& mountPoint, const QString& fs, + const QVariantMap& features, const QString& size, const QString& min, const QString& max ) @@ -144,6 +145,7 @@ PartitionLayout::addEntry( const QString& label, { entry.partFileSystem = m_defaultFsType; } + entry.partFeatures = features; m_partLayout.append( entry ); @@ -239,6 +241,15 @@ PartitionLayout::execute( Device* dev, { currentPartition->fileSystem().setLabel( part.partLabel ); } + if ( !part.partFeatures.isEmpty() ) + { +#if defined( WITH_KPMCORE42API ) + for ( const auto& k : part.partFeatures.keys() ) + currentPartition->fileSystem().addFeature( k, part.partFeatures.value(k) ); +#else + cWarning() << "Ignoring features; requires KPMcore >= 4.2.0."; +#endif + } // Some buggy (legacy) BIOSes test if the bootflag of at least one partition is set. // Otherwise they ignore the device in boot-order, so add it here. partList.append( currentPartition ); diff --git a/src/modules/partition/core/PartitionLayout.h b/src/modules/partition/core/PartitionLayout.h index 50bb1ba43..3ec7f48ee 100644 --- a/src/modules/partition/core/PartitionLayout.h +++ b/src/modules/partition/core/PartitionLayout.h @@ -31,6 +31,7 @@ // Qt #include #include +#include class Partition; @@ -42,6 +43,7 @@ public: QString partLabel; QString partMountPoint; FileSystem::Type partFileSystem = FileSystem::Unknown; + QVariantMap partFeatures; CalamaresUtils::Partition::PartitionSize partSize; CalamaresUtils::Partition::PartitionSize partMinSize; CalamaresUtils::Partition::PartitionSize partMaxSize; @@ -75,6 +77,7 @@ public: bool addEntry( const QString& label, const QString& mountPoint, const QString& fs, + const QVariantMap& features, const QString& size, const QString& min = QString(), const QString& max = QString() ); diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index 6fbb44cb4..5b7d5ee60 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -106,9 +106,15 @@ defaultFileSystemType: "ext4" # mountPoint: "/home" # size: 3G # minSize: 1.5G +# features: +# 64bit: false +# casefold: true # - name: "data" # filesystem: "fat32" # mountPoint: "/data" +# features: +# sector-size: 4096 +# sectors-per-cluster: 128 # size: 100% # # There can be any number of partitions, each entry having the following attributes: @@ -120,6 +126,8 @@ defaultFileSystemType: "ext4" # % of the available drive space if a '%' is appended to the value # - minSize: minimum partition size (optional parameter) # - maxSize: maximum partition size (optional parameter) +# - features: filesystem features (optional parameter; requires KPMCore >= 4.2.0) +# name: boolean or integer or string # Checking for available storage # From 54356a22ba64b1629041d0944f43f11c012b3409 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 22 Mar 2020 23:04:12 +0100 Subject: [PATCH 5/5] [fsresizer] Chase API change in tests - Missed this earlier because the module is not enabled in FreeBSD. --- src/modules/fsresizer/Tests.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/fsresizer/Tests.cpp b/src/modules/fsresizer/Tests.cpp index cee390b6b..42d587631 100644 --- a/src/modules/fsresizer/Tests.cpp +++ b/src/modules/fsresizer/Tests.cpp @@ -64,7 +64,7 @@ void FSResizerTests::testConfigurationRobust() size: 100% atleast: 600MiB )" ); - j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); + j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) ); QVERIFY( j.name().isEmpty() ); QCOMPARE( j.size().unit(), SizeUnit::None ); QCOMPARE( j.minimumSize().unit(), SizeUnit::None ); @@ -82,7 +82,7 @@ fs: / size: 100% atleast: 600MiB )" ); - j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); + j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) ); QVERIFY( !j.name().isEmpty() ); QCOMPARE( j.name(), QString("/") ); QCOMPARE( j.size().unit(), SizeUnit::Percent ); @@ -97,7 +97,7 @@ dev: /dev/m00 size: 72 MiB atleast: 127 % )" ); - j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); + j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) ); QVERIFY( !j.name().isEmpty() ); QCOMPARE( j.name(), QString("/") ); QCOMPARE( j.size().unit(), SizeUnit::MiB ); @@ -111,7 +111,7 @@ dev: /dev/m00 size: 72 MiB atleast: 127 % )" ); - j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); + j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) ); QVERIFY( !j.name().isEmpty() ); QCOMPARE( j.name(), QString("/dev/m00") ); QCOMPARE( j.size().unit(), SizeUnit::MiB ); @@ -126,7 +126,7 @@ fs: / size: 71MiB # atleast: 127% )" ); - j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); + j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) ); QVERIFY( !j.name().isEmpty() ); QCOMPARE( j.name(), QString("/") ); QCOMPARE( j.size().unit(), SizeUnit::MiB );