feat(StatusQ): SanityChecker app for imports validation

Closes: #8071
This commit is contained in:
Michał Cieślak 2022-10-27 12:54:23 +02:00 committed by Jakub
parent cabfaf1ed6
commit 5f659da9f8
4 changed files with 77 additions and 1 deletions

View File

@ -20,4 +20,5 @@ set(QML_IMPORT_PATH
add_subdirectory(vendor/SortFilterProxyModel) add_subdirectory(vendor/SortFilterProxyModel)
add_subdirectory(sandbox) add_subdirectory(sandbox)
add_subdirectory(sanity_checker)
add_subdirectory(tests) add_subdirectory(tests)

View File

@ -5,7 +5,7 @@ find_package(
COMPONENTS Core Quick QuickControls2 COMPONENTS Core Quick QuickControls2
REQUIRED) REQUIRED)
file(GLOB_RECURSE QML_FILES "../*.qml") file(GLOB_RECURSE QML_FILES "../*.qml" "../qmldir")
file(GLOB_RECURSE JS_FILES "../*.js") file(GLOB_RECURSE JS_FILES "../*.js")
file(GLOB_RECURSE HEADERS *.h) file(GLOB_RECURSE HEADERS *.h)
if(APPLE) if(APPLE)

View File

@ -0,0 +1,27 @@
project(SanityChecker)
find_package(
Qt5
COMPONENTS Core Quick QuickControls2
REQUIRED)
set(QRC_FILES ../src/statusq.qrc ../src/assets.qrc)
qt5_add_resources(QRC_COMPILED ${QRC_FILES})
add_executable(
${PROJECT_NAME}
main.cpp
${QRC_FILES}
${QRC_COMPILED}
)
target_link_libraries(
${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick Qt5::QuickControls2
SortFilterProxyModel)
if (APPLE)
find_library(AppKit AppKit)
find_library(Foundation Foundation)
target_link_libraries(${PROJECT_NAME} PRIVATE ${AppKit} ${Foundation})
endif()

View File

@ -0,0 +1,48 @@
#include <QCoreApplication>
#include <QDebug>
#include <QDirIterator>
#include <QQmlComponent>
#include <QQmlEngine>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QQmlEngine engine;
engine.addImportPath(QStringLiteral(":/"));
QDirIterator it(":", QDirIterator::Subdirectories);
bool errorsFound = false;
while (it.hasNext()) {
QFileInfo info = it.fileInfo();
if (info.suffix() == QStringLiteral("qml")) {
QFile file(it.filePath());
file.open(QIODevice::ReadOnly);
QTextStream in(&file);
QString line = in.readLine();
if (line != QStringLiteral("pragma Singleton")) {
engine.setBaseUrl(QStringLiteral("qrc") + info.dir().path()
+ QDir::separator());
QQmlComponent component(&engine, it.fileName());
if (component.isError()) {
qWarning() << component.errors();
errorsFound = true;
}
}
}
it.next();
}
if (errorsFound)
return EXIT_FAILURE;
qDebug() << "Verification completed successfully.";
return EXIT_SUCCESS;
}