From 5f659da9f8e6781c1d99e1756af1ecceb5359207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Thu, 27 Oct 2022 12:54:23 +0200 Subject: [PATCH] feat(StatusQ): SanityChecker app for imports validation Closes: #8071 --- ui/StatusQ/CMakeLists.txt | 1 + ui/StatusQ/sandbox/CMakeLists.txt | 2 +- ui/StatusQ/sanity_checker/CMakeLists.txt | 27 +++++++++++++ ui/StatusQ/sanity_checker/main.cpp | 48 ++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 ui/StatusQ/sanity_checker/CMakeLists.txt create mode 100644 ui/StatusQ/sanity_checker/main.cpp diff --git a/ui/StatusQ/CMakeLists.txt b/ui/StatusQ/CMakeLists.txt index 91b9c40154..58b1d8d149 100644 --- a/ui/StatusQ/CMakeLists.txt +++ b/ui/StatusQ/CMakeLists.txt @@ -20,4 +20,5 @@ set(QML_IMPORT_PATH add_subdirectory(vendor/SortFilterProxyModel) add_subdirectory(sandbox) +add_subdirectory(sanity_checker) add_subdirectory(tests) diff --git a/ui/StatusQ/sandbox/CMakeLists.txt b/ui/StatusQ/sandbox/CMakeLists.txt index cf9db8d815..2e08725698 100644 --- a/ui/StatusQ/sandbox/CMakeLists.txt +++ b/ui/StatusQ/sandbox/CMakeLists.txt @@ -5,7 +5,7 @@ find_package( COMPONENTS Core Quick QuickControls2 REQUIRED) -file(GLOB_RECURSE QML_FILES "../*.qml") +file(GLOB_RECURSE QML_FILES "../*.qml" "../qmldir") file(GLOB_RECURSE JS_FILES "../*.js") file(GLOB_RECURSE HEADERS *.h) if(APPLE) diff --git a/ui/StatusQ/sanity_checker/CMakeLists.txt b/ui/StatusQ/sanity_checker/CMakeLists.txt new file mode 100644 index 0000000000..00428e2618 --- /dev/null +++ b/ui/StatusQ/sanity_checker/CMakeLists.txt @@ -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() diff --git a/ui/StatusQ/sanity_checker/main.cpp b/ui/StatusQ/sanity_checker/main.cpp new file mode 100644 index 0000000000..2d3fe953da --- /dev/null +++ b/ui/StatusQ/sanity_checker/main.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +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; +}