From e71fa5963b34feb033bdf70fe63949e7287905ec Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 09:47:30 -0400 Subject: [PATCH 01/16] CMake: document top-level definitions and options --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aeb8a584..226c97a31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,9 @@ # # SKIP_MODULES : a space or semicolon-separated list of directory names # under src/modules that should not be built. +# USE_ : fills in SKIP_MODULES for modules called - +# BUILD_ : choose additional things to build +# DEBUG_ : special developer flags for debugging # # Example usage: # @@ -62,7 +65,8 @@ option( WITH_KF5Crash "Enable crash reporting with KCrash." ON ) # all the implementations are enabled (this just means they are # **available** to `settings.conf`, not that they are used). # -# Currently, no USE_ variables exist. +# Currently, only USE_services is in use (to pick only one of the two +# modules, systemd or openrc). set( USE_services "" CACHE STRING "Select the services module to use" ) ### Calamares application info From d7594860b09562a1909dbcf8a396afca65bb0d0b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 11:07:07 -0400 Subject: [PATCH 02/16] CMake: fix calamares_add_library - Remove the commented-out cruft and the whinging - Fix use of COMPILE_DEFINITIONS with a list passed in - Remove unused arguments (TYPE, TARGET) - Document calamares_add_library - Document how to use COMPILE_DEFINITIONS (in calamares_add_plugin) --- CMakeModules/CalamaresAddLibrary.cmake | 50 ++++++++++++++------------ CMakeModules/CalamaresAddPlugin.cmake | 4 +++ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/CMakeModules/CalamaresAddLibrary.cmake b/CMakeModules/CalamaresAddLibrary.cmake index f6e96d12a..d5d734989 100644 --- a/CMakeModules/CalamaresAddLibrary.cmake +++ b/CMakeModules/CalamaresAddLibrary.cmake @@ -19,27 +19,41 @@ ### # # Support functions for building plugins. - +# +# Usage: +# +# calamares_add_library( +# library-name +# EXPORT_MACRO macro-name +# TARGET_TYPE +# EXPORT export-name +# VERSION version +# SOVERSION version +# INSTALL_BINDIR dir +# RESOURCES resource-file +# SOURCES source-file... +# UI ui-file... +# LINK_LIBRARIES lib... +# LINK_PRIVATE_LIBRARIES lib... +# COMPILE_DEFINITIONS def... +# [NO_INSTALL] +# [NO_VERSION] +# ) +# +# The COMPILE_DEFINITIONS are set on the resulting module with a suitable +# flag (i.e. `-D`) so only state the name (optionally, also the value) +# without a `-D` prefixed to it. Pass in a CMake list as needed. include( CMakeParseArguments ) function(calamares_add_library) # parse arguments (name needs to be saved before passing ARGN into the macro) set(NAME ${ARGV0}) set(options NO_INSTALL NO_VERSION) - set(oneValueArgs NAME TYPE EXPORT_MACRO TARGET TARGET_TYPE EXPORT VERSION SOVERSION INSTALL_BINDIR RESOURCES) - set(multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS QT5_MODULES) + set(oneValueArgs NAME EXPORT_MACRO TARGET_TYPE EXPORT VERSION SOVERSION INSTALL_BINDIR RESOURCES) + set(multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS) cmake_parse_arguments(LIBRARY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(LIBRARY_NAME ${NAME}) - -# message("*** Arguments for ${LIBRARY_NAME}") -# message("Sources: ${LIBRARY_SOURCES}") -# message("Link libraries: ${LIBRARY_LINK_LIBRARIES}") -# message("UI: ${LIBRARY_UI}") -# message("TARGET_TYPE: ${LIBRARY_TARGET_TYPE}") -# message("EXPORT_MACRO: ${LIBRARY_EXPORT_MACRO}") -# message("NO_INSTALL: ${LIBRARY_NO_INSTALL}") - set(target ${LIBRARY_NAME}) # qt stuff @@ -76,13 +90,8 @@ function(calamares_add_library) endif() if(LIBRARY_COMPILE_DEFINITIONS) - # Dear CMake, i hate you! Sincerely, domme - # At least in CMake 2.8.8, you CANNOT set more than one COMPILE_DEFINITIONS value - # only takes the first one if called multiple times or bails out with wrong number of arguments - # when passing in a list, thus i redefine the export macro here in hope it won't mess up other targets - add_definitions( "-D${LIBRARY_EXPORT_MACRO}" ) - - set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_COMPILE_DEFINITIONS}) + set( _lib_definitions "${LIBRARY_EXPORT_MACRO}" ${LIBRARY_COMPILE_DEFINITIONS} ) + set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS "${_lib_definitions}") endif() # add link targets @@ -119,9 +128,6 @@ function(calamares_add_library) set(LIBRARY_INSTALL_LIBDIR "${LIBRARY_INSTALL_BINDIR}") endif() - #message("INSTALL_BINDIR: ${LIBRARY_INSTALL_BINDIR}") - #message("INSTALL_LIBDIR: ${LIBRARY_INSTALL_LIBDIR}") - # make installation optional, maybe useful for dummy plugins one day if(NOT LIBRARY_NO_INSTALL) include(GNUInstallDirs) diff --git a/CMakeModules/CalamaresAddPlugin.cmake b/CMakeModules/CalamaresAddPlugin.cmake index 886501a56..1d749d51c 100644 --- a/CMakeModules/CalamaresAddPlugin.cmake +++ b/CMakeModules/CalamaresAddPlugin.cmake @@ -40,6 +40,10 @@ # [SHARED_LIB] # [EMERGENCY] # ) +# +# The COMPILE_DEFINITIONS are set on the resulting module with a suitable +# flag (i.e. `-D`) so only state the name (optionally, also the value) +# without a `-D` prefixed to it. include( CMakeParseArguments ) include( CalamaresAddLibrary ) From 4b486cfe82a9d69801604ae995ef9895eca0f389 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 13:25:35 -0400 Subject: [PATCH 03/16] [libcalamares] Add some debugging Jobs - FailJob always fails, and GoodJob always succeeds, both without doing anything. These aren't particularly useful, except for debugging. --- src/libcalamares/CMakeLists.txt | 1 + src/libcalamares/JobExample.cpp | 42 +++++++++++++++++++ src/libcalamares/JobExample.h | 73 +++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/libcalamares/JobExample.cpp create mode 100644 src/libcalamares/JobExample.h diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 4bf78176e..aeea34470 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -16,6 +16,7 @@ set( libSources CppJob.cpp GlobalStorage.cpp Job.cpp + JobExample.cpp JobQueue.cpp ProcessJob.cpp Settings.cpp diff --git a/src/libcalamares/JobExample.cpp b/src/libcalamares/JobExample.cpp new file mode 100644 index 000000000..83259ae6d --- /dev/null +++ b/src/libcalamares/JobExample.cpp @@ -0,0 +1,42 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "JobExample.h" + +namespace Calamares +{ + +QString +NamedJob::prettyName() const +{ + return tr( "Example job (%1)" ).arg( m_name ); +} + +JobResult +GoodJob::exec() +{ + return JobResult::ok(); +} + +JobResult +FailJob::exec() +{ + return JobResult::error( tr( "Job failed (%1)" ).arg( m_name ), tr( "Programmed job failure was explicitly requested." ) ); +} + +} // namespace diff --git a/src/libcalamares/JobExample.h b/src/libcalamares/JobExample.h new file mode 100644 index 000000000..fd5eea109 --- /dev/null +++ b/src/libcalamares/JobExample.h @@ -0,0 +1,73 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CALAMARES_JOB_EXAMPLE_H +#define CALAMARES_JOB_EXAMPLE_H + +#include "Job.h" + +namespace Calamares { + +/** @brief A Job with a name + * + * This includes a default implementation of prettyName(), + * but is only used as a base for FailJob and GoodJob, + * which are support / bogus classes. + */ +class DLLEXPORT NamedJob : public Job +{ +public: + explicit NamedJob( const QString& name, QObject* parent = nullptr ) + : Job( parent ) + , m_name( name ) + { + } + + virtual QString prettyName() const override; +protected: + const QString m_name; +} ; + +/// @brief Job does nothing, always succeeds +class DLLEXPORT GoodJob : public NamedJob +{ +public: + explicit GoodJob( const QString& name, QObject* parent = nullptr ) + : NamedJob( name, parent ) + { + } + + virtual JobResult exec() override; +} ; + + +/// @brief Job does nothing, always fails +class DLLEXPORT FailJob : public NamedJob +{ +public: + explicit FailJob( const QString& name, QObject* parent = nullptr ) + : NamedJob( name, parent ) + { + } + + virtual JobResult exec() override; +} ; + +} // namespace Calamares + +#endif // CALAMARES_JOB_EXAMPLE_H From 826453aa657b85c35b000f509164db39cf202af9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 16:11:20 -0400 Subject: [PATCH 04/16] [calamares] Note that qDebug() is sometimes ok --- src/calamares/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index b84d4f4db..e2b5da8bf 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -114,6 +114,7 @@ main( int argc, char* argv[] ) } else { + // Here we have not yet set-up the logger system, so qDebug() is ok auto instancelist = guard.instances(); qDebug() << "Calamares is already running, shutting down."; if ( instancelist.count() > 0 ) From 3db708dd0472152b2931b02cab2089248621e02e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 16:11:04 -0400 Subject: [PATCH 05/16] [keyboard] qDebug -> cDebug --- src/modules/keyboard/keyboardwidget/keyboardglobal.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/keyboard/keyboardwidget/keyboardglobal.cpp b/src/modules/keyboard/keyboardwidget/keyboardglobal.cpp index 55132826e..8b6cac4be 100644 --- a/src/modules/keyboard/keyboardwidget/keyboardglobal.cpp +++ b/src/modules/keyboard/keyboardwidget/keyboardglobal.cpp @@ -22,6 +22,8 @@ #include "keyboardglobal.h" +#include "utils/Logger.h" + //### //### Public methods //### @@ -52,7 +54,7 @@ QMap KeyboardGlobal::parseKeyboardModels(QString filepath) fh.open(QIODevice::ReadOnly); if (!fh.isOpen()) { - qDebug() << "X11 Keyboard model definitions not found!"; + cDebug() << "X11 Keyboard model definitions not found!"; return models; } @@ -100,7 +102,7 @@ QMap< QString, KeyboardGlobal::KeyboardInfo > KeyboardGlobal::parseKeyboardLayou fh.open(QIODevice::ReadOnly); if (!fh.isOpen()) { - qDebug() << "X11 Keyboard layout definitions not found!"; + cDebug() << "X11 Keyboard layout definitions not found!"; return layouts; } From 2caefce3cbee5681dc37c5ec0a46618c231b0b5b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 09:47:50 -0400 Subject: [PATCH 06/16] [locale] Add a CMake option for debugging --- src/modules/locale/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/locale/CMakeLists.txt b/src/modules/locale/CMakeLists.txt index b70c6d1ab..8faf8468c 100644 --- a/src/modules/locale/CMakeLists.txt +++ b/src/modules/locale/CMakeLists.txt @@ -1,8 +1,10 @@ # When debugging the timezone widget, add this debugging definition # to have a debugging-friendly timezone widget, debug logging, # and no intrusive timezone-setting while clicking around. -# -# add_definitions( -DDEBUG_TIMEZONES ) +option( DEBUG_TIMEZONES "Debug-friendly timezone widget." OFF ) +if( DEBUG_TIMEZONES ) + add_definitions( -DDEBUG_TIMEZONES ) +endif() include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) From 62f03d8aad037d5ceadf2b4679d21d06cc215359 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 10:21:57 -0400 Subject: [PATCH 07/16] [partition] Allow unsafe partitioning decisions - This is a compile-time choice, and off by default. This may be useful for developers that need to get through installation to a different partition on their root drive. - Add an option to avoid actually doing unsafe things. This is an extra safeguard; you need to turn on one and turn off the other option to really be unsafe. --- src/modules/partition/CMakeLists.txt | 16 ++++++++++++++++ src/modules/partition/core/DeviceList.cpp | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index b9b2109a3..56520845e 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -1,3 +1,18 @@ +# When debugging the partitioning widget, or experimenting, you may +# want to allow unsafe partitioning choices (e.g. doing things to the +# current disk). Set DEBUG_PARTITION_UNSAFE to allow that (it turns off +# some filtering of devices). +option( DEBUG_PARTITION_UNSAFE "Allow unsafe partitioning choices." OFF ) +option( DEBUG_PARTITION_LAME "Unsafe partitioning will error out on exec." ON ) + +set( _partition_defs ) +if( DEBUG_PARTITION_UNSAFE ) + if( DEBUG_PARTITION_LAME ) + list( APPEND _partition_defs DEBUG_PARTITION_LAME ) + endif() + list( APPEND _partition_defs DEBUG_PARTITION_UNSAFE ) +endif() + find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE) include(KDEInstallDirs) @@ -84,6 +99,7 @@ if ( KPMcore_FOUND ) kpmcore calamaresui KF5::CoreAddons + COMPILE_DEFINITIONS ${_partition_defs} SHARED_LIB ) else() diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index f51eec047..43d31fc5b 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -109,6 +109,9 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) CoreBackend* backend = CoreBackendManager::self()->backend(); DeviceList devices = backend->scanDevices( true ); +#ifdef DEBUG_PARTITION_UNSAFE + cWarning() << "Allowing unsafe partitioning choices." << devices.count() << "candidates."; +#else cDebug() << "Removing unsuitable devices:" << devices.count() << "candidates."; // Remove the device which contains / from the list @@ -142,6 +145,7 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) } else ++it; +#endif return devices; } From 8db004ce4552a4b790d9164ff2b491787011d37a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 13:32:18 -0400 Subject: [PATCH 08/16] [partition] Use the FailJob to stop installation - For unsafe installations (compile-time option), make sure things fail before partitions are actually written, unless the other option is also turned off. --- src/modules/partition/core/DeviceList.cpp | 3 +++ src/modules/partition/core/PartitionCoreModule.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index 43d31fc5b..cba942a06 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -111,6 +111,9 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) #ifdef DEBUG_PARTITION_UNSAFE cWarning() << "Allowing unsafe partitioning choices." << devices.count() << "candidates."; +#ifdef DEBUG_PARTITION_LAME + cDebug() << ".. it has been lamed, and will fail."; +#endif #else cDebug() << "Removing unsuitable devices:" << devices.count() << "candidates."; diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 07cb0fcfd..6beace4ff 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -45,6 +45,9 @@ #include "jobs/SetPartitionFlagsJob.h" #include "utils/CalamaresUtils.h" +#ifdef DEBUG_PARTITION_LAME +#include "JobExample.h" +#endif #include "Typedefs.h" #include "utils/Logger.h" @@ -497,6 +500,17 @@ PartitionCoreModule::jobs() const QList< Calamares::job_ptr > lst; QList< Device* > devices; +#ifdef DEBUG_PARTITION_UNSAFE +#ifdef DEBUG_PARTITION_LAME + cDebug() << "Unsafe partitioning is enabled."; + cDebug() << ".. it has been lamed, and will fail."; + lst << Calamares::job_ptr( new Calamares::FailJob( QStringLiteral( "Partition" ) ) ); +#else + cWarning() << "Unsafe partitioning is enabled."; + cWarning() << ".. the unsafe actions will be executed."; +#endif +#endif + lst << Calamares::job_ptr( new ClearTempMountsJob() ); for ( auto info : m_deviceInfos ) From cd545e51b0338638cc7211ad335c63854033a979 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 16:08:31 -0400 Subject: [PATCH 09/16] [partition] Reduce superfluous logging --- src/modules/partition/jobs/FillGlobalStorageJob.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 1f4026dec..72146e2a0 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -45,7 +45,6 @@ typedef QHash UuidForPartitionHash; static UuidForPartitionHash findPartitionUuids( QList < Device* > devices ) { - cDebug() << "Gathering UUIDs for partitions that exist now."; UuidForPartitionHash hash; foreach ( Device* device, devices ) { @@ -56,12 +55,11 @@ findPartitionUuids( QList < Device* > devices ) QString path = p->partitionPath(); QString uuid = p->fileSystem().readUUID( p->partitionPath() ); hash.insert( path, uuid ); - cDebug() << ".. added path=" << path << "UUID=" << uuid; } } if ( hash.isEmpty() ) - cDebug() << ".. no UUIDs found."; + cDebug() << "No UUIDs found for existing partitions."; return hash; } @@ -147,7 +145,6 @@ FillGlobalStorageJob::prettyDescription() const QString path = partitionMap.value( "device" ).toString(); QString mountPoint = partitionMap.value( "mountPoint" ).toString(); QString fsType = partitionMap.value( "fs" ).toString(); - qDebug() << partitionMap.value( "uuid" ) << path << mountPoint << fsType; if ( mountPoint.isEmpty() || fsType.isEmpty() ) continue; if ( path.isEmpty() ) From 1ffc0bf77df56f708ce8f3c8726a3671ec2f617a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 16:26:37 -0400 Subject: [PATCH 10/16] [partition] Allow all the unsafe options - If the unsafe actions are enabled, but won't be executed, allow more unsafe actions like erasing mounted partitions and everything. --- src/modules/partition/gui/ChoicePage.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 9d86a32a1..446d26a89 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -1359,6 +1359,16 @@ ChoicePage::setupActions() ) } +#ifdef DEBUG_PARTITION_UNSAFE +#ifdef DEBUG_PARTITION_LAME + // If things can't be broken, allow all the buttons + atLeastOneCanBeReplaced = true; + atLeastOneCanBeResized = true; + atLeastOneIsMounted = false; + isInactiveRAID = false; +#endif +#endif + if ( atLeastOneCanBeReplaced ) m_replaceButton->show(); else From 5d6d2b8078de3d363f9581e73a68ba704072802c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 17 Mar 2019 18:10:41 -0400 Subject: [PATCH 11/16] [partition] Make convenienceName() available for debugging - Function for human-readable names is useful in more parts of the partition module. --- src/modules/partition/core/PartUtils.cpp | 2 +- src/modules/partition/core/PartUtils.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 5cf8101f9..a02c18f97 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -43,7 +43,7 @@ namespace PartUtils { -static QString +QString convenienceName( const Partition* const candidate ) { if ( !candidate->mountPoint().isEmpty() ) diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index 0ad559a60..9b4efeec9 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -46,6 +46,15 @@ enum SizeUnit GiB }; +/** + * @brief Provides a nice human-readable name for @p candidate + * + * The most-specific human-readable name for the partition @p candidate + * is returned (e.g. device name, or partition path). In the worst + * case, a string representation of (void *)candidate is returned. + */ +QString convenienceName( const Partition* const candidate ); + /** * @brief canBeReplaced checks whether the given Partition satisfies the criteria * for replacing it with the new OS. From 2a2795c54ce655f067e8e44637adce00e8423f4e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 20 Mar 2019 16:32:13 +0100 Subject: [PATCH 12/16] [partition] Avoid KPMCore warnings - Get ready for KPMCore post-3.3.0, which deprecates a bunch of Flag and State in preparation of enum classes. --- src/modules/partition/core/KPMHelpers.cpp | 10 +++++----- src/modules/partition/core/KPMHelpers.h | 8 ++++++++ src/modules/partition/core/PartUtils.cpp | 2 +- src/modules/partition/core/PartitionActions.cpp | 6 +++--- src/modules/partition/core/PartitionCoreModule.cpp | 6 +++--- src/modules/partition/core/PartitionCoreModule.h | 3 ++- src/modules/partition/core/PartitionLayout.cpp | 4 ++-- src/modules/partition/gui/ReplaceWidget.cpp | 2 +- src/modules/partition/tests/PartitionJobTests.cpp | 8 ++++---- 9 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/modules/partition/core/KPMHelpers.cpp b/src/modules/partition/core/KPMHelpers.cpp index f8be44345..3c0a55987 100644 --- a/src/modules/partition/core/KPMHelpers.cpp +++ b/src/modules/partition/core/KPMHelpers.cpp @@ -67,7 +67,7 @@ isPartitionFreeSpace( Partition* partition ) bool isPartitionNew( Partition* partition ) { - return partition->state() == Partition::StateNew; + return partition->state() == KPM_PARTITION_STATE(New); } @@ -127,11 +127,11 @@ createNewPartition( PartitionNode* parent, role, fs, fs->firstSector(), fs->lastSector(), QString() /* path */, - PartitionTable::FlagNone /* availableFlags */, + KPM_PARTITION_FLAG(None) /* availableFlags */, QString() /* mountPoint */, false /* mounted */, flags /* activeFlags */, - Partition::StateNew + KPM_PARTITION_STATE(New) ); } @@ -169,11 +169,11 @@ createNewEncryptedPartition( PartitionNode* parent, PartitionRole( newRoles ), fs, fs->firstSector(), fs->lastSector(), QString() /* path */, - PartitionTable::FlagNone /* availableFlags */, + KPM_PARTITION_FLAG(None) /* availableFlags */, QString() /* mountPoint */, false /* mounted */, flags /* activeFlags */, - Partition::StateNew ); + KPM_PARTITION_STATE(New) ); return p; } diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index 0bcc533fb..3a2365984 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -33,6 +33,14 @@ class Partition; class PartitionNode; class PartitionRole; +#ifdef WITH_KPMCOREGT33 +#define KPM_PARTITION_FLAG(x) PartitionTable::Flag::x +#define KPM_PARTITION_STATE(x) Partition::State::x +#else +#define KPM_PARTITION_FLAG(x) PartitionTable::Flag##x +#define KPM_PARTITION_STATE(x) Partition::State##x +#endif + /** * Helper functions to manipulate partitions */ diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index a02c18f97..60bd80044 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -425,7 +425,7 @@ isEfiBootable( const Partition* candidate ) const PartitionTable* table = dynamic_cast( root ); cDebug() << " .. partition table" << (void *)table << "type" << ( table ? table->type() : PartitionTable::TableType::unknownTableType ); return table && ( table->type() == PartitionTable::TableType::gpt ) && - flags.testFlag( PartitionTable::FlagBoot ); + flags.testFlag( KPM_PARTITION_FLAG(Boot) ); } QString diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 4172002fa..f7185b219 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -129,7 +129,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO FileSystem::Fat32, firstFreeSector, lastSector, - PartitionTable::FlagNone + KPM_PARTITION_FLAG(None) ); PartitionInfo::setFormat( efiPartition, true ); PartitionInfo::setMountPoint( efiPartition, o.efiPartitionMountPoint ); @@ -178,7 +178,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO FileSystem::LinuxSwap, lastSectorForRoot + 1, dev->totalLogical() - 1, - PartitionTable::FlagNone + KPM_PARTITION_FLAG(None) ); } else @@ -191,7 +191,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO lastSectorForRoot + 1, dev->totalLogical() - 1, o.luksPassphrase, - PartitionTable::FlagNone + KPM_PARTITION_FLAG(None) ); } PartitionInfo::setFormat( swapPartition, true ); diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 6beace4ff..5d9b21bb0 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -299,7 +299,7 @@ PartitionCoreModule::createPartition( Device* device, deviceInfo->jobs << Calamares::job_ptr( job ); - if ( flags != PartitionTable::FlagNone ) + if ( flags != KPM_PARTITION_FLAG(None) ) { SetPartFlagsJob* fJob = new SetPartFlagsJob( device, partition, flags ); deviceInfo->jobs << Calamares::job_ptr( fJob ); @@ -401,7 +401,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition ) } QList< Calamares::job_ptr >& jobs = deviceInfo->jobs; - if ( partition->state() == Partition::StateNew ) + if ( partition->state() == KPM_PARTITION_STATE(New) ) { // First remove matching SetPartFlagsJobs for ( auto it = jobs.begin(); it != jobs.end(); ) @@ -832,7 +832,7 @@ PartitionCoreModule::layoutApply( Device *dev, if ( part->mountPoint() == "/" ) { createPartition( dev, part, - part->activeFlags() | ( isEfi ? PartitionTable::FlagNone : PartitionTable::FlagBoot ) + part->activeFlags() | ( isEfi ? KPM_PARTITION_FLAG(None) : KPM_PARTITION_FLAG(Boot) ) ); } else diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index 743f9c178..dc0c5eff5 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -20,6 +20,7 @@ #ifndef PARTITIONCOREMODULE_H #define PARTITIONCOREMODULE_H +#include "core/KPMHelpers.h" #include "core/PartitionLayout.h" #include "core/PartitionModel.h" #include "Typedefs.h" @@ -136,7 +137,7 @@ public: * applied to the newly-created partition. */ void createPartition( Device* device, Partition* partition, - PartitionTable::Flags flags = PartitionTable::FlagNone ); + PartitionTable::Flags flags = KPM_PARTITION_FLAG(None) ); void createVolumeGroup( QString &vgName, QVector< const Partition* > pvList, qint32 peSize ); diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index 4f62db7d6..98095b9ed 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -143,7 +143,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, part.partFileSystem, firstSector, end, - PartitionTable::FlagNone + KPM_PARTITION_FLAG(None) ); } else @@ -156,7 +156,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, firstSector, end, luksPassphrase, - PartitionTable::FlagNone + KPM_PARTITION_FLAG(None) ); } PartitionInfo::setFormat( currentPartition, true ); diff --git a/src/modules/partition/gui/ReplaceWidget.cpp b/src/modules/partition/gui/ReplaceWidget.cpp index faedc03d4..9c7a199be 100644 --- a/src/modules/partition/gui/ReplaceWidget.cpp +++ b/src/modules/partition/gui/ReplaceWidget.cpp @@ -154,7 +154,7 @@ ReplaceWidget::onPartitionSelected() Partition* partition = model->partitionForIndex( m_ui->partitionTreeView->currentIndex() ); if ( !partition || - partition->state() != Partition::StateNone ) + partition->state() != KPM_PARTITION_STATE(None) ) { updateStatus( CalamaresUtils::Fail, tr( "The selected item does not appear to be a valid partition." ) ); diff --git a/src/modules/partition/tests/PartitionJobTests.cpp b/src/modules/partition/tests/PartitionJobTests.cpp index 6a7e2ab72..0314ea9cd 100644 --- a/src/modules/partition/tests/PartitionJobTests.cpp +++ b/src/modules/partition/tests/PartitionJobTests.cpp @@ -228,11 +228,11 @@ PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition, Partiti role, fs, firstSector, lastSector, QString() /* path */, - PartitionTable::FlagNone /* availableFlags */, + KPM_PARTITION_FLAG(None) /* availableFlags */, QString() /* mountPoint */, false /* mounted */, - PartitionTable::FlagNone /* activeFlags */, - Partition::StateNew + KPM_PARTITION_FLAG(None) /* activeFlags */, + KPM_PARTITION_STATE(New) ); return new CreatePartitionJob( m_device.data(), partition ); } @@ -366,7 +366,7 @@ PartitionJobTests::testResizePartition() FileSystem::Ext4, oldFirst, oldLast, - PartitionTable::FlagNone + KPM_PARTITION_FLAG(None) ); CreatePartitionJob* job = new CreatePartitionJob( m_device.data(), partition ); job->updatePreview(); From 68f29ebf20441c5864b670832a1c31f354ab4d6a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 20 Mar 2019 16:37:50 +0100 Subject: [PATCH 13/16] [partition] Handle partition flag FlagEsp post KPMCore 3.3.0 --- src/modules/partition/core/KPMHelpers.h | 2 ++ src/modules/partition/core/PartUtils.cpp | 2 +- src/modules/partition/core/PartitionActions.cpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index 3a2365984..f1b8bd8a9 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -36,9 +36,11 @@ class PartitionRole; #ifdef WITH_KPMCOREGT33 #define KPM_PARTITION_FLAG(x) PartitionTable::Flag::x #define KPM_PARTITION_STATE(x) Partition::State::x +#define KPM_PARTITION_FLAG_ESP PartitionTable::Flag::Boot #else #define KPM_PARTITION_FLAG(x) PartitionTable::Flag##x #define KPM_PARTITION_STATE(x) Partition::State##x +#define KPM_PARTITION_FLAG_ESP PartitionTable::FlagEsp #endif /** diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 60bd80044..a4738aa8c 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -407,7 +407,7 @@ isEfiBootable( const Partition* candidate ) auto flags = PartitionInfo::flags( candidate ); /* If bit 17 is set, old-style Esp flag, it's OK */ - if ( flags.testFlag( PartitionTable::FlagEsp ) ) + if ( flags.testFlag( KPM_PARTITION_FLAG_ESP ) ) return true; /* Otherwise, if it's a GPT table, Boot (bit 0) is the same as Esp */ diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index f7185b219..074783186 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -133,7 +133,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO ); PartitionInfo::setFormat( efiPartition, true ); PartitionInfo::setMountPoint( efiPartition, o.efiPartitionMountPoint ); - core->createPartition( dev, efiPartition, PartitionTable::FlagEsp ); + core->createPartition( dev, efiPartition, KPM_PARTITION_FLAG_ESP ); firstFreeSector = lastSector + 1; } else From e8c18c0b5cc4595028ab3805e6c2ec42bfc637bd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 20 Mar 2019 16:46:10 +0100 Subject: [PATCH 14/16] [partition] Prepare scanDevices for post-KPMCore 3.3.0 --- src/modules/partition/core/DeviceList.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index cba942a06..858bb5c73 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -107,7 +107,11 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) bool writableOnly = (which == DeviceType::WritableOnly); CoreBackend* backend = CoreBackendManager::self()->backend(); - DeviceList devices = backend->scanDevices( true ); +#ifdef WITH_KPMCOREGT33 + DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag(0) ); +#else + DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true ); +#endif #ifdef DEBUG_PARTITION_UNSAFE cWarning() << "Allowing unsafe partitioning choices." << devices.count() << "candidates."; From 478168c8410ae663228f39d6bb8dfaafeac67eca Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 20 Mar 2019 18:16:54 +0100 Subject: [PATCH 15/16] [fsresizer] Make sure KPMCore version definitions are consistent - Duplicate setting from partition module to fsresizer --- src/modules/fsresizer/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/fsresizer/CMakeLists.txt b/src/modules/fsresizer/CMakeLists.txt index e339b2799..12349c835 100644 --- a/src/modules/fsresizer/CMakeLists.txt +++ b/src/modules/fsresizer/CMakeLists.txt @@ -6,6 +6,10 @@ if ( KPMcore_FOUND ) include_directories( ${KPMCORE_INCLUDE_DIR} ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamares ) + if ( KPMcore_VERSION VERSION_GREATER "3.3.0") + add_definitions(-DWITH_KPMCOREGT33) # kpmcore greater than 3.3 + endif() + # The PartitionIterator is a small class, and it's easiest -- but also a # gross hack -- to just compile it again from the partition module tree. calamares_add_plugin( fsresizer From affc73d3d2f9c5696678ee45fe92cfeb8235dc20 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 20 Mar 2019 18:20:56 +0100 Subject: [PATCH 16/16] [fsresizer] Avoid KPMCore warnings about scanDevices() --- src/modules/fsresizer/ResizeFSJob.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/fsresizer/ResizeFSJob.cpp b/src/modules/fsresizer/ResizeFSJob.cpp index 2ce9eba70..fa197e476 100644 --- a/src/modules/fsresizer/ResizeFSJob.cpp +++ b/src/modules/fsresizer/ResizeFSJob.cpp @@ -120,7 +120,12 @@ ResizeFSJob::PartitionMatch ResizeFSJob::findPartition( CoreBackend* backend ) { using DeviceList = QList< Device* >; - DeviceList devices = backend->scanDevices( false ); +#ifdef WITH_KPMCOREGT33 + DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag(0) ); +#else + DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true ); +#endif + cDebug() << "ResizeFSJob found" << devices.count() << "devices."; for ( DeviceList::iterator dev_it = devices.begin(); dev_it != devices.end(); ++dev_it ) {