CI: apply coding style across the entire codebase again

This commit is contained in:
Adriaan de Groot 2020-08-25 23:44:08 +02:00
parent 1cd9b93a22
commit a2180936ef
44 changed files with 234 additions and 168 deletions

View file

@ -35,7 +35,8 @@ static const char usage[] = "Usage: txload <origin> [<alternate> ...]\n"
"Outputs to stdout a human-readable list of differences between the\n"
"translations.\n";
bool load_file(const char* filename, QDomDocument& doc)
bool
load_file( const char* filename, QDomDocument& doc )
{
QFile file( filename );
QString err;
@ -48,7 +49,8 @@ bool load_file(const char* filename, QDomDocument& doc)
QByteArray ba( file.read( 1024 * 1024 ) );
qDebug() << "Read" << ba.length() << "bytes from" << filename;
if (!doc.setContent(ba, &err, &err_line, &err_column)) {
if ( !doc.setContent( ba, &err, &err_line, &err_column ) )
{
qDebug() << "Could not read" << filename << ':' << err_line << ':' << err_column << ' ' << err;
file.close();
return false;
@ -58,45 +60,58 @@ bool load_file(const char* filename, QDomDocument& doc)
return true;
}
QDomElement find_context(QDomDocument& doc, const QString& name)
QDomElement
find_context( QDomDocument& doc, const QString& name )
{
QDomElement top = doc.documentElement();
QDomNode n = top.firstChild();
while (!n.isNull()) {
if (n.isElement()) {
while ( !n.isNull() )
{
if ( n.isElement() )
{
QDomElement e = n.toElement();
if ( ( e.tagName() == "context" ) && ( e.firstChildElement( "name" ).text() == name ) )
{
return e;
}
}
n = n.nextSibling();
}
return QDomElement();
}
QDomElement find_message(QDomElement& context, const QString& source)
QDomElement
find_message( QDomElement& context, const QString& source )
{
QDomNode n = context.firstChild();
while (!n.isNull()) {
if (n.isElement()) {
while ( !n.isNull() )
{
if ( n.isElement() )
{
QDomElement e = n.toElement();
if ( e.tagName() == "message" )
{
QString msource = e.firstChildElement( "source" ).text();
if ( msource == source )
{
return e;
}
}
}
n = n.nextSibling();
}
return QDomElement();
}
bool merge_into(QDomElement& origin, QDomElement& alternate)
bool
merge_into( QDomElement& origin, QDomElement& alternate )
{
QDomNode n = alternate.firstChild();
while (!n.isNull()) {
if (n.isElement()) {
while ( !n.isNull() )
{
if ( n.isElement() )
{
QDomElement alternateMessage = n.toElement();
if ( alternateMessage.tagName() == "message" )
{
@ -119,7 +134,8 @@ bool merge_into(QDomElement& origin, QDomElement& alternate)
}
if ( !alternateTranslationText.isEmpty() && ( alternateTranslationText != originTranslationText ) )
{
qDebug() << "\n\n\nSource:" << alternateSourceText << "\nTL1:" << originTranslationText << "\nTL2:" << alternateTranslationText;
qDebug() << "\n\n\nSource:" << alternateSourceText << "\nTL1:" << originTranslationText
<< "\nTL2:" << alternateTranslationText;
}
}
}
@ -130,12 +146,14 @@ bool merge_into(QDomElement& origin, QDomElement& alternate)
}
bool merge_into(QDomDocument& originDocument, QDomElement& context)
bool
merge_into( QDomDocument& originDocument, QDomElement& context )
{
QDomElement name = context.firstChildElement( "name" );
if ( name.isNull() )
{
return false;
}
QString contextname = name.text();
QDomElement originContext = find_context( originDocument, contextname );
@ -148,24 +166,30 @@ bool merge_into(QDomDocument& originDocument, QDomElement& context)
return merge_into( originContext, context );
}
bool merge_into(QDomDocument& originDocument, QDomDocument& alternateDocument)
bool
merge_into( QDomDocument& originDocument, QDomDocument& alternateDocument )
{
QDomElement top = alternateDocument.documentElement();
QDomNode n = top.firstChild();
while (!n.isNull()) {
if (n.isElement()) {
while ( !n.isNull() )
{
if ( n.isElement() )
{
QDomElement e = n.toElement();
if ( e.tagName() == "context" )
if ( !merge_into( originDocument, e ) )
{
return false;
}
}
n = n.nextSibling();
}
return true;
}
int main(int argc, char** argv)
int
main( int argc, char** argv )
{
QCoreApplication a( argc, argv );
@ -177,16 +201,22 @@ int main(int argc, char** argv)
QDomDocument originDocument( "origin" );
if ( !load_file( argv[ 1 ], originDocument ) )
{
return 1;
}
for ( int i = 2; i < argc; ++i )
{
QDomDocument alternateDocument( "alternate" );
if ( !load_file( argv[ i ], alternateDocument ) )
{
return 1;
}
if ( !merge_into( originDocument, alternateDocument ) )
{
return 1;
}
}
QString outfilename( argv[ 1 ] );
outfilename.append( ".new" );

View file

@ -67,7 +67,8 @@ CalamaresApplication::init()
{
Logger::setupLogfile();
cDebug() << "Calamares version:" << CALAMARES_VERSION;
cDebug() << Logger::SubEntry << " languages:" << QString( CALAMARES_TRANSLATION_LANGUAGES ).replace( ";", ", " );
cDebug() << Logger::SubEntry
<< " languages:" << QString( CALAMARES_TRANSLATION_LANGUAGES ).replace( ";", ", " );
if ( !Calamares::Settings::instance() )
{

View file

@ -184,7 +184,8 @@ DebugWindow::DebugWindow()
#endif
] {
QString moduleName = m_ui->modulesListView->currentIndex().data().toString();
Module* module = ModuleManager::instance()->moduleInstance( ModuleSystem::InstanceKey::fromString( moduleName ) );
Module* module
= ModuleManager::instance()->moduleInstance( ModuleSystem::InstanceKey::fromString( moduleName ) );
if ( module )
{
m_module = module->configurationMap();

View file

@ -14,26 +14,29 @@
#include "utils/Yaml.h"
#include <unistd.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <QFile>
#include <QByteArray>
#include <QFile>
using std::cerr;
static const char usage[] = "Usage: test_conf [-v] [-b] <file> ...\n";
int main(int argc, char** argv)
int
main( int argc, char** argv )
{
bool verbose = false;
bool bytes = false;
int opt;
while ((opt = getopt(argc, argv, "vb")) != -1) {
switch (opt) {
while ( ( opt = getopt( argc, argv, "vb" ) ) != -1 )
{
switch ( opt )
{
case 'v':
verbose = true;
break;
@ -60,10 +63,14 @@ int main(int argc, char** argv)
{
QFile f( filename );
if ( f.open( QFile::ReadOnly | QFile::Text ) )
{
doc = YAML::Load( f.readAll().constData() );
}
}
else
{
doc = YAML::LoadFile( filename );
}
if ( doc.IsNull() )
{
@ -86,9 +93,11 @@ int main(int argc, char** argv)
{
cerr << "Keys:\n";
for ( auto i = doc.begin(); i != doc.end(); ++i )
{
cerr << i->first.as< std::string >() << '\n';
}
}
}
catch ( YAML::Exception& e )
{
cerr << "WARNING:" << filename << '\n';

View file

@ -323,7 +323,8 @@ load_module( const ModuleConfig& moduleConfig )
cDebug() << "Module" << moduleName << "job-configuration:" << configFile;
Calamares::Module* module = Calamares::moduleFromDescriptor( Calamares::ModuleSystem::Descriptor::fromDescriptorData( descriptor ), name, configFile, moduleDirectory );
Calamares::Module* module = Calamares::moduleFromDescriptor(
Calamares::ModuleSystem::Descriptor::fromDescriptorData( descriptor ), name, configFile, moduleDirectory );
return module;
}

View file

@ -67,7 +67,8 @@ Handler::Handler( const QString& implementation, const QString& url, const QStri
{
cWarning() << "GeoIP style *none* does not do anything.";
}
else if ( m_type == Type::Fixed && Calamares::Settings::instance() && !Calamares::Settings::instance()->debugMode() )
else if ( m_type == Type::Fixed && Calamares::Settings::instance()
&& !Calamares::Settings::instance()->debugMode() )
{
cWarning() << "GeoIP style *fixed* is not recommended for production.";
}

View file

@ -358,7 +358,9 @@ ZonesModel::find( const QString& region, const QString& zone ) const
}
STATICTEST const TimeZoneData*
find( double startingDistance, const ZoneVector& zones, const std::function< double( const TimeZoneData* ) >& distanceFunc )
find( double startingDistance,
const ZoneVector& zones,
const std::function< double( const TimeZoneData* ) >& distanceFunc )
{
double smallestDistance = startingDistance;
const TimeZoneData* closest = nullptr;
@ -379,7 +381,8 @@ const TimeZoneData*
ZonesModel::find( const std::function< double( const TimeZoneData* ) >& distanceFunc ) const
{
const auto* officialZone = CalamaresUtils::Locale::find( 1000000.0, m_private->m_zones, distanceFunc );
const auto* altZone = CalamaresUtils::Locale::find( distanceFunc( officialZone ), m_private->m_altZones, distanceFunc );
const auto* altZone
= CalamaresUtils::Locale::find( distanceFunc( officialZone ), m_private->m_altZones, distanceFunc );
// If nothing was closer than the official zone already was, altZone is
// nullptr; but if there is a spot-patch, then we need to re-find

View file

@ -86,8 +86,7 @@ moduleConfigurationCandidates( bool assumeBuildDir, const QString& moduleName, c
return paths;
}
void
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
void Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
{
QStringList configCandidates
= moduleConfigurationCandidates( Settings::instance()->debugMode(), name(), configFileName );

View file

@ -89,9 +89,8 @@ RequirementsModel::describe() const
int count = 0;
for ( const auto& r : m_requirements )
{
cDebug() << Logger::SubEntry << "requirement" << count << r.name
<< "satisfied?" << r.satisfied
<< "mandatory?" << r.mandatory;
cDebug() << Logger::SubEntry << "requirement" << count << r.name << "satisfied?" << r.satisfied << "mandatory?"
<< r.mandatory;
if ( r.mandatory && !r.satisfied )
{
acceptable = false;

View file

@ -62,7 +62,8 @@ InternalManager::InternalManager()
else
{
auto* backend_p = CoreBackendManager::self()->backend();
cDebug() << Logger::SubEntry << "Backend" << Logger::Pointer(backend_p) << backend_p->id() << backend_p->version();
cDebug() << Logger::SubEntry << "Backend" << Logger::Pointer( backend_p ) << backend_p->id()
<< backend_p->version();
s_kpm_loaded = true;
}
}

View file

@ -187,7 +187,8 @@ System::runCommand( System::RunLocation location,
? ( static_cast< int >( std::chrono::milliseconds( timeoutSec ).count() ) )
: -1 ) )
{
cWarning() << "Process" << args.first() << "timed out after" << timeoutSec.count() << "s. Output so far:\n" << Logger::NoQuote{} << process.readAllStandardOutput();
cWarning() << "Process" << args.first() << "timed out after" << timeoutSec.count() << "s. Output so far:\n"
<< Logger::NoQuote {} << process.readAllStandardOutput();
return ProcessResult::Code::TimedOut;
}
@ -204,7 +205,8 @@ System::runCommand( System::RunLocation location,
bool showDebug = ( !Calamares::Settings::instance() ) || ( Calamares::Settings::instance()->debugMode() );
if ( ( r != 0 ) || showDebug )
{
cDebug() << Logger::SubEntry << "Target cmd:" << RedactedList( args ) << "output:\n" << Logger::NoQuote{} << output;
cDebug() << Logger::SubEntry << "Target cmd:" << RedactedList( args ) << "output:\n"
<< Logger::NoQuote {} << output;
}
return ProcessResult( r, output );
}

View file

@ -412,7 +412,8 @@ LibCalamaresTests::testVariantStringListCode()
m.insert( key, 17 );
QCOMPARE( getStringList( m, key ), QStringList {} );
m.insert( key, QString( "more strings" ) );
QCOMPARE( getStringList( m, key ), QStringList { "more strings" } ); // A single string **can** be considered a stringlist!
QCOMPARE( getStringList( m, key ),
QStringList { "more strings" } ); // A single string **can** be considered a stringlist!
m.insert( key, QVariant {} );
QCOMPARE( getStringList( m, key ), QStringList {} );
}

View file

@ -49,17 +49,30 @@ namespace CalamaresUtils
*/
namespace Traits
{
template< class > struct sfinae_true : std::true_type{};
}
}
template < class >
struct sfinae_true : std::true_type
{
};
} // namespace Traits
} // namespace CalamaresUtils
#define DECLARE_HAS_METHOD( m ) \
namespace CalamaresUtils { namespace Traits { \
struct has_ ## m { \
template< class T > static auto f(int) -> sfinae_true<decltype(&T:: m)>; \
template< class T > static auto f(long) -> std::false_type; \
template< class T > using t = decltype( f <T>(0) ); \
}; } } \
template< class T > using has_ ## m = CalamaresUtils::Traits:: has_ ## m ::t<T>;
namespace CalamaresUtils \
{ \
namespace Traits \
{ \
struct has_##m \
{ \
template < class T > \
static auto f( int ) -> sfinae_true< decltype( &T::m ) >; \
template < class T > \
static auto f( long ) -> std::false_type; \
template < class T > \
using t = decltype( f< T >( 0 ) ); \
}; \
} \
} \
template < class T > \
using has_##m = CalamaresUtils::Traits::has_##m ::t< T >;
#endif

View file

@ -58,7 +58,10 @@ DLLEXPORT double getDouble( const QVariantMap& map, const QString& key, double d
* Returns @p d if there is no such key or it is not a map-value.
* (e.g. if @p success is false).
*/
DLLEXPORT QVariantMap getSubMap( const QVariantMap& map, const QString& key, bool& success, const QVariantMap& d = QVariantMap() );
DLLEXPORT QVariantMap getSubMap( const QVariantMap& map,
const QString& key,
bool& success,
const QVariantMap& d = QVariantMap() );
} // namespace CalamaresUtils
#endif

View file

@ -48,7 +48,8 @@ moduleFromDescriptor( const Calamares::ModuleSystem::Descriptor& moduleDescripto
std::unique_ptr< Module > m;
if ( !moduleDescriptor.isValid() ) {
if ( !moduleDescriptor.isValid() )
{
cError() << "Bad module descriptor format" << instanceId;
return nullptr;
}
@ -68,7 +69,9 @@ moduleFromDescriptor( const Calamares::ModuleSystem::Descriptor& moduleDescripto
}
else
{
cError() << "Bad interface" << Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() ) << "for module type" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() );
cError() << "Bad interface"
<< Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() )
<< "for module type" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() );
}
}
else if ( moduleDescriptor.type() == Type::Job )
@ -91,7 +94,9 @@ moduleFromDescriptor( const Calamares::ModuleSystem::Descriptor& moduleDescripto
}
else
{
cError() << "Bad interface" << Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() ) << "for module type" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() );
cError() << "Bad interface"
<< Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() )
<< "for module type" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() );
}
}
else
@ -101,7 +106,9 @@ moduleFromDescriptor( const Calamares::ModuleSystem::Descriptor& moduleDescripto
if ( !m )
{
cError() << "Bad module type (" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() ) << ") or interface string (" << Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() ) << ") for module "
cError() << "Bad module type (" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() )
<< ") or interface string ("
<< Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() ) << ") for module "
<< instanceId;
return nullptr;
}

View file

@ -104,7 +104,8 @@ ModuleManager::doInit()
if ( ok && !moduleName.isEmpty() && ( moduleName == currentDir.dirName() )
&& !m_availableDescriptorsByModuleName.contains( moduleName ) )
{
auto descriptor = Calamares::ModuleSystem::Descriptor::fromDescriptorData( moduleDescriptorMap );
auto descriptor
= Calamares::ModuleSystem::Descriptor::fromDescriptorData( moduleDescriptorMap );
descriptor.setDirectory( descriptorFileInfo.absoluteDir().absolutePath() );
m_availableDescriptorsByModuleName.insert( moduleName, descriptor );
}
@ -243,11 +244,8 @@ ModuleManager::loadModules()
}
else
{
thisModule
= Calamares::moduleFromDescriptor( descriptor,
instanceKey.id(),
configFileName,
descriptor.directory() );
thisModule = Calamares::moduleFromDescriptor(
descriptor, instanceKey.id(), configFileName, descriptor.directory() );
if ( !thisModule )
{
cError() << "Module" << instanceKey.toString() << "cannot be created from descriptor"
@ -375,8 +373,7 @@ ModuleManager::checkDependencies()
for ( auto it = m_availableDescriptorsByModuleName.begin(); it != m_availableDescriptorsByModuleName.end();
++it )
{
QStringList unmet = missingRequiredModules( it->requiredModules(),
m_availableDescriptorsByModuleName );
QStringList unmet = missingRequiredModules( it->requiredModules(), m_availableDescriptorsByModuleName );
if ( unmet.count() > 0 )
{
@ -403,8 +400,7 @@ ModuleManager::checkModuleDependencies( const Module& m )
}
bool allRequirementsFound = true;
QStringList requiredModules
= m_availableDescriptorsByModuleName[ m.name() ].requiredModules();
QStringList requiredModules = m_availableDescriptorsByModuleName[ m.name() ].requiredModules();
for ( const QString& required : requiredModules )
{

View file

@ -202,7 +202,8 @@ PreserveFiles::setConfigurationMap( const QVariantMap& configurationMap )
{
QString filename = li.toString();
if ( !filename.isEmpty() )
m_items.append( Item { filename, filename, CalamaresUtils::Permissions( defaultPermissions ), ItemType::Path } );
m_items.append(
Item { filename, filename, CalamaresUtils::Permissions( defaultPermissions ), ItemType::Path } );
else
{
cDebug() << "Empty filename for preservefiles, item" << c;

View file

@ -8,8 +8,8 @@
#include "utils/Logger.h"
#include <QtTest/QtTest>
#include <QObject>
#include <QtTest/QtTest>
class TrackingTests : public QObject
{
@ -28,17 +28,17 @@ TrackingTests::TrackingTests()
{
}
TrackingTests::~TrackingTests()
{
}
TrackingTests::~TrackingTests() {}
void TrackingTests::initTestCase()
void
TrackingTests::initTestCase()
{
Logger::setupLogLevel( Logger::LOGDEBUG );
cDebug() << "Tracking test started.";
}
void TrackingTests::testEmptyConfig()
void
TrackingTests::testEmptyConfig()
{
Logger::setupLogLevel( Logger::LOGDEBUG );

View file

@ -16,11 +16,11 @@
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h"
#include <QDir>
#include <QFile>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDir>
#include <QFile>
using WriteMode = CalamaresUtils::System::WriteMode;

View file

@ -106,7 +106,8 @@ UserTests::testDefaultGroups()
}
}
void UserTests::testDefaultGroupsYAML_data()
void
UserTests::testDefaultGroupsYAML_data()
{
QTest::addColumn< QString >( "filename" );
QTest::addColumn< int >( "count" );

View file

@ -45,7 +45,8 @@ static inline void
labelOk( QLabel* pix, QLabel* label )
{
label->clear();
pix->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::StatusOk, CalamaresUtils::Original, label->size() ) );
pix->setPixmap(
CalamaresUtils::defaultPixmap( CalamaresUtils::StatusOk, CalamaresUtils::Original, label->size() ) );
}
/** @brief Sets error or ok on a label depending on @p status and @p value

View file

@ -19,8 +19,8 @@
#include <DllMacro.h>
#include <QVariant>
#include "Config.h"
#include <QVariant>
class PLUGINDLLEXPORT UsersQmlViewStep : public Calamares::QmlViewStep
{
@ -44,10 +44,7 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override;
QObject * getConfig() override
{
return m_config;
}
QObject* getConfig() override { return m_config; }
private:
Config* m_config;

View file

@ -8,8 +8,8 @@
*
*/
#include "WebViewConfig.h"
#include "WebViewStep.h"
#include "WebViewConfig.h"
#include <QVariant>

View file

@ -146,9 +146,7 @@ GeneralRequirements::checkRequirements()
{
checkEntries.append(
{ entry,
[ req = m_requiredStorageGiB ] {
return tr( "has at least %1 GiB available drive space" ).arg( req );
},
[req = m_requiredStorageGiB] { return tr( "has at least %1 GiB available drive space" ).arg( req ); },
[req = m_requiredStorageGiB] {
return tr( "There is not enough drive space. At least %1 GiB is required." ).arg( req );
},

View file

@ -11,7 +11,8 @@
#define PARTMAN_DEVICES_H
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
int check_big_enough( long long required_space );