Skip to content

Commit

Permalink
Implement version major.minor.release-stage.build (#3011)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasp00 authored Sep 10, 2016
1 parent eb86e25 commit 5eb0ae2
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 75 deletions.
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
52 changes: 35 additions & 17 deletions cmake/modules/VersionInfo.cmake
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
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()

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()
Expand All @@ -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"
)

1 change: 0 additions & 1 deletion cmake/nsis/lmms.rc.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ lmmsicon ICON cmake/nsis/lmms.ico
#include <windows.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
Expand Down
15 changes: 8 additions & 7 deletions include/ProjectVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@

#include <QtCore/QString>

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"
*/
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; }

Expand All @@ -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;
} ;

Expand Down
4 changes: 2 additions & 2 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
14 changes: 8 additions & 6 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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" )
{
Expand All @@ -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();
}
Expand Down
51 changes: 36 additions & 15 deletions src/core/ProjectVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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();
}


Expand Down
4 changes: 0 additions & 4 deletions src/lmmsversion.h.in
Original file line number Diff line number Diff line change
@@ -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@"
25 changes: 13 additions & 12 deletions tests/src/core/ProjectVersionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

5 comments on commit 5eb0ae2

@tresf
Copy link
Member

@tresf tresf commented on 5eb0ae2 Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasp00 this seems to be affecting the windows package name negatively.

With this commit, I always get lmms-1.2.0-win64.exe as a build version package name, which is incorrect.

@jasp00
Copy link
Member Author

@jasp00 jasp00 commented on 5eb0ae2 Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does CMake report?

Configuring LMMS
--------------------------
* Project version             : 1.2.0-rc2
*   Major version             : 1
*   Minor version             : 2
*   Release version           : 0
*   Stage version             : rc2
*   Build version             : 0

@tresf
Copy link
Member

@tresf tresf commented on 5eb0ae2 Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question...

lmms/lmms :

Configuring LMMS
--------------------------
* Project version             : 1.1.90.459
*   Major version             : 1
*   Minor version             : 1
*   Release version           : 90
*   Stage version             : 
*   Build version             : 459
*

tresf/lmms :

Configuring LMMS
--------------------------
* Project version             : 1.2.0
*   Major version             : 1
*   Minor version             : 2
*   Release version           : 0
*   Stage version             : 
*   Build version             : 0
*

@jasp00
Copy link
Member Author

@jasp00 jasp00 commented on 5eb0ae2 Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using version 1.2.0. Either you are forcing the version or Git reports that for some reason. What is the output of:
git describe --tags --match v[0-9].[0-9].[0-9]* ?

@tresf
Copy link
Member

@tresf tresf commented on 5eb0ae2 Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah perhaps it's an anomaly with my branch. I'll test later on and report back but AFAIK, it should use the commit counter unless the current commit is THE tagged release, which isn't the case on my branch.

Please sign in to comment.