aboutsummaryrefslogtreecommitdiff
path: root/autotests/kconfig_compiler
diff options
context:
space:
mode:
authorTomaz Canabrava <tcanabrava@kde.org>2020-01-14 18:52:43 +0000
committerTomaz Canabrava <tcanabrava@kde.org>2020-01-16 10:15:36 +0000
commit98c32e29f50465d4d4e16bafdf0491edbfb422b0 (patch)
tree06898a9ff9a5ed2e385b25a6b7fe258bb9eacb9c /autotests/kconfig_compiler
parenta601ac563d33681569befd22c9182cddaecf30b1 (diff)
downloadkconfig-98c32e29f50465d4d4e16bafdf0491edbfb422b0.tar.gz
kconfig-98c32e29f50465d4d4e16bafdf0491edbfb422b0.tar.bz2
WIP: Refactor KConfigXT
Summary: The current KConfigXT compiler is in a sad state: It's a massive file with loads of global variables that handle state, the generator is done within the main() function and it seems to have grown organically. There are no classes to separate logic / state / generation, what exists is code that generates code from a xml / ini pair, but it's hard to even discover what a bit of code is doing. The code istyle is C++ / Java from the nineties, which is not bad per see but it also uses quite a few things that are going to be deprecated in Qt 6 so I'm also taking the time make the code more streamlined with newer code style (no iterators, lambdas, auto usage, etc). The code that generates the files simplly pushes strings to a text stream, and it's hard to figure out when something starts or something ends: for instance, the code that generates the Constructor has more than sixty lines of code englobing some nested if - for - if - for constructs. Currently the code is "done" - there's one bug that I still need to find & fix regarding Translations, but the rest seems sane. The current testcode generates incorrect *whitespaces* regarding the old code (there's some parts that I feel that it's important to fix before merging, but overall, the whitespace changes are not bad and easier to handle, old code had a hand-counted amount of spaces before each line, new code has a function whitespace() that adds the current-and-correct amount of whitespaces based on indentation level that you start by startScope() and ends with endScope(). rest of the code still needs to be ported to it. I plan to fix the testcases whitespace by manually adding them, I'v fougth with the code for a while and added a few hacks there but I don't want to make the code hackish again. New code is not perfect by any means, but is a good step in the right direction. This code tries to Separate the compiler code into many different files / classes to be more obvious what's happening, and each class also has many helper methods to minimize copypaste. - CodeGenerator: Has base code for the header and source files that can be shared - HeaderGenerator: Logic for generating the header file - SourceGenerator: Logic for generating the source file - KcfgParser: Logic for parsing the kcfg file and extracting the information from the Xml file - CommonStructs: a header that contains the structs that are currently used everywhere. - KConfigParameters: (was CfgConfig - ConfigConfig, wat) - Has information passed via the kcfgc file - kcfg_compiler - will be renamed to main - start the other classes and generates the files. This code here currently has the begining of this separation, with the CodeGenerator and the HeaderGenerator in a ~good~ state, but unfinished. Test Plan: - Run the test cases, - Compare the diffs generated by the testcases and fix in the code the errors / differences - Run and compare real kde source with the new and old generators to look for errors Reviewers: #frameworks, ervin, bport, dfaure Reviewed By: dfaure Subscribers: bport, ngraham, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D26202
Diffstat (limited to 'autotests/kconfig_compiler')
-rw-r--r--autotests/kconfig_compiler/kconfigcompiler_test.cpp22
-rw-r--r--autotests/kconfig_compiler/test1.h.ref1
-rw-r--r--autotests/kconfig_compiler/test10.h.ref2
-rw-r--r--autotests/kconfig_compiler/test11.h.ref1
-rw-r--r--autotests/kconfig_compiler/test11a.h.ref1
-rw-r--r--autotests/kconfig_compiler/test12.h.ref1
-rw-r--r--autotests/kconfig_compiler/test13.h.ref2
-rw-r--r--autotests/kconfig_compiler/test9.h.ref1
-rw-r--r--autotests/kconfig_compiler/test_dpointer.cpp.ref44
-rw-r--r--autotests/kconfig_compiler/test_translation_kde.h.ref1
-rw-r--r--autotests/kconfig_compiler/test_translation_kde_domain.h.ref1
-rw-r--r--autotests/kconfig_compiler/test_translation_qt.h.ref1
12 files changed, 39 insertions, 39 deletions
diff --git a/autotests/kconfig_compiler/kconfigcompiler_test.cpp b/autotests/kconfig_compiler/kconfigcompiler_test.cpp
index 383745b1..7ab4a923 100644
--- a/autotests/kconfig_compiler/kconfigcompiler_test.cpp
+++ b/autotests/kconfig_compiler/kconfigcompiler_test.cpp
@@ -125,9 +125,7 @@ void KConfigCompiler_Test::testBaselineComparison()
if (content != contentRef) {
appendFileDiff(fileRef.fileName(), file.fileName());
}
- // use split('\n') to avoid
- // the whole output shown inline
- QCOMPARE(content.split('\n'), contentRef.split('\n'));
+
QVERIFY(content == contentRef);
}
@@ -166,17 +164,23 @@ void KConfigCompiler_Test::appendFileDiff(const QString &oldFile, const QString
return;
}
- QStringList args;
- args << QStringLiteral("-u");
- args << QFileInfo(oldFile).absoluteFilePath();
- args << QFileInfo(newFile).absoluteFilePath();
+ QStringList args({
+ QStringLiteral("-u"),
+ QFileInfo(oldFile).absoluteFilePath(),
+ QFileInfo(newFile).absoluteFilePath() });
QProcess process;
process.start(m_diffExe, args, QIODevice::ReadOnly);
process.waitForStarted();
process.waitForFinished();
+
if (process.exitCode() == 1) {
- QByteArray out = process.readAllStandardOutput();
- qDebug() << '\n' << out;
+ const QString diffFileName = oldFile + QStringLiteral(".diff");
+ QFile diffFile(diffFileName);
+ QVERIFY2(diffFile.open(QIODevice::WriteOnly), qPrintable(QLatin1String("Could not save diff file for ") + oldFile));
+ diffFile.write(process.readAllStandardOutput());
+
+ // force a failure to print the flename where we stored the diff.
+ QVERIFY2(false, qPrintable(QLatin1String("This test failed, look at the following file for details: ") + diffFileName));
}
}
diff --git a/autotests/kconfig_compiler/test1.h.ref b/autotests/kconfig_compiler/test1.h.ref
index 77c3b65f..52921ac6 100644
--- a/autotests/kconfig_compiler/test1.h.ref
+++ b/autotests/kconfig_compiler/test1.h.ref
@@ -8,6 +8,7 @@
#include <QDebug>
#include <qdir.h>
+
class Test1 : public KConfigSkeleton
{
public:
diff --git a/autotests/kconfig_compiler/test10.h.ref b/autotests/kconfig_compiler/test10.h.ref
index 93839a54..82bbab84 100644
--- a/autotests/kconfig_compiler/test10.h.ref
+++ b/autotests/kconfig_compiler/test10.h.ref
@@ -14,7 +14,6 @@ class Test10 : public KConfigSkeleton
static Test10 *self();
~Test10();
-
/**
Get foo bar
*/
@@ -24,7 +23,6 @@ class Test10 : public KConfigSkeleton
return self()->mFooBar;
}
-
/**
Get bar foo
*/
diff --git a/autotests/kconfig_compiler/test11.h.ref b/autotests/kconfig_compiler/test11.h.ref
index 395810ef..2acbe9e5 100644
--- a/autotests/kconfig_compiler/test11.h.ref
+++ b/autotests/kconfig_compiler/test11.h.ref
@@ -11,6 +11,7 @@
#include <QDebug>
#include "test11_types.h"
+
class Test11 : public MyPrefs
{
public:
diff --git a/autotests/kconfig_compiler/test11a.h.ref b/autotests/kconfig_compiler/test11a.h.ref
index 23c83713..62b59381 100644
--- a/autotests/kconfig_compiler/test11a.h.ref
+++ b/autotests/kconfig_compiler/test11a.h.ref
@@ -11,6 +11,7 @@
#include <QDebug>
#include "test11_types.h"
+
class Test11a : public MyPrefs
{
public:
diff --git a/autotests/kconfig_compiler/test12.h.ref b/autotests/kconfig_compiler/test12.h.ref
index d96d4609..e3954282 100644
--- a/autotests/kconfig_compiler/test12.h.ref
+++ b/autotests/kconfig_compiler/test12.h.ref
@@ -15,7 +15,6 @@ class Test12 : public KConfigSkeleton
Test12( );
~Test12();
-
/**
Get RnRSource
*/
diff --git a/autotests/kconfig_compiler/test13.h.ref b/autotests/kconfig_compiler/test13.h.ref
index 6c67fc5d..3a6e7f89 100644
--- a/autotests/kconfig_compiler/test13.h.ref
+++ b/autotests/kconfig_compiler/test13.h.ref
@@ -16,7 +16,6 @@ class Test13 : public KConfigSkeleton
Test13( );
~Test13();
-
Q_PROPERTY(QUrl picturesDir READ picturesDir CONSTANT)
/**
Get picturesDir
@@ -46,7 +45,6 @@ class Test13 : public KConfigSkeleton
return mBrightness;
}
-
Q_PROPERTY(bool startsWithUppercase READ startsWithUppercase CONSTANT)
/**
Get StartsWithUppercase
diff --git a/autotests/kconfig_compiler/test9.h.ref b/autotests/kconfig_compiler/test9.h.ref
index 9bcf0001..6e40cf48 100644
--- a/autotests/kconfig_compiler/test9.h.ref
+++ b/autotests/kconfig_compiler/test9.h.ref
@@ -8,6 +8,7 @@
#include <QDebug>
#include <qdir.h>
+
class Test9 : public KConfigSkeleton
{
public:
diff --git a/autotests/kconfig_compiler/test_dpointer.cpp.ref b/autotests/kconfig_compiler/test_dpointer.cpp.ref
index c69d38a4..1bfb9f52 100644
--- a/autotests/kconfig_compiler/test_dpointer.cpp.ref
+++ b/autotests/kconfig_compiler/test_dpointer.cpp.ref
@@ -157,8 +157,8 @@ TestDPointer::TestDPointer( )
void TestDPointer::setAutoSave( bool v )
{
- if (!self()->isImmutable( QStringLiteral( "AutoSave" ) ))
- self()->d->autoSave = v;
+ if (!self()->isImmutable( QStringLiteral( "AutoSave" ) ))
+ self()->d->autoSave = v;
}
bool TestDPointer::autoSave()
@@ -174,8 +174,8 @@ KConfigSkeleton::ItemBool *TestDPointer::autoSaveItem()
void TestDPointer::setAutoSaveInterval( int v )
{
- if (!self()->isImmutable( QStringLiteral( "AutoSaveInterval" ) ))
- self()->d->autoSaveInterval = v;
+ if (!self()->isImmutable( QStringLiteral( "AutoSaveInterval" ) ))
+ self()->d->autoSaveInterval = v;
}
int TestDPointer::autoSaveInterval()
@@ -191,8 +191,8 @@ KConfigSkeleton::ItemInt *TestDPointer::autoSaveIntervalItem()
void TestDPointer::setConfirm( bool v )
{
- if (!self()->isImmutable( QStringLiteral( "Confirm" ) ))
- self()->d->confirm = v;
+ if (!self()->isImmutable( QStringLiteral( "Confirm" ) ))
+ self()->d->confirm = v;
}
bool TestDPointer::confirm()
@@ -208,8 +208,8 @@ KConfigSkeleton::ItemBool *TestDPointer::confirmItem()
void TestDPointer::setArchiveFile( const QString & v )
{
- if (!self()->isImmutable( QStringLiteral( "ArchiveFile" ) ))
- self()->d->archiveFile = v;
+ if (!self()->isImmutable( QStringLiteral( "ArchiveFile" ) ))
+ self()->d->archiveFile = v;
}
QString TestDPointer::archiveFile()
@@ -225,8 +225,8 @@ KConfigSkeleton::ItemString *TestDPointer::archiveFileItem()
void TestDPointer::setDestination( int v )
{
- if (!self()->isImmutable( QStringLiteral( "Destination" ) ))
- self()->d->destination = v;
+ if (!self()->isImmutable( QStringLiteral( "Destination" ) ))
+ self()->d->destination = v;
}
int TestDPointer::destination()
@@ -242,8 +242,8 @@ KConfigSkeleton::ItemEnum *TestDPointer::destinationItem()
void TestDPointer::setHourSize( int v )
{
- if (!self()->isImmutable( QStringLiteral( "HourSize" ) ))
- self()->d->hourSize = v;
+ if (!self()->isImmutable( QStringLiteral( "HourSize" ) ))
+ self()->d->hourSize = v;
}
int TestDPointer::hourSize()
@@ -259,8 +259,8 @@ KConfigSkeleton::ItemInt *TestDPointer::hourSizeItem()
void TestDPointer::setSelectionStartsEditor( bool v )
{
- if (!self()->isImmutable( QStringLiteral( "SelectionStartsEditor" ) ))
- self()->d->selectionStartsEditor = v;
+ if (!self()->isImmutable( QStringLiteral( "SelectionStartsEditor" ) ))
+ self()->d->selectionStartsEditor = v;
}
bool TestDPointer::selectionStartsEditor()
@@ -276,8 +276,8 @@ KConfigSkeleton::ItemBool *TestDPointer::selectionStartsEditorItem()
void TestDPointer::setSelectedPlugins( const QStringList & v )
{
- if (!self()->isImmutable( QStringLiteral( "SelectedPlugins" ) ))
- self()->d->selectedPlugins = v;
+ if (!self()->isImmutable( QStringLiteral( "SelectedPlugins" ) ))
+ self()->d->selectedPlugins = v;
}
QStringList TestDPointer::selectedPlugins()
@@ -293,8 +293,8 @@ KConfigSkeleton::ItemStringList *TestDPointer::selectedPluginsItem()
void TestDPointer::setHighlightColor( const QColor & v )
{
- if (!self()->isImmutable( QStringLiteral( "HighlightColor" ) ))
- self()->d->highlightColor = v;
+ if (!self()->isImmutable( QStringLiteral( "HighlightColor" ) ))
+ self()->d->highlightColor = v;
}
QColor TestDPointer::highlightColor()
@@ -310,8 +310,8 @@ KConfigSkeleton::ItemColor *TestDPointer::highlightColorItem()
void TestDPointer::setAgendaBgColor( const QColor & v )
{
- if (!self()->isImmutable( QStringLiteral( "AgendaBgColor" ) ))
- self()->d->agendaBgColor = v;
+ if (!self()->isImmutable( QStringLiteral( "AgendaBgColor" ) ))
+ self()->d->agendaBgColor = v;
}
QColor TestDPointer::agendaBgColor()
@@ -327,8 +327,8 @@ KConfigSkeleton::ItemColor *TestDPointer::agendaBgColorItem()
void TestDPointer::setTimeBarFont( const QFont & v )
{
- if (!self()->isImmutable( QStringLiteral( "TimeBarFont" ) ))
- self()->d->timeBarFont = v;
+ if (!self()->isImmutable( QStringLiteral( "TimeBarFont" ) ))
+ self()->d->timeBarFont = v;
}
QFont TestDPointer::timeBarFont()
diff --git a/autotests/kconfig_compiler/test_translation_kde.h.ref b/autotests/kconfig_compiler/test_translation_kde.h.ref
index f9b582c4..0e50b5a2 100644
--- a/autotests/kconfig_compiler/test_translation_kde.h.ref
+++ b/autotests/kconfig_compiler/test_translation_kde.h.ref
@@ -17,7 +17,6 @@ class TestTranslationKde : public KConfigSkeleton
TestTranslationKde( );
~TestTranslationKde();
-
/**
Get Enable automatic saving of calendar
*/
diff --git a/autotests/kconfig_compiler/test_translation_kde_domain.h.ref b/autotests/kconfig_compiler/test_translation_kde_domain.h.ref
index 2fa42c71..4ed5d9bd 100644
--- a/autotests/kconfig_compiler/test_translation_kde_domain.h.ref
+++ b/autotests/kconfig_compiler/test_translation_kde_domain.h.ref
@@ -17,7 +17,6 @@ class TestTranslationKdeDomain : public KConfigSkeleton
TestTranslationKdeDomain( );
~TestTranslationKdeDomain();
-
/**
Get Enable automatic saving of calendar
*/
diff --git a/autotests/kconfig_compiler/test_translation_qt.h.ref b/autotests/kconfig_compiler/test_translation_qt.h.ref
index 9831468b..2fe3274a 100644
--- a/autotests/kconfig_compiler/test_translation_qt.h.ref
+++ b/autotests/kconfig_compiler/test_translation_qt.h.ref
@@ -17,7 +17,6 @@ class TestTranslationQt : public KConfigSkeleton
TestTranslationQt( );
~TestTranslationQt();
-
/**
Get Enable automatic saving of calendar
*/