Permalink
Browse files

Improve version number handling

The file VERSION.txt describes the version of Aseba.
CMake uses that file to construct the version number of
the package.

That version is also embedded in the `asebacommon` library by
CMake.

`common/consts.h` defines two variables:

* ASEBA_VERSION  : A textual representation of aseba version ("x.y.z")
* ASEBA_REVISION : A textual representation of the git short hash

When releasing a new version of the software, only VERSION.txt
needs to be updated.
  • Loading branch information...
cor3ntin committed Mar 14, 2018
1 parent 91d8a68 commit a822ea6ae853e21e3dea98ceff5dd9fb6a7d802c
View
@@ -89,6 +89,10 @@ if(WIN32)
)
endif()
SET(CPACK_PACKAGE_VERSION_MAJOR "${ASEBA_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${ASEBA_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${ASEBA_VERSION_PATCH}")
include(CPack)
@@ -1,16 +1,3 @@
# This module checks for Git binaries, extracts the revision number, and writes it in version.h
# The user can provide a version number through the USER_BUILD_VERSION variable
# version management
if (USER_BUILD_VERSION)
message(STATUS "User version given: " ${USER_BUILD_VERSION})
file(WRITE ${CMAKE_BINARY_DIR}/version.h "#define ASEBA_BUILD_VERSION \"${USER_BUILD_VERSION}\"\n")
return()
endif (USER_BUILD_VERSION)
##########
# detect git
##########
find_package(Git QUIET)
if (NOT GIT_FOUND)
find_program(GIT_EXECUTABLE git NO_CMAKE_FIND_ROOT_PATH)
@@ -19,42 +6,23 @@ if (NOT GIT_FOUND)
endif (GIT_EXECUTABLE)
endif (NOT GIT_FOUND)
set(GIT_REVISION "")
if (GIT_FOUND)
message(STATUS "Git executable found")
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short --verify HEAD
OUTPUT_VARIABLE GIT_REV
OUTPUT_VARIABLE GIT_REVISION
ERROR_VARIABLE git_rev_error
RESULT_VARIABLE git_rev_result
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${git_rev_result} EQUAL 0)
set(HAS_GIT_REP 1)
endif(${git_rev_result} EQUAL 0)
else (GIT_FOUND)
message(STATUS "Git executable NOT found")
endif (GIT_FOUND)
# react accordingly
if (GIT_FOUND AND HAS_GIT_REP)
message(STATUS "Git repository found")
set(HAS_DYN_VERSION)
# write a file with the GIT_REV define
file(WRITE ${CMAKE_BINARY_DIR}/version.h.txt "#define ASEBA_BUILD_VERSION \"git-${GIT_REV}\"\n")
# write NSIS version file (for Windows build)
file(READ "${PROJECT_SOURCE_DIR}/aseba/common/consts.h" COMMON_CONSTS_H)
string(REGEX MATCH [0-9]+\\.[0-9]+\\.[0-9]+ ASEBA_VERSION ${COMMON_CONSTS_H})
file(WRITE ${CMAKE_BINARY_DIR}/version.nsi "!define VERSION \"${ASEBA_VERSION}-git-${GIT_REV}\"\n")
# copy the file to the final header only if the version changes
# reduces needless rebuilds
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different version.h.txt version.h)
add_custom_target(versionheader ALL DEPENDS ${CMAKE_BINARY_DIR}/version.h)
set_source_files_properties(${CMAKE_BINARY_DIR}/version.h PROPERTIES GENERATED TRUE HEADER_FILE_ONLY TRUE)
return()
endif (GIT_FOUND AND HAS_GIT_REP)
##########
# default
##########
message(STATUS "(svn / git executable not found OR not a svn / git repository) and no user version given, version is unknown.")
file(WRITE ${CMAKE_BINARY_DIR}/version.h "#define ASEBA_BUILD_VERSION \"unknown\"\n")
file(READ "${PROJECT_SOURCE_DIR}/VERSION.txt" VERSION_FILE)
string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" ASEBA_VERSION ${VERSION_FILE})
set(ASEBA_VERSION_MAJOR ${CMAKE_MATCH_1})
set(ASEBA_VERSION_MINOR ${CMAKE_MATCH_2})
set(ASEBA_VERSION_PATCH ${CMAKE_MATCH_3})
View
@@ -0,0 +1,2 @@
#Version of aseba. Must be of the form <MAJOR>.<MINOR>.<PATCH>
1.6.9
@@ -129,7 +129,7 @@ if (QT_QCOLLECTIONGENERATOR_EXECUTABLE)
qt5_add_resources(resfiles ${CMAKE_CURRENT_BINARY_DIR}/asebastudiohelp.qrc)
endif ()
add_executable(asebastudio WIN32 ${studio_SRCS} ${studio_MOCS} ${resfiles} ${CMAKE_BINARY_DIR}/version.h)
add_executable(asebastudio WIN32 ${studio_SRCS} ${studio_MOCS} ${resfiles})
if (HAS_DYN_VERSION)
add_dependencies(asebastudio versionheader)
endif ()
@@ -143,9 +143,9 @@ codesign(asebastudio)
# Thymio VPL standalone
if (ANDROID)
add_library(thymiovpl SHARED ${thymiovpl_SRCS} ${resfiles} ${CMAKE_BINARY_DIR}/version.h)
add_library(thymiovpl SHARED ${thymiovpl_SRCS} ${resfiles})
else ()
add_executable(thymiovpl WIN32 ${thymiovpl_SRCS} ${resfiles} ${CMAKE_BINARY_DIR}/version.h)
add_executable(thymiovpl WIN32 ${thymiovpl_SRCS} ${resfiles})
endif ()
if (HAS_DYN_VERSION)
add_dependencies(thymiovpl versionheader)
@@ -160,8 +160,7 @@ target_link_libraries(thymiovpl asebaqtplugins asebaqtcommon asebacompiler aseba
codesign(thymiovpl)
#renderblocks
add_executable(rendervplblocks ${CMAKE_BINARY_DIR}/version.h)
target_sources(rendervplblocks PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/rendervplblocks.cpp ${resfiles})
add_executable(rendervplblocks ${CMAKE_CURRENT_SOURCE_DIR}/rendervplblocks.cpp ${resfiles})
target_link_libraries(rendervplblocks asebaqtplugins asebaqtcommon asebaqtabout asebacompiler asebacommon ${ADDITIONAL_LIBRARIES} Qt5::Xml Qt5::Svg Qt5::Widgets)
install_qt_app(rendervplblocks)
codesign(rendervplblocks)
@@ -41,9 +41,6 @@
#include <QDesktopServices>
#include <QtConcurrentRun>
#include <QSvgRenderer>
#include <version.h>
#include <iostream>
using std::copy;
@@ -31,8 +31,6 @@
#include <QShortcut>
#include <QDesktopServices>
#include <version.h>
namespace Aseba
{
/** \addtogroup studio */
@@ -192,7 +190,7 @@ namespace Aseba
layout->addWidget(editor, 1);
const QString text = tr("Aseba ver. %0 (build %1/protocol %2); Dashel ver. %3").
arg(ASEBA_VERSION).
arg(ASEBA_BUILD_VERSION).
arg(ASEBA_REVISION).
arg(ASEBA_PROTOCOL_VERSION).
arg(DASHEL_VERSION);
QLabel* label(new QLabel(text));
@@ -4,18 +4,18 @@ if (Qt5Widgets_FOUND AND Qt5Concurrent_FOUND AND Qt5Network_FOUND AND Qt5Xml_FOU
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-Wl,-subsystem,console ${CMAKE_EXE_LINKER_FLAGS}")
endif (WIN32)
set(thymioupgrader_SRCS
ThymioUpgrader.cpp)
qt5_wrap_cpp(thymioupgrader_MOCS
ThymioUpgrader.h
)
qt5_add_resources(resfiles thymioupgrader.qrc)
include_directories (${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
add_executable(thymioupgrader WIN32 ${thymioupgrader_SRCS} ${thymioupgrader_MOCS} ${resfiles} ${CMAKE_BINARY_DIR}/version.h)
add_executable(thymioupgrader WIN32 ${thymioupgrader_SRCS} ${thymioupgrader_MOCS} ${resfiles})
if (HAS_DYN_VERSION)
add_dependencies(thymioupgrader versionheader)
endif (HAS_DYN_VERSION)
@@ -1,16 +1,16 @@
if (Qt5Widgets_FOUND)
set(thymiownetconfig_SRCS
ThymioWNetConfig.cpp)
qt5_wrap_cpp(thymiownetconfig_MOCS
ThymioWNetConfig.h
)
qt5_add_resources(resfiles thymiownetconfig.qrc)
include_directories (${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
add_executable(thymiownetconfig WIN32 ${thymiownetconfig_SRCS} ${thymiownetconfig_MOCS} ${resfiles} ${CMAKE_BINARY_DIR}/version.h)
add_executable(thymiownetconfig WIN32 ${thymiownetconfig_SRCS} ${thymiownetconfig_MOCS} ${resfiles})
if (HAS_DYN_VERSION)
add_dependencies(thymiownetconfig versionheader)
endif (HAS_DYN_VERSION)
@@ -24,6 +24,6 @@ endif ()
if (UNIX)
add_executable(thymiownetconfig-cli thymiownetconfig-cli.c)
target_link_libraries(thymiownetconfig-cli aseba_conf)
target_link_libraries(thymiownetconfig-cli aseba_conf asebacommon)
install(TARGETS thymiownetconfig-cli RUNTIME DESTINATION bin LIBRARY DESTINATION bin)
endif (UNIX)
@@ -1,3 +1,6 @@
configure_file("version.cpp.tpl" "version.cpp")
add_library(asebacommon
utils/FormatableString.cpp
utils/utils.cpp
@@ -6,6 +9,7 @@ add_library(asebacommon
msg/msg.cpp
msg/NodesManager.cpp
msg/TargetDescription.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
)
set_target_properties(asebacommon PROPERTIES VERSION ${LIB_VERSION_STRING})
target_link_libraries(asebacommon PUBLIC aseba_conf dashel)
@@ -21,7 +21,6 @@
#include "../consts.h"
#include "../authors.h"
#include "dashel/dashel.h"
#include <version.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
@@ -202,7 +201,7 @@ namespace Aseba
// libraries tab
const QString welcomeText = tr("The following software are used in Aseba:");
const QString libEntryText = tr("<b><a href=\"%3\">%1</a></b> version %2");
const QString asebaBuildInfo = tr("build version %1, protocol version %2").arg(ASEBA_BUILD_VERSION).arg(ASEBA_PROTOCOL_VERSION);
const QString asebaBuildInfo = tr("build version %1, protocol version %2").arg(ASEBA_REVISION).arg(ASEBA_PROTOCOL_VERSION);
const QString dashelStreamInfo = tr("supported stream types: %1").arg(QString::fromStdString(Dashel::streamTypeRegistry.list()));
const QString liStart = "<li style=\"margin-top:5px; margin-bottom:5px;\">";
const QString libraryText =
View
@@ -25,12 +25,10 @@
*/
/*@{*/
/*! version of Aseba as string */
#define ASEBA_VERSION "1.6.0"
/*! version of Aseba as an int */
#define ASEBA_VERSION_INT 10600
//defined version.cpp, generated by cmake from VERSION.txt
extern const char* ASEBA_VERSION;
//defined version.cpp, generated by cmake from git invokation
extern const char* ASEBA_REVISION;
/*! version of aseba protocol, including bytecodes types and constants */
#define ASEBA_PROTOCOL_VERSION 5
@@ -0,0 +1,2 @@
const char* ASEBA_VERSION = "@ASEBA_VERSION@";
const char* ASEBA_REVISION = "@GIT_REVISION@";
View
@@ -31,7 +31,7 @@ PROJECT_NAME = Aseba
# This could be handy for archiving the generated documentation or
# if some version control system is used.
PROJECT_NUMBER = "1.6.0"
PROJECT_NUMBER =
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
View
@@ -125,13 +125,6 @@ FunctionEnd
!insertmacro CleanShortcuts ""
!insertmacro CleanShortcuts "un."
; Function WriteVersionFile
; LogText "Writing version.txt"
; FileOpen $0 "$INSTDIR\version.txt" w ; Overwrite
; FileWrite $0 "${VERSION}"
; FileClose $0
; FunctionEnd
;Default installation folder
InstallDir "$PROGRAMFILES\AsebaStudio"
@@ -199,8 +192,6 @@ SectionGroup /e "-Aseba" GroupAseba
File "${ASEBA_SOURCE_DIRECTORY}\menu\windows\thymiowebbridge.ico"
File "${ASEBA_SOURCE_DIRECTORY}\menu\windows\scratchblock.ico"
; # Version file (version.txt)
; Call WriteVersionFile
; ${If} $Language == '1036'
; ; French
; File "README.fr.txt"

0 comments on commit a822ea6

Please sign in to comment.