Extract VERSION to avoid duplication

This commit is contained in:
luisangelsm
2026-03-30 17:19:40 +02:00
parent 74aebffd9b
commit 79a8acbd42
9 changed files with 46 additions and 44 deletions

View File

@ -153,7 +153,7 @@ jobs:
env: env:
MACOSX_DEPLOYMENT_TARGET: "11" MACOSX_DEPLOYMENT_TARGET: "11"
run: | run: |
VERSION="$(cat common/yacreader_global.h | grep '#define VERSION "' | tr -d '#define VERSION' | tr -d '"' )" VERSION="$(tr -d '\r\n' < VERSION)"
SKIP_CODESIGN="${{ env.IS_FORK }}" SKIP_CODESIGN="${{ env.IS_FORK }}"
SKIP_CODESIGN=$(echo "$SKIP_CODESIGN" | tr '[:upper:]' '[:lower:]') SKIP_CODESIGN=$(echo "$SKIP_CODESIGN" | tr '[:upper:]' '[:lower:]')
./compileOSX.sh $VERSION ${{ needs.initialization.outputs.build_number }} $SKIP_CODESIGN Qt6 universal ./compileOSX.sh $VERSION ${{ needs.initialization.outputs.build_number }} $SKIP_CODESIGN Qt6 universal
@ -510,7 +510,7 @@ jobs:
- name: Get version - name: Get version
id: version id: version
run: | run: |
VERSION="$(cat common/yacreader_global.h | grep '#define VERSION "' | tr -d '#define VERSION' | tr -d '"' ).${{ needs.initialization.outputs.build_number }}" VERSION="$(tr -d '\r\n' < VERSION).${{ needs.initialization.outputs.build_number }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION" echo "Version: $VERSION"
@ -577,7 +577,7 @@ jobs:
- name: Get version - name: Get version
id: version id: version
run: | run: |
VERSION="$(cat common/yacreader_global.h | grep '#define VERSION "' | tr -d '#define VERSION' | tr -d '"' )" VERSION="$(tr -d '\r\n' < VERSION)"
echo "version=$VERSION" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION" echo "Version: $VERSION"
@ -648,7 +648,7 @@ jobs:
- name: Get version - name: Get version
id: version id: version
run: | run: |
VERSION="$(cat common/yacreader_global.h | grep '#define VERSION "' | tr -d '#define VERSION' | tr -d '"' ).${{ needs.initialization.outputs.build_number }}" VERSION="$(tr -d '\r\n' < VERSION).${{ needs.initialization.outputs.build_number }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION" echo "Version: $VERSION"

View File

