From 8a64320214916404c148b1607ce163e1ea3c4d08 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 30 May 2025 19:06:29 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=D0=92=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D0=BE=D1=82=D0=B5=D0=BA=D1=83=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B7=D0=B1=D0=B8=D1=82=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=BE=D0=BC=D1=83=20=D1=81=D0=B8=D0=BC=D0=B2?= =?UTF-8?q?=D0=BE=D0=BB=D1=83=20=D0=BF=D1=80=D0=BE=D0=B1=D0=B5=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/snag/lib/lib.d | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/snag/lib/lib.d b/source/snag/lib/lib.d index 902691d..6db6056 100644 --- a/source/snag/lib/lib.d +++ b/source/snag/lib/lib.d @@ -2,6 +2,8 @@ module snag.lib.lib; import std.regex; import std.process; +import std.algorithm; +import std.string; bool isValidHash(string hash) { auto hashPattern = ctRegex!r"^[a-fA-F0-9]{7}$"; @@ -17,3 +19,9 @@ bool checkGit() { auto result = execute(["which", "git"]); return !result.status; } + +string[] splitByFirstSpace(string line) { + auto spaceIndex = line.indexOf(' '); + return spaceIndex == -1 ? + [line] : [line[0 .. spaceIndex], line[spaceIndex + 1..$]]; +} From 552b635b59cdce96d26645cf16521d8aa6fcb5c7 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 30 May 2025 19:07:09 +0300 Subject: [PATCH 2/7] =?UTF-8?q?-=20=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BF=D1=83=D1=82=D0=B8=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0/?= =?UTF-8?q?=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=D0=B5=20sta?= =?UTF-8?q?tus=20-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D1=81=D0=B5=D0=BA=D1=83=D0=BD?= =?UTF-8?q?=D0=B4=20=D0=BF=D1=80=D0=B8=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/snag/core/core.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/snag/core/core.d b/source/snag/core/core.d index 9917240..156d59a 100644 --- a/source/snag/core/core.d +++ b/source/snag/core/core.d @@ -131,7 +131,7 @@ class Snag { } writeln("The following list of files requires backup:"); result.output.split('\n')[0..$-1].map!(e => - e.strip.split + e.strip.splitByFirstSpace ).each!(e => writefln("\t%s\t/%s", gitStatus(e[0], true), e[1]) ); @@ -250,7 +250,7 @@ class Snag { [ "log", "--all", - "--date=format:%Y.%m.%d %H:%M", + "--date=format:%Y.%m.%d %H:%M:%S", "--pretty=" ~ format ], "Failed to retrieve the list of snapshots" From e43b792df8bd7558bbdd0dace62199a8d2da2f30 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 30 May 2025 19:11:31 +0300 Subject: [PATCH 3/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=B8=D0=B4=D0=B1?= =?UTF-8?q?=D1=8D=D0=BA=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BD=D0=BE=D0=B2=D0=B5=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BF=D1=80=D0=B5=D0=B4=D0=B2=D0=B8=D0=B4=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/app.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/app.d b/source/app.d index a79b3f8..d952688 100644 --- a/source/app.d +++ b/source/app.d @@ -237,7 +237,9 @@ int main(string[] args) return EXIT_FAILURE; } catch (Exception e) { writeln( - "AN UNEXPECTED ERROR HAS OCCURRED! PLEASE REPORT IT TO THE AUTHOR OF THE SNAG!\n\n", + "AN UNEXPECTED ERROR HAS OCCURRED!\n", + "PLEASE REPORT IT TO THE AUTHOR OF THE SNAG: ", + "alexander@zhirov.kz (Alexander Zhirov)\n\n", e ); return EXIT_FAILURE; From ee41d5f96d01794907c390209e1d7163c55896f8 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Mon, 2 Jun 2025 00:26:38 +0300 Subject: [PATCH 4/7] =?UTF-8?q?=D0=A1=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=D1=81=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=83=D1=82=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D0=BD=D0=B0=20=D0=B0=D0=B1?= =?UTF-8?q?=D1=81=D0=BE=D0=BB=D1=8E=D1=82=D0=BD=D1=8B=D0=B9,=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D0=B8=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20=D0=BF=D1=80=D0=BE=D0=B1?= =?UTF-8?q?=D0=BB=D0=B5=D0=BC=D1=83=20=D0=BF=D1=80=D0=B8=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B5=20=D1=81=20=D0=BF=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D0=BC=20=D0=B2=D0=BE=20=D0=B2=D1=80=D0=B5?= =?UTF-8?q?=D0=BC=D1=8F=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F/=D0=B2=D0=BE=D1=81=D1=81=D1=82=D0=B0=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/snag/core/core.d | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/snag/core/core.d b/source/snag/core/core.d index 156d59a..62150fc 100644 --- a/source/snag/core/core.d +++ b/source/snag/core/core.d @@ -158,7 +158,7 @@ class Snag { result = execute(_baseCommand ~ ["rev-parse", "--short", "HEAD"]); if (result.status == 128) { // Если это самый первый коммит после инициализации репозитория - git(["add", "."], "Failed to prepare files for archiving"); + git(["add", _config.project], "Failed to prepare files for archiving"); git(["commit", "-m"] ~ message, "Failed to create a snapshot"); newSnapshot = git( ["rev-parse", "--short", "HEAD"], @@ -197,7 +197,7 @@ class Snag { "Failed to create a branch from the current state" ); git( - ["add", "."], + ["add", _config.project], "Failed to prepare files for archiving" ); git( @@ -211,7 +211,7 @@ class Snag { } else { // Если коммит является посленим в ветке git( - ["add", "."], + ["add", _config.project], "Failed to prepare files for archiving" ); git( @@ -273,7 +273,7 @@ class Snag { ); if (result.output.length) { git( - ["restore", "."], + ["restore", _config.project], "Failed to reset file changes state" ); git( @@ -406,7 +406,7 @@ class Snag { ); // Создание нового снимка на основе состояния файлов из распакованного архива - result = execute(customCommand ~ ["add", "."]); + result = execute(customCommand ~ ["add", tempDirectory]); result.status && throw new SnagException( "Failed to prepare files for archiving:\n" @@ -427,7 +427,7 @@ class Snag { // Сброс состояния файлов git( - ["restore", "."], + ["restore", _config.project], "Failed to reset file changes state" ); git( From 80ace62abffb0d4e48b275647fa13ee522260863 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Mon, 2 Jun 2025 00:59:27 +0300 Subject: [PATCH 5/7] =?UTF-8?q?=D0=A3=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=20?= =?UTF-8?q?=D1=8F=D0=B2=D0=BD=D1=8B=D0=B9=20=D0=BF=D1=83=D1=82=D1=8C=20?= =?UTF-8?q?=D0=BA=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B5=D0=B9=20=D0=B4?= =?UTF-8?q?=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=8B=20git,=20=D1=82=D0=B0=D0=BA=20=D0=BA=D0=B0?= =?UTF-8?q?=D0=BA=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=20snag=20=D0=B8=D0=B7?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=87=D0=B5=D0=B9=20=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=B8=20=D0=BD=D0=B5=20=D0=B2=D1=8B=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D1=8F=D0=BB=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D1=8B=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=20=D1=81=D1=82=D0=B0=D1=80=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=D1=85=20git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/snag/core/core.d | 8 ++++---- source/snag/core/rules.d | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/snag/core/core.d b/source/snag/core/core.d index 62150fc..7f5f9a1 100644 --- a/source/snag/core/core.d +++ b/source/snag/core/core.d @@ -22,8 +22,8 @@ class Snag { this(SnagConfig config) { _baseCommand = format( - "git --git-dir=%s --work-tree=%s", - config.git, config.project + "git -C %s --git-dir=%s --work-tree=%s", + config.project, config.git, config.project ).split(); _config = config; @@ -381,8 +381,8 @@ class Snag { // Выполнение git команд относительно распакованного архива string[] customCommand = format( - "git --git-dir=%s --work-tree=%s", - _config.git, tempDirectory + "git -C %s --git-dir=%s --work-tree=%s", + tempDirectory, _config.git, tempDirectory ).split(); // Необходимо проверить, что текущее состояние файлов не идентично файлам распакованного архива diff --git a/source/snag/core/rules.d b/source/snag/core/rules.d index d8a2c9c..85fca40 100644 --- a/source/snag/core/rules.d +++ b/source/snag/core/rules.d @@ -75,8 +75,8 @@ class SnagRules { _gitignoreBak = _gitignore ~ ".bak"; _baseCommand = format( - "git --git-dir=%s --work-tree=%s", - config.git, config.project + "git -C %s --git-dir=%s --work-tree=%s", + config.project, config.git, config.project ).split(); generate(); From 4474cc5b7c22df23c724275b21df5d143ee37154 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Mon, 2 Jun 2025 01:04:07 +0300 Subject: [PATCH 6/7] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B3?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D0=BC=D1=8B=20=D0=BF=D1=80=D0=B8=20=D1=81?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=BA=D0=B5=20=D0=B2=20Cmake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/snag/version_.d.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/snag/version_.d.in b/source/snag/version_.d.in index 9a8338d..dc97913 100644 --- a/source/snag/version_.d.in +++ b/source/snag/version_.d.in @@ -1,3 +1,3 @@ module snag.version_; -enum snagVersion = "${PROJECT_VERSION_DISPLAY}"; +enum snagVersion = "${PROJECT_VERSION_DISPLAY}${PROJECT_VERSION_SUFFIX}"; From d58ab81fd83b0f052759855014d74d5e6c3734f3 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Mon, 2 Jun 2025 11:08:50 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=86=D0=B5=D1=81=D1=81=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D1=8B=20?= =?UTF-8?q?=D0=B8=D0=B7=20=D0=B8=D1=81=D1=85=D0=BE=D0=B4=D0=BD=D0=B3=D0=BE?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20=D0=BF=D1=80=D0=B8=20=D1=81?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=BA=D0=B5=20=D0=B2=20=D0=BF=D0=B0=D0=BA?= =?UTF-8?q?=D0=B5=D1=82:=20-=20=D0=9A=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20source/snag/version=5F.d=20=D0=B2=20?= =?UTF-8?q?source/snag/version=5F.d.bak=20=D0=B8=20=D0=BA=D0=B0=D0=B6?= =?UTF-8?q?=D0=B4=D1=8B=D0=B9=20=D1=80=D0=B0=D0=B7=20=D0=B2=D0=BE=D1=81?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D0=B0=D0=B2=D0=BB=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20=D0=BE=D1=80=D0=B8=D0=B3=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B5=20?= =?UTF-8?q?=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20CMake=20-=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=B7=D0=BE=D1=80=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20hash=20=D0=B2=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D0=BE=D0=BD=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=BE=20=D1=84=D0=BB=D0=B0=D0=B3=D1=83=20?= =?UTF-8?q?GIT=5FHASH=5FVERSION?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 17 +++++++---------- cmake/snag_git.cmake | 34 +++++++++++++++------------------- cmake/snag_version.cmake | 28 ++++++++++++++++++++++++++++ debian.md | 2 +- debian/rules | 2 +- source/snag/version_.d.in | 2 +- 6 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 cmake/snag_version.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 14f8b2f..2303b63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,15 @@ cmake_minimum_required(VERSION 3.14) project(snag) -set(PROJECT_VERSION_MAJOR 0) -set(PROJECT_VERSION_MINOR 1) -set(PROJECT_VERSION_PATCH 0) -string(TIMESTAMP PROJECT_VERSION_BUILD "%y%j.%H%M") - list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") -include(snag_git) +include(snag_version) +string(TIMESTAMP PROJECT_VERSION_BUILD "%y%j.%H%M") +if(GIT_HASH_VERSION) + message(STATUS "GIT_HASH_VERSION is set") + include(snag_git) +endif() include(snag_platforms) -set(PROJECT_VERSION_SUFFIX "-${GIT_VERSION_SUFFIX}") -# Overwrite suffix for Release or Release Candidate builds -set(PROJECT_VERSION_SUFFIX "-alpha.1") set(CMAKE_BUILD_TYPE "Release") if(CMAKE_BUILD_TYPE) set(BUILD_TYPE ${CMAKE_BUILD_TYPE}) @@ -27,7 +24,7 @@ message(STATUS "PROJECT_VERSION_DISPLAY: ${PROJECT_VERSION_DISPLAY}") message(STATUS "") # Deb package -set(DEB_PACKAGE_VERSION "${PROJECT_VERSION_DISPLAY}${PROJECT_VERSION_SUFFIX}") +set(DEB_PACKAGE_VERSION "${PROJECT_VERSION_DISPLAY}${PROJECT_VERSION_SUFFIX}${GIT_VERSION_SUFFIX}") if(PROJECT_VERSION_CODENAME) set(DEB_PACKAGE_VERSION "${DEB_PACKAGE_VERSION}-${PROJECT_VERSION_CODENAME}") endif() diff --git a/cmake/snag_git.cmake b/cmake/snag_git.cmake index dee20ed..fe97527 100644 --- a/cmake/snag_git.cmake +++ b/cmake/snag_git.cmake @@ -1,24 +1,20 @@ cmake_minimum_required(VERSION 3.6) -if(DEFINED ENV{CI_COMMIT_BRANCH}) - string(REGEX REPLACE ".*/" "" GIT_BRANCH $ENV{CI_COMMIT_BRANCH}) - string(REPLACE "_" "-" GIT_BRANCH ${GIT_BRANCH}) - if(NOT GIT_BRANCH STREQUAL "stable") - set(GIT_VERSION_SUFFIX "${GIT_BRANCH}-") +find_package(Git) + +if(GIT_FOUND) + # Получаем короткий хэш текущего коммита + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_SHORT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + # Проверяем, успешно ли получен хэш + if(GIT_SHORT_HASH) + message(STATUS "Git short hash: ${GIT_SHORT_HASH}") + set(GIT_VERSION_SUFFIX "-${GIT_SHORT_HASH}") else() - set(GIT_VERSION_SUFFIX "") + message(WARNING "Failed to retrieve Git short hash") endif() -else() - set(GIT_BRANCH "dev") - set(GIT_VERSION_SUFFIX "${GIT_BRANCH}-") endif() - -if(DEFINED ENV{CI_COMMIT_SHORT_SHA}) - set(GIT_TAG $ENV{CI_COMMIT_SHORT_SHA}) -else() - set(GIT_TAG "0000000") -endif() - -set(GIT_VERSION_SUFFIX "${GIT_VERSION_SUFFIX}${GIT_TAG}") -MESSAGE(STATUS "GIT_VERSION_SUFFIX: ${GIT_VERSION_SUFFIX}") -MESSAGE(STATUS "") diff --git a/cmake/snag_version.cmake b/cmake/snag_version.cmake new file mode 100644 index 0000000..e5d7c23 --- /dev/null +++ b/cmake/snag_version.cmake @@ -0,0 +1,28 @@ +cmake_minimum_required (VERSION 3.6) + +# Сохраняем копию файла с версией программы и каждый раз обновляем при конфигуре через Cmake +if(EXISTS "${CMAKE_SOURCE_DIR}/source/snag/version_.d.bak") + configure_file( + "${CMAKE_SOURCE_DIR}/source/snag/version_.d.bak" + "${CMAKE_SOURCE_DIR}/source/snag/version_.d" + COPYONLY + ) +else() + configure_file( + "${CMAKE_SOURCE_DIR}/source/snag/version_.d" + "${CMAKE_SOURCE_DIR}/source/snag/version_.d.bak" + COPYONLY + ) +endif() + +# Чтение файла version_.d +file(READ "${CMAKE_SOURCE_DIR}/source/snag/version_.d" VERSION_FILE_CONTENT) + +# Извлечение строки версии (например, "0.1.0-alpha.1") +string(REGEX MATCH "snagVersion = \"([0-9]+)\\.([0-9]+)\\.([0-9]+)([^\"]*)\"" _ ${VERSION_FILE_CONTENT}) + +# Установка переменных для мажорной, минорной, патч-версии и суффикса +set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1}) +set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2}) +set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3}) +set(PROJECT_VERSION_SUFFIX ${CMAKE_MATCH_4}) diff --git a/debian.md b/debian.md index 8f287aa..1cb700c 100644 --- a/debian.md +++ b/debian.md @@ -1,6 +1,6 @@ # Сборка из под Debian ``` -cmake . +cmake . -DGIT_HASH_VERSION=ON dpkg-buildpackage -us -uc -nc ``` diff --git a/debian/rules b/debian/rules index 1da37a9..0f12aca 100755 --- a/debian/rules +++ b/debian/rules @@ -8,7 +8,7 @@ DEST_DIR = $(DEBIAN_DIR)/snag dh $@ $(BUILD_SYSTEM) override_dh_auto_configure: - cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr + cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr -DGIT_HASH_VERSION=ON override_dh_auto_build: cmake --build build diff --git a/source/snag/version_.d.in b/source/snag/version_.d.in index dc97913..9005846 100644 --- a/source/snag/version_.d.in +++ b/source/snag/version_.d.in @@ -1,3 +1,3 @@ module snag.version_; -enum snagVersion = "${PROJECT_VERSION_DISPLAY}${PROJECT_VERSION_SUFFIX}"; +enum snagVersion = "${PROJECT_VERSION_DISPLAY}${PROJECT_VERSION_SUFFIX}${GIT_VERSION_SUFFIX}";