From 6df96f505fd0f70d84b50ad36498c3a4c05a61bc Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 23 Jan 2025 17:12:05 -0500 Subject: [PATCH] Separate version into component parts. This guarantees a consistent version representation and allows the version to be easily represented in other ways. --- doc/lib/pgBackRestDoc/ProjectInfo.pm | 26 +++++++++++++++++++++++--- src/version.h | 7 ++++++- test/test.pl | 17 +++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/doc/lib/pgBackRestDoc/ProjectInfo.pm b/doc/lib/pgBackRestDoc/ProjectInfo.pm index ec4f29890..a43e66a7d 100644 --- a/doc/lib/pgBackRestDoc/ProjectInfo.pm +++ b/doc/lib/pgBackRestDoc/ProjectInfo.pm @@ -26,6 +26,11 @@ push @EXPORT, qw(PROJECT_CONF); # Defines the current version of the BackRest executable. The version number is used to track features but does not affect what # repositories or manifests can be read - that's the job of the format number. #----------------------------------------------------------------------------------------------------------------------------------- +push @EXPORT, qw(PROJECT_VERSION_MAJOR); +push @EXPORT, qw(PROJECT_VERSION_MINOR); +push @EXPORT, qw(PROJECT_VERSION_PATCH); +push @EXPORT, qw(PROJECT_VERSION_SUFFIX); + push @EXPORT, qw(PROJECT_VERSION); # Repository Format Number @@ -46,7 +51,6 @@ my $strProjectInfo = ${new pgBackRestTest::Common::Storage( foreach my $strLine (split("\n", $strProjectInfo)) { - if ($strLine =~ /^#define PROJECT_NAME/) { eval("use constant PROJECT_NAME => " . (split(" ", $strLine))[-1]); @@ -56,9 +60,21 @@ foreach my $strLine (split("\n", $strProjectInfo)) eval("use constant PROJECT_EXE => " . (split(" ", $strLine))[-1]); eval("use constant PROJECT_CONF => " . (split(" ", $strLine))[-1] . " . \'.conf\'"); } - elsif ($strLine =~ /^#define PROJECT_VERSION/) + elsif ($strLine =~ /^#define PROJECT_VERSION_MAJOR/) { - eval("use constant PROJECT_VERSION => " . (split(" ", $strLine))[-1]); + eval("use constant PROJECT_VERSION_MAJOR => \"" . (split(" ", $strLine))[-1] . "\""); + } + elsif ($strLine =~ /^#define PROJECT_VERSION_MINOR/) + { + eval("use constant PROJECT_VERSION_MINOR => " . (split(" ", $strLine))[-1]); + } + elsif ($strLine =~ /^#define PROJECT_VERSION_PATCH/) + { + eval("use constant PROJECT_VERSION_PATCH => " . (split(" ", $strLine))[-1]); + } + elsif ($strLine =~ /^#define PROJECT_VERSION_SUFFIX/) + { + eval("use constant PROJECT_VERSION_SUFFIX => " . (split(" ", $strLine))[-1]); } elsif ($strLine =~ /^#define REPOSITORY_FORMAT/) { @@ -66,4 +82,8 @@ foreach my $strLine (split("\n", $strProjectInfo)) } } +eval( + 'use constant PROJECT_VERSION => "' . PROJECT_VERSION_MAJOR() . '.' . PROJECT_VERSION_MINOR() . '.' . PROJECT_VERSION_PATCH() . + PROJECT_VERSION_SUFFIX() . '"'); + 1; diff --git a/src/version.h b/src/version.h index 1f4d173e1..2e6594f1a 100644 --- a/src/version.h +++ b/src/version.h @@ -31,8 +31,13 @@ will be invalid unless migration functions are written. #define REPOSITORY_FORMAT 5 /*********************************************************************************************************************************** -Software version +Project version components. PROJECT_VERSION is automatically generated from the component parts. ***********************************************************************************************************************************/ +#define PROJECT_VERSION_MAJOR 2 +#define PROJECT_VERSION_MINOR 55 +#define PROJECT_VERSION_PATCH 0 +#define PROJECT_VERSION_SUFFIX "dev" + #define PROJECT_VERSION "2.55.0dev" #endif diff --git a/test/test.pl b/test/test.pl index ad039807a..fe50dedc6 100755 --- a/test/test.pl +++ b/test/test.pl @@ -435,6 +435,23 @@ eval buildPutDiffers($oStorageBackRest, "${strBackRestBase}/meson.build", $strMesonBuildNew); + # Auto-generate version for version.h + #------------------------------------------------------------------------------------------------------------------------------- + my $strVersionCOld = ${$oStorageTest->get("${strBackRestBase}/src/version.h")}; + my $strVersionCNew; + + foreach my $strLine (split("\n", $strVersionCOld)) + { + if ($strLine =~ /^#define PROJECT_VERSION /) + { + $strLine = "#define PROJECT_VERSION" . (' ' x 45) . '"' . PROJECT_VERSION . '"'; + } + + $strVersionCNew .= "${strLine}\n"; + } + + buildPutDiffers($oStorageBackRest, "${strBackRestBase}/src/version.h", $strVersionCNew); + # Start build container if vm is not none #------------------------------------------------------------------------------------------------------------------------------- if ($strVm ne VM_NONE)