@ -1,7 +1,13 @@
cmake_minimum_required(VERSION 3.25...4.3.1) cmake_minimum_required(VERSION 3.25...4.3.1)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" YACREADER_VERSION)
string(STRIP "${YACREADER_VERSION}" YACREADER_VERSION)
if(NOT YACREADER_VERSION MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$")
message(FATAL_ERROR "VERSION must contain a semantic version like x.y.z")
endif()
project(YACReader project(YACReader
VERSION 10.0.0 VERSION ${YACREADER_VERSION}
LANGUAGES C CXX LANGUAGES C CXX
) )

1
VERSION Normal file
View File

@ -0,0 +1 @@
10.0.0

View File

@ -52,12 +52,8 @@ for /r %src_path%\build %%f in (*.qm) do (
copy %src_path%\vc_redist.%ARCH%.exe . copy %src_path%\vc_redist.%ARCH%.exe .
type %src_path%\common\yacreader_global.h | findstr /R /C:"#define VERSION " > tmp set /p VERSION=<%src_path%\VERSION
set /p VERSION= < tmp
set VERSION=%VERSION:#define VERSION "=%
set VERSION=%VERSION:"=%
echo %VERSION% echo %VERSION%
del tmp
echo "iscc start" echo "iscc start"
iscc /DVERSION=%VERSION% /DPLATFORM=%ARCH% /DCOMPRESSED_ARCHIVE_BACKEND=%COMPRESSION% /DBUILD_NUMBER=%BUILD_NUMBER% build_installer_qt6.iss || exit /b iscc /DVERSION=%VERSION% /DPLATFORM=%ARCH% /DCOMPRESSED_ARCHIVE_BACKEND=%COMPRESSION% /DBUILD_NUMBER=%BUILD_NUMBER% build_installer_qt6.iss || exit /b

View File

@ -1,12 +1,23 @@
# Common libraries for YACReader # Common libraries for YACReader
# Fine-grained STATIC targets per concern # Fine-grained STATIC targets per concern
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/version.h
@ONLY
)
# --- yr_global (no GUI, used by all 3 apps) --- # --- yr_global (no GUI, used by all 3 apps) ---
add_library(yr_global STATIC add_library(yr_global STATIC
${CMAKE_CURRENT_BINARY_DIR}/version.h
version.h.in
yacreader_global.h yacreader_global.h
yacreader_global.cpp yacreader_global.cpp
) )
target_include_directories(yr_global PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(yr_global PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(yr_global PUBLIC Qt::Core) target_link_libraries(yr_global PUBLIC Qt::Core)
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
target_compile_definitions(yr_global PRIVATE target_compile_definitions(yr_global PRIVATE
@ -171,6 +182,7 @@ target_link_libraries(rhi_flow_reader PUBLIC
Qt::Gui Qt::Gui
Qt::GuiPrivate Qt::GuiPrivate
Qt::Widgets Qt::Widgets
yr_global
) )
qt_add_shaders(rhi_flow_reader "flow_shaders_reader" qt_add_shaders(rhi_flow_reader "flow_shaders_reader"
BASE rhi/shaders BASE rhi/shaders
@ -194,6 +206,7 @@ target_link_libraries(rhi_flow_library PUBLIC
Qt::Gui Qt::Gui
Qt::GuiPrivate Qt::GuiPrivate
Qt::Widgets Qt::Widgets
yr_global
) )
qt_add_shaders(rhi_flow_library "flow_shaders_library" qt_add_shaders(rhi_flow_library "flow_shaders_library"
BASE rhi/shaders BASE rhi/shaders

View File

@ -6,16 +6,15 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QRegExp>
#include <QStringList>
#include <QTimer> #include <QTimer>
#include <QUrl> #include <QUrl>
#include <QVersionNumber>
#include <QtGlobal> #include <QtGlobal>
#define PREVIOUS_VERSION_TESTING "6.0.0" #define PREVIOUS_VERSION_TESTING "6.0.0"
HttpVersionChecker::HttpVersionChecker() HttpVersionChecker::HttpVersionChecker()
: HttpWorker("https://raw.githubusercontent.com/YACReader/yacreader/master/common/yacreader_global.h", DEFAULT_USER_AGENT) : HttpWorker("https://raw.githubusercontent.com/YACReader/yacreader/master/VERSION", DEFAULT_USER_AGENT)
{ {
connect(this, &HttpVersionChecker::dataReady, this, QOverload<const QByteArray &>::of(&HttpVersionChecker::checkNewVersion)); connect(this, &HttpVersionChecker::dataReady, this, QOverload<const QByteArray &>::of(&HttpVersionChecker::checkNewVersion));
} }
@ -27,39 +26,17 @@ void HttpVersionChecker::checkNewVersion(const QByteArray &data)
bool HttpVersionChecker::checkNewVersion(QString sourceContent) bool HttpVersionChecker::checkNewVersion(QString sourceContent)
{ {
QRegExp rx("#define VERSION \"([0-9]+).([0-9]+).([0-9]+)\"");
bool newVersion = false;
bool sameVersion = true;
// bool currentVersionIsNewer = false;
#ifdef QT_DEBUG #ifdef QT_DEBUG
QString version(PREVIOUS_VERSION_TESTING); const auto currentVersion = QVersionNumber::fromString(PREVIOUS_VERSION_TESTING);
#else #else
QString version(VERSION); const auto currentVersion = QVersionNumber::fromString(QString::fromLatin1(VERSION));
#endif #endif
QStringList sl = version.split("."); const auto latestVersion = QVersionNumber::fromString(sourceContent.trimmed());
if (rx.indexIn(sourceContent) != -1) {
int length = qMin(sl.size(), (rx.cap(4) != "") ? 4 : 3);
for (int i = 0; i < length; i++) {
if (rx.cap(i + 1).toInt() < sl.at(i).toInt()) {
return false;
}
if (rx.cap(i + 1).toInt() > sl.at(i).toInt()) {
newVersion = true;
break;
} else
sameVersion = sameVersion && rx.cap(i + 1).toInt() == sl.at(i).toInt();
}
if (!newVersion && sameVersion) {
if ((sl.size() == 3) && (rx.cap(4) != ""))
newVersion = true;
}
}
if (newVersion == true) { if (!currentVersion.isNull() && !latestVersion.isNull() && QVersionNumber::compare(latestVersion, currentVersion) > 0) {
emit newVersionDetected(); emit newVersionDetected();
return true; return true;
} else { }
return false; return false;
} }
}

6
common/version.h.in Normal file
View File

@ -0,0 +1,6 @@
#ifndef YACREADER_VERSION_H
#define YACREADER_VERSION_H
#define VERSION "@PROJECT_VERSION@"
#endif

View File

@ -9,7 +9,10 @@
class QLibrary; class QLibrary;
#define VERSION "10.0.0" // Compatibility for already released apps that still parse this file for update checks.
// TODO: remove after old releases have migrated away from scraping this header.
// #define VERSION "10.0.0"
#include "version.h"
// Used to check if the database needs to be updated, the version is stored in the database. // Used to check if the database needs to be updated, the version is stored in the database.
// This value is only incremented when the database structure changes. // This value is only incremented when the database structure changes.

View File

@ -1,7 +1,7 @@
#! /bin/bash #! /bin/bash
set -e set -e
VERSION=${1:-"9.9.1"} VERSION=${1:-$(tr -d '\r\n' < VERSION)}
BUILD_NUMBER=${2:-"0"} BUILD_NUMBER=${2:-"0"}