Skip to content

Commit

Permalink
Merge pull request #2715 from jougs/cleanup
Browse files Browse the repository at this point in the history
Transition version handling to proper semantic versioning when building from Git and release tarballs
  • Loading branch information
Helveg authored Apr 27, 2023
2 parents 0473658 + 3bbb357 commit 257620c
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 77 deletions.
11 changes: 1 addition & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ set( with-intel-compiler-flags OFF CACHE STRING "User defined flags for the Inte
set( with-libraries OFF CACHE STRING "Link additional libraries [default=OFF]. Give full path. Separate multiple libraries by ';'." )
set( with-includes OFF CACHE STRING "Add additional include paths [default=OFF]. Give full path without '-I'. Separate multiple include paths by ';'." )
set( with-defines OFF CACHE STRING "Additional defines, e.g. '-DXYZ=1' [default=OFF]. Separate multiple defines by ';'." )
set( with-version-suffix "" CACHE STRING "Set a user defined version suffix [default='']." )

# documentation build configuration
set( with-userdoc OFF CACHE STRING "Build user documentation [default=OFF]")
Expand Down Expand Up @@ -150,7 +149,6 @@ nest_process_with_sionlib()
nest_process_with_mpi4py()
nest_process_with_boost()
nest_process_target_bits_split()
nest_process_version_suffix()
nest_process_userdoc()
nest_process_devdoc()

Expand Down Expand Up @@ -183,17 +181,10 @@ nest_check_have_std_nan()
nest_check_have_std_isnan()
nest_check_random123()

################################################################################
################## Create version string ##################
################################################################################

include( NestVersionInfo )
get_version_info()
printInfo("-- NEST version: ${NEST_VERSION_STRING}")
printInfo("Done configuring NEST version: ${NEST_VERSION}")

################################################################################
################## Enable Testing Targets ##################
################################################################################
enable_testing()
set( TEST_OPTS "" )

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.4.0-post0.dev0
2 changes: 1 addition & 1 deletion bin/nest-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ while test $# -gt 0; do
echo $exec_prefix
;;
--version)
echo "@NEST_VERSION_STRING@"
echo "@NEST_VERSION@"
;;
--help)
usage 0
Expand Down
43 changes: 43 additions & 0 deletions build_support/version_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# version_info.sh
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

# This script extracts version control information to be used in
# cmake/NestVersionInfo.cmake

HASH=$(git rev-parse HEAD)

# Might fail if not on a branch, or no remote tracking branch is set
BRANCH_REMOTE=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>&1)
if [ $? -eq 0 ]; then
REMOTE=$(echo ${BRANCH_REMOTE} | cut -d\/ -f1)
else
REMOTE="unknown"
fi

# Might fail if we are not on a branch (i.e. in 'detached HEAD' mode)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ ! $? -eq 0 ] || [ ${BRANCH} = "HEAD" ]; then
BRANCH="unknown"
fi

# Printing with semicolons as separators, as this will be interpreted as
# a list by cmake
echo ${HASH}\;${BRANCH}\;${REMOTE}
68 changes: 20 additions & 48 deletions cmake/NestVersionInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,31 @@
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

# Determine NEST version based on git branch
# Put NEST version number and version control information into CMake variables
#
# This module defines
# NEST_VERSION_BRANCH, the current git branch (nest-3.0)
# NEST_VERSION_SUFFIX, set using -Dwith-version-suffix=<suffix>. ("-pre")
# NEST_VERSION, the numeric version number plus the suffix ("3.0-pre")
# NEST_VERSION_GITHASH, the current git revision hash (empty for tarballs) ("dd47c39ce")
# NEST_VERSION_STRING, the full NEST version string ("nest-3.0-pre@dd47c39ce")
# NEST_VERSION, the numeric version number including a suffix
# NEST_VERSION_GIT, a boolean indicating if source is managed by git
# NEST_VERSION_GIT_HASH, the current git revision hash (unset for tarballs)
# NEST_VERSION_GIT_BRANCH, the current git branch (unset for tarballs)
# NEST_VERSION_GIT_REMOTE, the upstream remote (if any) of the tracked branch (unset for tarballs)
#
# In release branches, the string "UNKNOWN" below has to be replaced
# with the proper version (e.g. "nest-2.20") in order to get the
# correct version number if building from tarballs.


