From cbfb7e6979a9f22f06520b427d12e5b9afff48e3 Mon Sep 17 00:00:00 2001 From: Rogier Date: Wed, 3 Aug 2016 08:07:27 +0200 Subject: [PATCH] Make cpack fail if the current git commit id does not match the one at cmake time. cpack would happily build a package with an incorrect version. --- CMakeCPackLists.txt | 6 ++++++ CMakeLists.txt | 1 + Changelog | 2 ++ 3 files changed, 9 insertions(+) diff --git a/CMakeCPackLists.txt b/CMakeCPackLists.txt index fe6710f..3e42b5b 100644 --- a/CMakeCPackLists.txt +++ b/CMakeCPackLists.txt @@ -1,4 +1,10 @@ +execute_process(COMMAND git describe --long "--match=[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" --dirty=-WIP --abbrev=8 + RESULT_VARIABLE VERSION_EXIT OUTPUT_VARIABLE CURRENT_GIT_VERSION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) +if(NOT CPACK_GIT_VERSION STREQUAL CURRENT_GIT_VERSION) + message(FATAL_ERROR "The current git commit number (${CURRENT_GIT_VERSION}) does not match the number at cmake time (${CPACK_GIT_VERSION}).\nPlease rebuild the project (cmake . && make)") +endif(NOT CPACK_GIT_VERSION STREQUAL CURRENT_GIT_VERSION) + if(CPACK_GENERATOR STREQUAL "TGZ") if(CPACK_TGZ_PACKAGE_FILE_NAME) set(CPACK_PACKAGE_FILE_NAME "${CPACK_TGZ_PACKAGE_FILE_NAME}") diff --git a/CMakeLists.txt b/CMakeLists.txt index 58497e1..e0dd10c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,6 +359,7 @@ set(DUMPNODES_SCRIPTS set(PACKAGING_VERSION "1" CACHE STRING "Version of the packaging - '1' by default; increment when building a new package from the same sources (i.e. from the same commit)") #set(CPACK_SET_DESTDIR ON) +set(CPACK_GIT_VERSION ${GIT_VERSION}) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Map generator for Minetest") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_HOME_DIRECTORY}/package-description.txt") set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) diff --git a/Changelog b/Changelog index aaf40e9..3ff5cc9 100644 --- a/Changelog +++ b/Changelog @@ -14,6 +14,8 @@ - Workaround to allow compilation with clang when using leveldb. This is broken due to libstdc++ ABI incompatibility - Fixed compilation failure on FreeBSD (10.3) using gcc + - Detect when package version will not match current git commit id, + and refuse to build package with wrong version. [31 May 2016] Features: - Support for postgresql backend added