From 5eb0ae2d7576a12e7a2cd16e4bae7baeeee41c83 Mon Sep 17 00:00:00 2001 From: Javier Serrano Polo Date: Sat, 10 Sep 2016 02:27:59 +0000 Subject: [PATCH] Implement version major.minor.release-stage.build (#3011) --- CMakeLists.txt | 18 ++++++---- cmake/CMakeLists.txt | 11 +++--- cmake/modules/VersionInfo.cmake | 52 ++++++++++++++++++--------- cmake/nsis/lmms.rc.in | 1 - include/ProjectVersion.h | 15 ++++---- src/core/ConfigManager.cpp | 4 +-- src/core/DataFile.cpp | 14 ++++---- src/core/ProjectVersion.cpp | 51 ++++++++++++++++++-------- src/lmmsversion.h.in | 4 --- tests/src/core/ProjectVersionTest.cpp | 25 ++++++------- 10 files changed, 120 insertions(+), 75 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8524b4cbf5e..f4dbc80f4d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,13 +31,17 @@ SET(PROJECT_EMAIL "lmms-devel@lists.sourceforge.net") SET(PROJECT_DESCRIPTION "${PROJECT_NAME_UCASE} - Free music production software") SET(PROJECT_COPYRIGHT "2008-${PROJECT_YEAR} ${PROJECT_AUTHOR}") SET(VERSION_MAJOR "1") -SET(VERSION_MINOR "1") -SET(VERSION_PATCH "91") -#SET(VERSION_SUFFIX "") -SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") -IF(VERSION_SUFFIX) - SET(VERSION "${VERSION}-${VERSION_SUFFIX}") -ENDIF(VERSION_SUFFIX) +SET(VERSION_MINOR "2") +SET(VERSION_RELEASE "0") +SET(VERSION_STAGE "rc2") +SET(VERSION_BUILD "0") +SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE}") +IF(VERSION_STAGE) + SET(VERSION "${VERSION}-${VERSION_STAGE}") +ENDIF() +IF(VERSION_BUILD) + SET(VERSION "${VERSION}.${VERSION_BUILD}") +ENDIF() # Override version information for non-base builds INCLUDE(VersionInfo) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1a3a1ec3da8..b27dec91e0f 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -4,13 +4,16 @@ SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt") SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}") SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}") -SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}") +SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_RELEASE}") +IF(VERSION_STAGE) + SET(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}-${VERSION_STAGE}") +ENDIF() +IF(VERSION_BUILD) + SET(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH}.${VERSION_BUILD}") +ENDIF() SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_UCASE}") SET(CPACK_SOURCE_GENERATOR "TBZ2") SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${VERSION}") -IF(VERSION_SUFFIX) - SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}-${VERSION_SUFFIX}") -ENDIF() IF(NOT DEFINED WIN32) SET(CPACK_STRIP_FILES "bin/${CMAKE_PROJECT_NAME};${PLUGIN_DIR}/*.so") SET(CPACK_PACKAGE_EXECUTABLES "${CMAKE_PROJECT_NAME}" "${PROJECT_NAME_UCASE} binary") diff --git a/cmake/modules/VersionInfo.cmake b/cmake/modules/VersionInfo.cmake index 8b449a3be07..cf6932cbbba 100644 --- a/cmake/modules/VersionInfo.cmake +++ b/cmake/modules/VersionInfo.cmake @@ -1,25 +1,29 @@ FIND_PACKAGE(Git) IF(GIT_FOUND AND NOT FORCE_VERSION) - # Look for git tag information (e.g. Stable: "v1.0.0", Non-stable: "v1.0.0-123-a1b2c3d4") + # Look for git tag information (e.g. Tagged: "v1.0.0", Non-tagged: "v1.0.0-123-a1b2c3d") EXECUTE_PROCESS( COMMAND "${GIT_EXECUTABLE}" describe --tags --match v[0-9].[0-9].[0-9]* OUTPUT_VARIABLE GIT_TAG WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - TIMEOUT 1 + TIMEOUT 10 OUTPUT_STRIP_TRAILING_WHITESPACE) STRING(REPLACE "-" ";" TAG_LIST "${GIT_TAG}") LIST(LENGTH TAG_LIST TAG_LIST_LENGTH) - IF(TAG_LIST_LENGTH EQUAL 1) - # Stable build, FORCE_VERSION=x.x.x + IF(TAG_LIST_LENGTH GREATER 0) LIST(GET TAG_LIST 0 FORCE_VERSION) STRING(REPLACE "v" "" FORCE_VERSION "${FORCE_VERSION}") + ENDIF() + IF(TAG_LIST_LENGTH EQUAL 2) + LIST(GET TAG_LIST 1 VERSION_STAGE) + SET(FORCE_VERSION "${FORCE_VERSION}-${VERSION_STAGE}") ELSEIF(TAG_LIST_LENGTH EQUAL 3) - # Non-stable build, FORCE_VERSION=x.x.x-hash - LIST(GET TAG_LIST 0 FORCE_VERSION) - LIST(GET TAG_LIST 2 COMMIT_HASH) - STRING(REPLACE "v" "" FORCE_VERSION "${FORCE_VERSION}") - STRING(REPLACE "g" "" COMMIT_HASH "${COMMIT_HASH}") - SET(FORCE_VERSION "${FORCE_VERSION}-${COMMIT_HASH}") + LIST(GET TAG_LIST 1 EXTRA_COMMITS) + SET(FORCE_VERSION "${FORCE_VERSION}.${EXTRA_COMMITS}") + ELSEIF(TAG_LIST_LENGTH EQUAL 4) + LIST(GET TAG_LIST 1 VERSION_STAGE) + LIST(GET TAG_LIST 2 EXTRA_COMMITS) + SET(FORCE_VERSION + "${FORCE_VERSION}-${VERSION_STAGE}.${EXTRA_COMMITS}") ENDIF() ENDIF() @@ -27,15 +31,28 @@ IF(FORCE_VERSION STREQUAL "internal") # Use release info from /CMakeLists.txt ELSEIF(FORCE_VERSION) STRING(REPLACE "." ";" VERSION_LIST "${FORCE_VERSION}") - STRING(REPLACE "-" ";" VERSION_LIST "${VERSION_LIST}") LIST(LENGTH VERSION_LIST VERSION_LENGTH) LIST(GET VERSION_LIST 0 VERSION_MAJOR) LIST(GET VERSION_LIST 1 VERSION_MINOR) - LIST(GET VERSION_LIST 2 VERSION_PATCH) + LIST(GET VERSION_LIST 2 VERSION_RELEASE) + SET(VERSION_STAGE "") + SET(VERSION_BUILD 0) IF(VERSION_LENGTH GREATER 3) - LIST(GET VERSION_LIST 3 VERSION_SUFFIX) + LIST(GET VERSION_LIST 3 VERSION_BUILD) ENDIF() + + STRING(REPLACE "-" ";" VERSION_LIST "${VERSION_RELEASE}") + LIST(LENGTH VERSION_LIST VERSION_LENGTH) + IF(VERSION_LENGTH GREATER 1) + LIST(GET VERSION_LIST 0 VERSION_RELEASE) + LIST(GET VERSION_LIST 1 VERSION_STAGE) + ENDIF() + SET(VERSION "${FORCE_VERSION}") +ELSEIF(GIT_FOUND) + MESSAGE( +"Could not get project version. Using release info from /CMakeLists.txt" + ) ELSE() MESSAGE("Git not found. Using release info from /CMakeLists.txt") ENDIF() @@ -45,15 +62,16 @@ ENDIF() MESSAGE("\n" "Configuring ${PROJECT_NAME_UCASE}\n" "--------------------------\n" - "* Build version : ${VERSION}\n" + "* Project version : ${VERSION}\n" "* Major version : ${VERSION_MAJOR}\n" "* Minor version : ${VERSION_MINOR}\n" - "* Patch version : ${VERSION_PATCH}\n" - "* Suffix version : ${VERSION_SUFFIX}\n" + "* Release version : ${VERSION_RELEASE}\n" + "* Stage version : ${VERSION_STAGE}\n" + "* Build version : ${VERSION_BUILD}\n" "*\n\n" "Optional Version Usage:\n" "--------------------------\n" "* Override version: -DFORCE_VERSION=x.x.x-x\n" - "* Disable hash suffix: -DFORCE_VERSION=internal\n" + "* Ignore Git information: -DFORCE_VERSION=internal\n" ) diff --git a/cmake/nsis/lmms.rc.in b/cmake/nsis/lmms.rc.in index 7b6f6f79b82..f153ee2356a 100644 --- a/cmake/nsis/lmms.rc.in +++ b/cmake/nsis/lmms.rc.in @@ -2,7 +2,6 @@ lmmsicon ICON cmake/nsis/lmms.ico #include VS_VERSION_INFO VERSIONINFO - FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEOS VOS_NT_WINDOWS32 FILETYPE VFT_APP diff --git a/include/ProjectVersion.h b/include/ProjectVersion.h index 545b916687f..37d8201c769 100644 --- a/include/ProjectVersion.h +++ b/include/ProjectVersion.h @@ -29,9 +29,6 @@ #include -enum CompareType { Major, Minor, Release, Build }; - - /*! \brief Version number parsing and comparison * * Parses and compares version information. i.e. "1.0.3" < "1.0.10" @@ -39,13 +36,16 @@ enum CompareType { Major, Minor, Release, Build }; class ProjectVersion { public: - ProjectVersion(QString version, CompareType c = CompareType::Build); - ProjectVersion(const char * version, CompareType c = CompareType::Build); + enum CompareType { Major, Minor, Release, Stage, Build }; + + ProjectVersion(QString version, CompareType c = Build); + ProjectVersion(const char * version, CompareType c = Build); int getMajor() const { return m_major; } int getMinor() const { return m_minor; } int getRelease() const { return m_release; } - QString getBuild() const { return m_build; } + QString getStage() const { return m_stage; } + int getBuild() const { return m_build; } CompareType getCompareType() const { return m_compareType; } ProjectVersion setCompareType(CompareType compareType) { m_compareType = compareType; return * this; } @@ -57,7 +57,8 @@ class ProjectVersion int m_major; int m_minor; int m_release; - QString m_build; + QString m_stage; + int m_build; CompareType m_compareType; } ; diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index 0e937bd5bf2..cbedf4b05d4 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -147,13 +147,13 @@ void ConfigManager::upgrade() ProjectVersion createdWith = m_version; - if ( createdWith.setCompareType(Build) < "1.1.90" ) + if ( createdWith.setCompareType(ProjectVersion::Build) < "1.1.90" ) { upgrade_1_1_90(); } // Don't use old themes as they break the UI (i.e. 0.4 != 1.0, etc) - if ( createdWith.setCompareType(Minor) != LMMS_VERSION ) + if ( createdWith.setCompareType(ProjectVersion::Minor) != LMMS_VERSION ) { m_artworkDir = defaultArtworkDir(); } diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index 8ac8b58f9a5..89b6981ab79 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -939,15 +939,15 @@ void DataFile::upgrade() { upgrade_0_4_0_rc2(); } - if( version < ProjectVersion("1.0.99", CompareType::Release) ) + if( version < "1.0.99-0" ) { upgrade_1_0_99(); } - if( version < ProjectVersion("1.1.0", CompareType::Release) ) + if( version < "1.1.0-0" ) { upgrade_1_1_0(); } - if( version < ProjectVersion("1.1.91", CompareType::Release) ) + if( version < "1.1.91-0" ) { upgrade_1_1_91(); } @@ -1018,12 +1018,13 @@ void DataFile::loadData( const QByteArray & _data, const QString & _sourceFile ) { // compareType defaults to Build,so it doesn't have to be set here ProjectVersion createdWith = root.attribute( "creatorversion" ); - ProjectVersion openedWith = LMMS_VERSION;; + ProjectVersion openedWith = LMMS_VERSION; if ( createdWith != openedWith ) { // only one compareType needs to be set, and we can compare on one line because setCompareType returns ProjectVersion - if ( createdWith.setCompareType(Minor) != openedWith) + if( createdWith.setCompareType( ProjectVersion::Minor ) + != openedWith ) { if( gui != nullptr && root.attribute( "type" ) == "song" ) { @@ -1045,7 +1046,8 @@ void DataFile::loadData( const QByteArray & _data, const QString & _sourceFile ) } // the upgrade needs to happen after the warning as it updates the project version. - if( createdWith.setCompareType(Build) < openedWith ) + if( createdWith.setCompareType( ProjectVersion::Build ) + < openedWith ) { upgrade(); } diff --git a/src/core/ProjectVersion.cpp b/src/core/ProjectVersion.cpp index 045368343e7..18bb98a2d24 100644 --- a/src/core/ProjectVersion.cpp +++ b/src/core/ProjectVersion.cpp @@ -42,14 +42,21 @@ int parseMinor(QString & version) { int parseRelease(QString & version) { - return version.section( '.', 2 ).section( '-', 0, 0 ).toInt(); + return version.section( '.', 2, 2 ).section( '-', 0, 0 ).toInt(); } -QString parseBuild(QString & version) { - return version.section( '.', 2 ).section( '-', 1 ); +QString parseStage(QString & version) { + return version.section( '.', 2, 2 ).section( '-', 1 ); +} + + + + +int parseBuild(QString & version) { + return version.section( '.', 3 ).toInt(); } @@ -59,7 +66,8 @@ ProjectVersion::ProjectVersion(QString version, CompareType c) : m_version(version), m_major(parseMajor(m_version)), m_minor(parseMinor(m_version)), - m_release(parseRelease(m_version)) , + m_release(parseRelease(m_version)), + m_stage(parseStage(m_version)), m_build(parseBuild(m_version)), m_compareType(c) { @@ -73,6 +81,7 @@ ProjectVersion::ProjectVersion(const char* version, CompareType c) : m_major(parseMajor(m_version)), m_minor(parseMinor(m_version)), m_release(parseRelease(m_version)), + m_stage(parseStage(m_version)), m_build(parseBuild(m_version)), m_compareType(c) { @@ -87,8 +96,7 @@ int ProjectVersion::compare(const ProjectVersion & a, const ProjectVersion & b, { return a.getMajor() - b.getMajor(); } - - else if(c == CompareType::Major) + if(c == Major) { return 0; } @@ -97,7 +105,7 @@ int ProjectVersion::compare(const ProjectVersion & a, const ProjectVersion & b, { return a.getMinor() - b.getMinor(); } - else if(c == CompareType::Minor) + if(c == Minor) { return 0; } @@ -106,23 +114,36 @@ int ProjectVersion::compare(const ProjectVersion & a, const ProjectVersion & b, { return a.getRelease() - b.getRelease(); } - else if(c == CompareType::Release) + if(c == Release) { return 0; } - // make sure 0.x.y > 0.x.y-alpha - if(a.getBuild().isEmpty()) + if(!(a.getStage().isEmpty() && b.getStage().isEmpty())) { - return 1; + // make sure 0.x.y > 0.x.y-alpha + if(a.getStage().isEmpty()) + { + return 1; + } + if(b.getStage().isEmpty()) + { + return -1; + } + + // 0.x.y-beta > 0.x.y-alpha + int cmp = QString::compare(a.getStage(), b.getStage()); + if(cmp) + { + return cmp; + } } - if(b.getBuild().isEmpty()) + if(c == Stage) { - return -1; + return 0; } - // 0.x.y-beta > 0.x.y-alpha - return QString::compare(a.getBuild(), b.getBuild()); + return a.getBuild() - b.getBuild(); } diff --git a/src/lmmsversion.h.in b/src/lmmsversion.h.in index 4f575d15421..dc7ae84d050 100644 --- a/src/lmmsversion.h.in +++ b/src/lmmsversion.h.in @@ -1,6 +1,2 @@ -#define LMMS_VERSION_MAJOR @VERSION_MAJOR@ -#define LMMS_VERSION_MINOR @VERSION_MINOR@ -#define LMMS_VERSION_PATCH @VERSION_PATCH@ -#define LMMS_VERSION_SUFFIX "@VERSION_SUFFIX@" #define LMMS_VERSION "@VERSION@" #define LMMS_PROJECT_COPYRIGHT "@PROJECT_COPYRIGHT@" diff --git a/tests/src/core/ProjectVersionTest.cpp b/tests/src/core/ProjectVersionTest.cpp index b27b1cc46f6..879f68a7fd4 100644 --- a/tests/src/core/ProjectVersionTest.cpp +++ b/tests/src/core/ProjectVersionTest.cpp @@ -30,18 +30,19 @@ class ProjectVersionTest : QTestSuite { Q_OBJECT private slots: - void ProjectVersionComparaisonTests() - { - QVERIFY(ProjectVersion("1.1.0", CompareType::Minor) > "1.0.3"); - QVERIFY(ProjectVersion("1.1.0", CompareType::Major) < "2.1.0"); - QVERIFY(ProjectVersion("1.1.0", CompareType::Release) > "0.2.1"); - QVERIFY(ProjectVersion("1.1.4", CompareType::Release) < "1.1.10"); - QVERIFY(ProjectVersion("1.1.0", CompareType::Minor) == "1.1.5"); - QVERIFY( ! ( ProjectVersion("3.1.0", CompareType::Minor) < "2.2.5" ) ); - QVERIFY( ! ( ProjectVersion("2.5.0", CompareType::Release) < "2.2.5" ) ); - QVERIFY(ProjectVersion("1.1.0") > "1.1.0-alpha"); - QVERIFY(ProjectVersion("1.1.0-alpha") < "1.1.0-beta"); - } + void ProjectVersionComparisonTests() + { + QVERIFY(ProjectVersion("1.1.0", ProjectVersion::Minor) > "1.0.3"); + QVERIFY(ProjectVersion("1.1.0", ProjectVersion::Major) < "2.1.0"); + QVERIFY(ProjectVersion("1.1.0", ProjectVersion::Release) > "0.2.1"); + QVERIFY(ProjectVersion("1.1.4", ProjectVersion::Release) < "1.1.10"); + QVERIFY(ProjectVersion("1.1.0", ProjectVersion::Minor) == "1.1.5"); + QVERIFY( ! ( ProjectVersion("3.1.0", ProjectVersion::Minor) < "2.2.5" ) ); + QVERIFY( ! ( ProjectVersion("2.5.0", ProjectVersion::Release) < "2.2.5" ) ); + QVERIFY(ProjectVersion("1.1.0") > "1.1.0-alpha"); + QVERIFY(ProjectVersion("1.1.0-alpha") < "1.1.0-beta"); + QVERIFY(ProjectVersion("1.2.0-rc1") < "1.2.0-rc2"); + } } ProjectVersionTests; #include "ProjectVersionTest.moc"