Skip to content

Commit

Permalink
Merge pull request htm-community#632 from htm-community/setting_version
Browse files Browse the repository at this point in the history
added versioning from git tags
  • Loading branch information
breznak authored Aug 14, 2019
2 parents adf8039 + d719410 commit 58f0a9e
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 10 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}" CACHE PATH "Default Install location" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

# obtain the version from git and put it in the VERSION file
include(versioning.cmake)
get_versions(VERSION MAJOR MINOR PATCH)

message(STATUS "REPOSITORY_DIR = ${REPOSITORY_DIR}")
message(STATUS "CMAKE_BINARY_DIR = ${CMAKE_BINARY_DIR}")
message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
message(STATUS "FORCE_CPP11 = ${FORCE_CPP11}")
message(STATUS "FORCE_BOOST = ${FORCE_BOOST}")
message(STATUS "BINDING_BUILD = ${BINDING_BUILD}")
message(STATUS "Environment var CXX = $ENV{CXX}")
message(STATUS "VERSION = ${VERSION}")
message(STATUS "MAJOR = ${MAJOR}")
message(STATUS "MINOR = ${MINOR}")
message(STATUS "PATCH = ${PATCH}")
message("")

# Determine common toolchain settings, compiler and link flags
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
2.0.0
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ build_script:
- python -m pip install --user --upgrade pip setuptools setuptools-scm wheel || exit
- python -m pip install --no-cache-dir --user -r bindings/py/packaging/requirements.txt || exit

# we need to find the previous git tags so a shallow clone is not enough
- git fetch --depth=200

# Build the library with the python interface (64bit Release build)
- cd %HTM_CORE%
Expand Down
14 changes: 6 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ set(CORE_LIB_INCLUDES ${CORE_LIB_INCLUDES} PARENT_SCOPE)
# Create Version.hpp
# Extract current git sha and record in htm/Version.hpp.in
#
execute_process(COMMAND git rev-parse HEAD
OUTPUT_VARIABLE HTM_CORE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(HTM_CORE_VERSION ${VERSION})
configure_file(
"${PROJECT_SOURCE_DIR}/htm/Version.hpp.in"
"${PROJECT_BINARY_DIR}/Version.hpp")
Expand Down Expand Up @@ -453,10 +451,10 @@ install(DIRECTORY "${CMAKE_INSTALL_PREFIX}/distr/dist/"
set(CPACK_PACKAGE_NAME "htm.core")
set(CPACK_PACKAGE_VENDOR "https://github.com/htm-community/htm.core")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "htm.core - Community implementation of Numenta's algorthms.")
set(CPACK_PACKAGE_VERSION "2.0.0")
set(CPACK_PACKAGE_VERSION_MAJOR "2")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PATCH})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "htm.core")

if(MSVC)
Expand All @@ -465,5 +463,5 @@ else()
set(CPACK_GENERATOR "TGZ")
endif()
set(CPACK_RESOURCE_FILE_LICENSE "${REPOSITORY_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_FILE_NAME "htm_core-${HTM_CORE_VERSION}-${PLATFORM}${BITNESS}${PLATFORM_SUFFIX}")
set(CPACK_PACKAGE_FILE_NAME "htm_core-${VERSION}-${PLATFORM}${BITNESS}${PLATFORM_SUFFIX}")
include(CPack)
119 changes: 119 additions & 0 deletions versioning.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# -----------------------------------------------------------------------------
# HTM Community Edition of NuPIC
# Copyright (C) 2019, Numenta, Inc.
#
# Author: David Keeney, 2019
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
# -----------------------------------------------------------------------------


# This function figures out the version from git and returns Version, Major, Minor, Patch
#
# This function will query git to find the most recent tag by calling
# git describe --tags
# If there is a tag on the PR then this will be an exact match and this
# determins the version. If there have been commits
# since the tag it may contain additional info relating to the commit.
#
# Once we have the version, we parse out the Major, Minor, and Patch components
# and we write the version into the VERSION file if its different.
# The components VERSION, MAJOR, MINOR, and PATCH are returned to
# the top level CMakeLists.txt file. The VERSION file's value is also
# integrated into the created version.h file which is part of the
# includes folder in the GitHub binary distribution.
#
# These four components are used to create the GitHub release package during
# packaging. The value in VERSION file will be used by setup.py to set
# the version when it creates the wheel file which is the package for PYPI.
#
# If someone should try to build without having cloned the repository
# (just downloaded a tag.gz or zip), it will just use the current value
# in the VERSION file.

function(get_versions version major minor patch)
# do we have Git installed and are we in a repository?
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND "${GIT_EXECUTABLE}" log --pretty=format:'%h' -n 1
OUTPUT_VARIABLE GIT_REV
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
endif()
# Check whether we got any revision; which isn't
# always the case, e.g. when someone downloaded a tar.gz or zip
# file from Github instead of a checkout...
# or maybe git is not even installed.
if ("${GIT_REV}" STREQUAL "")
# use the version already in the VERSION file.
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VERSION GIT_TAG)
endif()
else()

# see if there as a tag set on this PR
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --exact-match --tags
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)

if ("${GIT_TAG}" STREQUAL "")
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
endif()
endif()

if ("${GIT_TAG}" STREQUAL "")
set(m_version ${GIT_REV})
set(${version} ${m_version} PARENT_SCOPE)
set(${major} 0 PARENT_SCOPE)
set(${minor} 0 PARENT_SCOPE)
set(${patch} 0 PARENT_SCOPE)
return()
else()
set(m_version ${GIT_TAG})
endif()

message(STATUS "Version from Git: ${m_version}")

string(REGEX REPLACE "^([vV])([0-9]*)([.][0-9]*[.][0-9]*-?.*)$" "\\2" numbers ${m_version} )
set(m_major ${numbers})
string(REGEX REPLACE "^([vV][0-9]*[.])([0-9]*)([.][0-9]*-?.*)$" "\\2" numbers ${m_version} )
set(m_minor ${numbers})
string(REGEX REPLACE "^([vV][0-9]*[.][0-9]*[.])([0-9]*)(-?.*)$" "\\2" numbers ${m_version} )
set(m_patch ${numbers})

# limiting ourselves to Major.Minor.Patch format for version.
set(m_version "${m_major}.${m_minor}.${m_patch}")

# Write it to the file VERSION if it is different.
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VERSION m_version_)
else()
set(m_version_ "")
endif()

if (NOT "${m_version}" STREQUAL "${m_version_}")
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/VERSION "${m_version}")
endif()

# return the arguments
set(${version} ${m_version} PARENT_SCOPE)
set(${major} ${m_major} PARENT_SCOPE)
set(${minor} ${m_minor} PARENT_SCOPE)
set(${patch} ${m_patch} PARENT_SCOPE)
endfunction()

0 comments on commit 58f0a9e

Please sign in to comment.