macro(get_version_info)

if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
execute_process(
COMMAND "git" "rev-parse" "--short" "HEAD"
OUTPUT_VARIABLE NEST_VERSION_GITHASH
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)

execute_process(
COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD"
OUTPUT_VARIABLE NEST_VERSION_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)

if (NEST_VERSION_SUFFIX)
set(versionsuffix "-${NEST_VERSION_SUFFIX}")
endif()

if (NEST_VERSION_GITHASH)
set(githash "@${NEST_VERSION_GITHASH}")
endif()
endif()

if (NOT NEST_VERSION_BRANCH)
set(NEST_VERSION_BRANCH "UNKNOWN")
endif()

string(SUBSTRING "${NEST_VERSION_BRANCH}" 0 5 isRelease)
if (isRelease STREQUAL "nest-")
string(SUBSTRING "${NEST_VERSION_BRANCH}${versionsuffix}" 5 99999 NEST_VERSION)
else()
set(NEST_VERSION "${NEST_VERSION_BRANCH}${versionsuffix}")
endif()

set(NEST_VERSION_STRING "${NEST_VERSION_BRANCH}${versionsuffix}${githash}")
unset(branchname)
unset(versionsuffix)
file (STRINGS "${CMAKE_SOURCE_DIR}/VERSION" NEST_VERSION )

if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
set( NEST_VERSION_GIT 1 )
execute_process(
COMMAND "bash" "${PROJECT_SOURCE_DIR}/build_support/version_info.sh"
OUTPUT_VARIABLE NEST_VERSION_INFO
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
list( GET NEST_VERSION_INFO 0 NEST_VERSION_GIT_HASH )
list( GET NEST_VERSION_INFO 1 NEST_VERSION_GIT_BRANCH )
list( GET NEST_VERSION_INFO 2 NEST_VERSION_GIT_REMOTE )
endif()

endmacro()
10 changes: 1 addition & 9 deletions cmake/ProcessOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ function( NEST_PROCESS_WITH_OPTIMIZE )
endif ()
endfunction()

function( NEST_PROCESS_VERSION_SUFFIX )
if ( with-version-suffix )
foreach ( flag ${with-version-suffix} )
set( NEST_VERSION_SUFFIX "${flag}" PARENT_SCOPE )
endforeach ()
endif ()
endfunction()

function( NEST_PROCESS_WITH_DEBUG )
if ( with-debug )
if ( with-debug STREQUAL "ON" )
Expand Down Expand Up @@ -660,4 +652,4 @@ function( NEST_PROCESS_DEVDOC )
set( BUILD_DOXYGEN_DOCS ON PARENT_SCOPE )
set( BUILD_DOCS ON PARENT_SCOPE )
endif ()
endfunction ()
endfunction ()
2 changes: 1 addition & 1 deletion doc/fulldoc.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = NEST
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = @NEST_VERSION_STRING@
PROJECT_NUMBER = @NEST_VERSION@

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
8 changes: 4 additions & 4 deletions libnestutil/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
configuration process. Please make all changes in config.h.in.
*/

#define NEST_VERSION_STRING "@NEST_VERSION_STRING@"
#define NEST_VERSION_BRANCH "@NEST_VERSION_BRANCH@"
#define NEST_VERSION_SUFFIX "@NEST_VERSION_SUFFIX@"
#define NEST_VERSION "@NEST_VERSION@"
#define NEST_VERSION_GITHASH "@NEST_VERSION_GITHASH@"
#cmakedefine NEST_VERSION_GIT "@NEST_VERSION_GIT@"
#cmakedefine NEST_VERSION_GIT_HASH "@NEST_VERSION_GIT_HASH@"
#cmakedefine NEST_VERSION_GIT_BRANCH "@NEST_VERSION_GIT_BRANCH@"
#cmakedefine NEST_VERSION_GIT_REMOTE "@NEST_VERSION_GIT_REMOTE@"

// TODO NEST_HOST and NEST_HOSTVENDOR not available with cmake
#define NEST_HOST "@NEST_TARGET_TRIPLE@"
Expand Down
2 changes: 1 addition & 1 deletion nestkernel/recording_backend_ascii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ nest::RecordingBackendASCII::DeviceData::open_file()
throw IOError();
}

