Skip to content

Commit

Permalink
Implement version major.minor.build-stage.revision
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Serrano Polo committed Sep 1, 2016
1 parent 8c2f98a commit c9e11bd
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 81 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ 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_BUILD "91")
SET(VERSION_REVISION "0")
SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}")
IF(VERSION_REVISION)
SET(VERSION "${VERSION}.${VERSION_REVISION}")
ENDIF()

# Override version information for non-base builds
INCLUDE(VersionInfo)
Expand Down
6 changes: 3 additions & 3 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ 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_BUILD}")
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}")
IF(VERSION_REVISION)
SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_BUILD}.${VERSION_REVISION}")
ENDIF()
IF(NOT DEFINED WIN32)
SET(CPACK_STRIP_FILES "bin/${CMAKE_PROJECT_NAME};${PLUGIN_DIR}/*.so")
Expand Down
69 changes: 50 additions & 19 deletions cmake/modules/VersionInfo.cmake
Original file line number Diff line number Diff line change
@@ -1,41 +1,72 @@
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}")
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}")
ENDIF()
IF(TAG_LIST_LENGTH EQUAL 3)
# Non-tagged version
LIST(GET TAG_LIST 1 EXTRA_COMMITS)
STRING(REPLACE "." ";" VERSION_LIST "${FORCE_VERSION}")
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_BUILD)
SET(VERSION_REVISION 0)
IF(VERSION_LENGTH GREATER 3)
LIST(GET VERSION_LIST 3 VERSION_REVISION)
ENDIF()

EXECUTE_PROCESS(
COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE BRANCH_NAME
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_STRIP_TRAILING_WHITESPACE)
STRING(REGEX MATCH "^stable-${VERSION_MAJOR}\\.${VERSION_MINOR}"
STABLE_BRANCH "${BRANCH_NAME}")
IF(STABLE_BRANCH)
# Stable update, FORCE_VERSION=x.x.x.(x + commits)
MATH(EXPR VERSION_REVISION
"${VERSION_REVISION} + ${EXTRA_COMMITS}")
SET(FORCE_VERSION
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}.${VERSION_REVISION}"
)
ELSE()
# Development, FORCE_VERSION=x.x.(x + commits)
MATH(EXPR VERSION_BUILD
"${VERSION_BUILD} + ${EXTRA_COMMITS}")
SET(FORCE_VERSION
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}"
)
ENDIF()
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_BUILD)
IF(VERSION_LENGTH GREATER 3)
LIST(GET VERSION_LIST 3 VERSION_SUFFIX)
LIST(GET VERSION_LIST 3 VERSION_REVISION)
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 +76,15 @@ 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"
"* Build version : ${VERSION_BUILD}\n"
"* Revision version : ${VERSION_REVISION}\n"
"*\n\n"
"Optional Version Usage:\n"
"--------------------------\n"
"* Override version: -DFORCE_VERSION=x.x.x-x\n"
"* Disable hash suffix: -DFORCE_VERSION=internal\n"
"* Override version: -DFORCE_VERSION=x.x.x.x\n"
"* Ignore Git information: -DFORCE_VERSION=internal\n"
)

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

VS_VERSION_INFO VERSIONINFO
FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0
FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_BUILD@,@VERSION_REVISION@
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
Expand Down
19 changes: 10 additions & 9 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, Build, Stage, Revision };

ProjectVersion(QString version, CompareType c = Revision);
ProjectVersion(const char * version, CompareType c = Revision);

int getMajor() const { return m_major; }
int getMinor() const { return m_minor; }
int getRelease() const { return m_release; }
QString getBuild() const { return m_build; }
int getBuild() const { return m_build; }
QString getStage() const { return m_stage; }
int getRevision() const { return m_revision; }
CompareType getCompareType() const { return m_compareType; }
ProjectVersion setCompareType(CompareType compareType) { m_compareType = compareType; return * this; }

Expand All @@ -56,8 +56,9 @@ class ProjectVersion
QString m_version;
int m_major;
int m_minor;
int m_release;
QString m_build;
int m_build;
QString m_stage;
int m_revision;
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::Revision) < "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::Revision ) < openedWith )
{
upgrade();
}
Expand Down
59 changes: 40 additions & 19 deletions src/core/ProjectVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ int parseMinor(QString & version) {



int parseRelease(QString & version) {
return version.section( '.', 2 ).section( '-', 0, 0 ).toInt();
int parseBuild(QString & version) {
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 parseRevision(QString & version) {
return version.section( '.', 3 ).toInt();
}


Expand All @@ -59,8 +66,9 @@ 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_build(parseBuild(m_version)),
m_stage(parseStage(m_version)),
m_revision(parseRevision(m_version)),
m_compareType(c)
{
}
Expand All @@ -72,8 +80,9 @@ ProjectVersion::ProjectVersion(const char* version, CompareType c) :
m_version(QString(version)),
m_major(parseMajor(m_version)),
m_minor(parseMinor(m_version)),
m_release(parseRelease(m_version)),
m_build(parseBuild(m_version)),
m_stage(parseStage(m_version)),
m_revision(parseRevision(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,32 +105,45 @@ int ProjectVersion::compare(const ProjectVersion & a, const ProjectVersion & b,
{
return a.getMinor() - b.getMinor();
}
else if(c == CompareType::Minor)
if(c == Minor)
{
return 0;
}

if(a.getRelease() != b.getRelease())
if(a.getBuild() != b.getBuild())
{
return a.getRelease() - b.getRelease();
return a.getBuild() - b.getBuild();
}
else if(c == CompareType::Release)
if(c == Build)
{
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.getRevision() - b.getRevision();
}


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@"
Loading

0 comments on commit c9e11bd

Please sign in to comment.