From ac8fc70a4ebfb887c1add9069ddec1a66a9a196c Mon Sep 17 00:00:00 2001 From: woblight Date: Mon, 12 Aug 2024 21:08:22 +0200 Subject: [PATCH] Refine self update build options --- CI.mk | 5 +++-- CMakeLists.txt | 15 +++++++++++---- control.cpp | 18 ++++++++++++++++-- control.h | 19 +++++++++++++++++++ main.cpp | 12 ------------ main.qml | 3 ++- 6 files changed, 51 insertions(+), 21 deletions(-) diff --git a/CI.mk b/CI.mk index 8457b76..673c2a4 100644 --- a/CI.mk +++ b/CI.mk @@ -9,6 +9,7 @@ winepwd:=$(shell $(wine) winepath -w $(pwd)) WINEPREFIX=WINEPREFIX="$(pwd)/wine" WINEPATH=WINEPATH='C:\Program Files (x86)\CMake\bin;$(shell $(winepath) -w "$(pwd)/mingw64/bin");$(shell $(winepath) -w "$(pwd)/Qt/6.7.2/mingw_64/bin")' QTDIR="Z:$(pwd)/Qt/6.7.2/mingw_64/" branch:=$(CI_COMMIT_BRANCH) +gam_opts:=-DDGitAddonsManager_SELF_UPDATE=ON -DGitAddonsManager_GIT_DESCRIBE="$(shell git describe --tags --long)" -DGitAddonsManager_BUILD_NAME=$(CI_JOB_NAME) -DGitAddonsManager_BRANCH_NAME=$(branch) ifeq ($(branch),) branch:=$(CI_DEFAULT_BRANCH) endif @@ -19,7 +20,7 @@ finalize: cd GitAddonsManager && echo "# DO NOT EDIT" > .installedFiles && find ! -path . >> .installedFiles build: - mkdir -p build && cd build && cmake ../ -DGitAddonsManager_BUILD_NAME=$(CI_JOB_NAME) -DGitAddonsManager_BRANCH_NAME=$(branch) -G"Ninja" -DCMAKE_BUILD_TYPE=Release --install-prefix="$(pwd)/release" && ninja && ninja install + mkdir -p build && cd build && cmake ../ $(gam_opts) -G"Ninja" -DCMAKE_BUILD_TYPE=Release --install-prefix="$(pwd)/release" && ninja && ninja install linuxdeploy: build mkdir GitAddonsManager @@ -111,7 +112,7 @@ quazip/release/bin/libquazip1-qt6.dll: quazip/CMakeLists.txt $(wine) mingw32-make -C quazip/build install build_win64/GitAddonsManager.exe: Qt libgit2-0.27.2/release/bin/libgit2.dll zlib/build/libzlib.dll quazip/release/bin/libquazip1-qt6.dll - mkdir -p build_win64 && cd build_win64 && $(wine) cmake ../ -DGitAddonsManager_GIT_DESCRIBE="$(shell git describe --tags --long)" -DGitAddonsManager_BUILD_NAME=$(CI_JOB_NAME) -DGitAddonsManager_BRANCH_NAME=$(branch) -G"MinGW Makefiles" -DQuaZip-Qt6_DIR=$(pwd)/quazip/release/lib/cmake/QuaZip-Qt6-1.4/ -DLIBGIT2_LIBRARY=$(pwd)/libgit2-0.27.2/release/bin/libgit2.dll -DLIBGIT2_INCLUDE_DIR=$(pwd)/libgit2-0.27.2/release/include -DZLIB_LIBRARY=$(pwd)/zlib/build/libzlib.dll.a -DZLIB_INCLUDE_DIR=$(pwd)/zlib -DCMAKE_BUILD_TYPE=Release --install-prefix="$(winepwd)/release" + mkdir -p build_win64 && cd build_win64 && $(wine) cmake ../ $(gam_opts) -G"MinGW Makefiles" -DQuaZip-Qt6_DIR=$(pwd)/quazip/release/lib/cmake/QuaZip-Qt6-1.4/ -DLIBGIT2_LIBRARY=$(pwd)/libgit2-0.27.2/release/bin/libgit2.dll -DLIBGIT2_INCLUDE_DIR=$(pwd)/libgit2-0.27.2/release/include -DZLIB_LIBRARY=$(pwd)/zlib/build/libzlib.dll.a -DZLIB_INCLUDE_DIR=$(pwd)/zlib -DCMAKE_BUILD_TYPE=Release --install-prefix="$(winepwd)/release" $(wine) mingw32-make -C build_win64 -j $(shell nproc) $(wine) mingw32-make -C build_win64 install diff --git a/CMakeLists.txt b/CMakeLists.txt index 697165d..e4523ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,8 @@ set(${PROJECT_NAME}_BUILD_NAME "" CACHE STRING "name of the build pipeline for s set(${PROJECT_NAME}_BRANCH_NAME "" CACHE STRING "name of the branch for self updates") +option(${PROJECT_NAME}_SELF_UPDATE "Enable the self-update feature") + qt_add_executable(GitAddonsManager addon.h control.h utils.h main.cpp addon.cpp control.cpp @@ -70,11 +72,16 @@ add_compile_definitions( GAM_EXEC="GitAddonsManager${CMAKE_EXECUTABLE_SUFFIX}" ) -if (NOT ${PROJECT_NAME}_BUILD_NAME STREQUAL "") - add_compile_definitions(GAM_BUILD_NAME="${${PROJECT_NAME}_BUILD_NAME}") -endif() -if (NOT ${PROJECT_NAME}_BRANCH_NAME STREQUAL "") +if (${PROJECT_NAME}_SELF_UPDATE) + if (${PROJECT_NAME}_BUILD_NAME STREQUAL "") + message(FATAL_ERROR "${PROJECT_NAME}_SELF_UPDATE is enabled but ${PROJECT_NAME}_BUILD_NAME is not set" ) + endif() + if (${PROJECT_NAME}_BRANCH_NAME STREQUAL "") + message(FATAL_ERROR "${PROJECT_NAME}_SELF_UPDATE is enabled but ${PROJECT_NAME}_BRANCH_NAME is not set" ) + endif() add_compile_definitions(GAM_BRANCH_NAME="${${PROJECT_NAME}_BRANCH_NAME}") + add_compile_definitions(GAM_BUILD_NAME="${${PROJECT_NAME}_BUILD_NAME}") + add_compile_definitions(GAM_SELF_UPDATE) endif() target_link_libraries(GitAddonsManager PUBLIC Qt6::Core) diff --git a/control.cpp b/control.cpp index a7bb42d..03b22c7 100644 --- a/control.cpp +++ b/control.cpp @@ -520,7 +520,7 @@ void Control::setAvailableStyles(QStringList availableStyles) void Control::checkForUpdates() { -#if defined(GAM_BUILD_NAME) && defined(GAM_BRANCH_NAME) +#ifdef GAM_SELF_UPDATE QNetworkRequest req(QUrl(QString("https://gitlab.com/woblight/GitAddonsManager/-/jobs/artifacts/%1/download?job=%2").arg(GAM_BRANCH_NAME).arg(GAM_BUILD_NAME))); req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); connect(nam, &QNetworkAccessManager::finished, [](auto reply){ @@ -542,7 +542,7 @@ void Control::checkForUpdates() void Control::downloadUpdate() { -#if defined(GAM_BUILD_NAME) && defined(GAM_BRANCH_NAME) +#ifdef GAM_SELF_UPDATE QFile *zip = new QFile(QApplication::applicationDirPath() + "/GitAddonsManager.zip"); if (!zip->open(QFile::WriteOnly)) { setUpdateStatus(UpdateStatus::UpdateError); @@ -689,3 +689,17 @@ void Control::exportAddonList(const QUrl &path) out << addon->path() << " " << addon->name() << " " << remotes.join(" ") << " " << addon->currentBranch() << Qt::endl; } } + +QString Control::version() const +{ + return m_version; +} + +bool Control::selfUpdates() const +{ +#ifdef GAM_SELF_UPDATE + return true; +#else + return false; +#endif +} diff --git a/control.h b/control.h index a17f89d..aa050f3 100644 --- a/control.h +++ b/control.h @@ -55,6 +55,8 @@ class Control : public QObject QList m_addons; public: + Q_PROPERTY(QString version READ version CONSTANT) + Q_PROPERTY(bool selfUpdates READ selfUpdates CONSTANT) Q_PROPERTY(QList addons READ addons WRITE setAddons NOTIFY addonsChanged) Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged) Q_PROPERTY(int total READ total WRITE setTotal NOTIFY totalChanged) @@ -132,6 +134,10 @@ public: Q_INVOKABLE void exportAddonList(const QUrl &path); + QString version() const; + + bool selfUpdates() const; + private: static Control *m_instance; explicit Control(QObject *parent = nullptr); @@ -161,6 +167,19 @@ private: bool m_useRepoDirectory; + QString m_version = QString("%1 (%2 %3)").arg(GIT_DESCRIBE) +#ifdef GAM_BUILD_NAME + .arg(GAM_BUILD_NAME) +#else + .arg(QSysInfo::productType()) +#endif +#ifdef GAM_BANCH_NAME + .arg(GAM_BANCH_NAME) +#else + .arg(QSysInfo::buildCpuArchitecture()) +#endif + ; + signals: void addonsChanged(QList addons); diff --git a/main.cpp b/main.cpp index 544fd0f..e1c4e61 100644 --- a/main.cpp +++ b/main.cpp @@ -71,18 +71,6 @@ int main(int argc, char *argv[]) } else { Control::instance()->init(); qmlRegisterUncreatableType("GitAddonsManager.engine",1,0,"Addon",""); - engine.rootContext()->setContextProperty("gitVersion", QString("%1 (%2 %3)").arg(GIT_DESCRIBE) -#ifdef GAM_BUILD_NAME - .arg(GAM_BUILD_NAME) -#else - .arg(QSysInfo::productType()) -#endif -#ifdef GAM_BANCH_NAME - .arg(GAM_BANCH_NAME) -#else - .arg(QSysInfo::buildCpuArchitecture()) -#endif - ); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); } if (engine.rootObjects().isEmpty()) diff --git a/main.qml b/main.qml index c460c79..92b818c 100644 --- a/main.qml +++ b/main.qml @@ -154,12 +154,13 @@ ApplicationWindow { } TextArea { readOnly: true - text: gitVersion + text: Engine.version selectByMouse: true onFocusChanged: if (focus) selectAll() } Button { id: updateButton + visible: Engine.selfUpdates contentItem: RowLayout { BusyIndicator { implicitHeight: parent.height