file_ << "# NEST version: " << NEST_VERSION_STRING << std::endl
file_ << "# NEST version: " << NEST_VERSION << std::endl
<< "# RecordingBackendASCII version: " << ASCII_REC_BACKEND_VERSION << std::endl;

const std::string timehead = ( time_in_steps_ ) ? "\ttime_step\ttime_offset" : "\ttime_ms";
Expand Down
2 changes: 1 addition & 1 deletion nestkernel/recording_backend_sionlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ nest::RecordingBackendSIONlib::close_files_()
sion_fwrite( &SIONLIB_REC_BACKEND_VERSION, sizeof( sion_uint32 ), 1, file.sid );

// write nest version into sionlib container file
const char* nest_version = NEST_VERSION_STRING;
const char* nest_version = NEST_VERSION;
char version_buffer[ NEST_VERSION_BUFFERSIZE ];
strncpy( version_buffer, nest_version, NEST_VERSION_BUFFERSIZE - 1 );
version_buffer[ NEST_VERSION_BUFFERSIZE - 1 ] = '\0';
Expand Down
2 changes: 1 addition & 1 deletion pynest/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from setuptools import setup

setup(
name = 'nest-simulator',
version = '@NEST_VERSION@@githash@',
version = '@NEST_VERSION@',
description = 'Python bindings for NEST',
author = 'The NEST Initiative',
url = 'https://www.nest-simulator.org',
Expand Down
13 changes: 12 additions & 1 deletion sli/slistartup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ SLIStartup::SLIStartup( int argc, char** argv )
, debug_( false )
, argv_name( "argv" )
, version_name( "version" )
, version_git_info_name( "git_info" )
, version_git_hash_name( "hash" )
, version_git_branch_name( "branch" )
, version_git_remote_name( "remote" )
, exitcode_name( "exitcode" )
, prgbuilt_name( "built" )
, prefix_name( "prefix" )
Expand Down Expand Up @@ -274,7 +278,14 @@ SLIStartup::init( SLIInterpreter* i )
assert( statusdict.valid() );

statusdict->insert_move( argv_name, commandline_args_ );
statusdict->insert( version_name, Token( new StringDatum( NEST_VERSION_STRING ) ) );
statusdict->insert( version_name, Token( new StringDatum( NEST_VERSION ) ) );
#ifdef NEST_VERSION_GIT
DictionaryDatum rcsinfodict( new Dictionary() );
rcsinfodict->insert( version_git_hash_name, Token( new StringDatum( NEST_VERSION_GIT_HASH ) ) );
rcsinfodict->insert( version_git_branch_name, Token( new StringDatum( NEST_VERSION_GIT_BRANCH ) ) );
rcsinfodict->insert( version_git_remote_name, Token( new StringDatum( NEST_VERSION_GIT_REMOTE ) ) );
statusdict->insert( version_git_info_name, Token( rcsinfodict ) );
#endif
statusdict->insert( exitcode_name, Token( new IntegerDatum( EXIT_SUCCESS ) ) );
statusdict->insert( prgbuilt_name, Token( new StringDatum( String::compose( "%1 %2", __DATE__, __TIME__ ) ) ) );
statusdict->insert( prgdatadir_name, Token( new StringDatum( slilibdir ) ) );
Expand Down
4 changes: 4 additions & 0 deletions sli/slistartup.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class SLIStartup : public SLIModule
public:
Name argv_name;
Name version_name;
Name version_git_info_name;
Name version_git_hash_name;
Name version_git_branch_name;
Name version_git_remote_name;
Name exitcode_name;
Name prgbuilt_name;
Name prefix_name;
Expand Down

0 comments on commit 257620c

Please sign in to comment.