From 5fadfa3159bf46d30329764f28b36e8d99b5270c Mon Sep 17 00:00:00 2001 From: Jochen Martin Eppler Date: Wed, 26 Apr 2023 17:59:08 +0200 Subject: [PATCH 1/6] Clean up version handling (once and for all ;-)) --- CMakeLists.txt | 2 +- VERSION | 1 + bin/nest-config.in | 2 +- build_support/version_info.sh | 43 +++++++++++++++ cmake/NestVersionInfo.cmake | 68 +++++++----------------- doc/fulldoc.conf.in | 2 +- libnestutil/config.h.in | 8 +-- nestkernel/recording_backend_ascii.cpp | 2 +- nestkernel/recording_backend_sionlib.cpp | 2 +- pynest/setup.py.in | 2 +- sli/slistartup.cc | 13 ++++- sli/slistartup.h | 4 ++ 12 files changed, 90 insertions(+), 59 deletions(-) create mode 100644 VERSION create mode 100644 build_support/version_info.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index b64057f8cf..8d3f9bd294 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,7 +189,7 @@ nest_check_random123() include( NestVersionInfo ) get_version_info() -printInfo("-- NEST version: ${NEST_VERSION_STRING}") +printInfo("Done configuring NEST version: ${NEST_VERSION}") ################################################################################ ################## Enable Testing Targets ################## diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000..d4f7728c55 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +3.4.0-post0.dev0 diff --git a/bin/nest-config.in b/bin/nest-config.in index b7cf9bcbdb..a54ae03521 100755 --- a/bin/nest-config.in +++ b/bin/nest-config.in @@ -56,7 +56,7 @@ while test $# -gt 0; do echo $exec_prefix ;; --version) - echo "@NEST_VERSION_STRING@" + echo "@NEST_VERSION@" ;; --help) usage 0 diff --git a/build_support/version_info.sh b/build_support/version_info.sh new file mode 100644 index 0000000000..1fc2a63678 --- /dev/null +++ b/build_support/version_info.sh @@ -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 . + +# 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 +REMOTE_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>&1) +if [ $? -eq 0 ]; then + REMOTE=$(echo ${REMOTE_BRANCH} | 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 + +# Print ingwith semicolons as separators, as this will be interpreted as +# a list by cmake +echo ${HASH}\;${BRANCH}\;${REMOTE} diff --git a/cmake/NestVersionInfo.cmake b/cmake/NestVersionInfo.cmake index 158cd49cf3..689e120181 100644 --- a/cmake/NestVersionInfo.cmake +++ b/cmake/NestVersionInfo.cmake @@ -17,59 +17,31 @@ # You should have received a copy of the GNU General Public License # along with NEST. If not, see . -# 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=. ("-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 tracked remote 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() diff --git a/doc/fulldoc.conf.in b/doc/fulldoc.conf.in index 537b824973..d8f40eda37 100644 --- a/doc/fulldoc.conf.in +++ b/doc/fulldoc.conf.in @@ -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 diff --git a/libnestutil/config.h.in b/libnestutil/config.h.in index 6ffe368c0d..89e1833693 100644 --- a/libnestutil/config.h.in +++ b/libnestutil/config.h.in @@ -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@" diff --git a/nestkernel/recording_backend_ascii.cpp b/nestkernel/recording_backend_ascii.cpp index 9fafd34082..a0128db941 100644 --- a/nestkernel/recording_backend_ascii.cpp +++ b/nestkernel/recording_backend_ascii.cpp @@ -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"; diff --git a/nestkernel/recording_backend_sionlib.cpp b/nestkernel/recording_backend_sionlib.cpp index eb5c7f6d18..43357b9225 100644 --- a/nestkernel/recording_backend_sionlib.cpp +++ b/nestkernel/recording_backend_sionlib.cpp @@ -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'; diff --git a/pynest/setup.py.in b/pynest/setup.py.in index 44f35b46ff..8233d2708f 100644 --- a/pynest/setup.py.in +++ b/pynest/setup.py.in @@ -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', diff --git a/sli/slistartup.cc b/sli/slistartup.cc index 527d55c468..c393de4e64 100644 --- a/sli/slistartup.cc +++ b/sli/slistartup.cc @@ -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" ) @@ -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 ) ) ); diff --git a/sli/slistartup.h b/sli/slistartup.h index 9454a1c6b7..e236ad9f88 100644 --- a/sli/slistartup.h +++ b/sli/slistartup.h @@ -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; From b2e035b90a1db2f0f9de07697f69f233b8ab3ca8 Mon Sep 17 00:00:00 2001 From: Jochen Martin Eppler Date: Wed, 26 Apr 2023 18:03:44 +0200 Subject: [PATCH 2/6] Cleanup --- CMakeLists.txt | 7 ------- cmake/ProcessOptions.cmake | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d3f9bd294..7e8dd76af2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,17 +183,10 @@ nest_check_have_std_nan() nest_check_have_std_isnan() nest_check_random123() -################################################################################ -################## Create version string ################## -################################################################################ - include( NestVersionInfo ) get_version_info() printInfo("Done configuring NEST version: ${NEST_VERSION}") -################################################################################ -################## Enable Testing Targets ################## -################################################################################ enable_testing() set( TEST_OPTS "" ) diff --git a/cmake/ProcessOptions.cmake b/cmake/ProcessOptions.cmake index a540cfb4b0..8d1c58c394 100644 --- a/cmake/ProcessOptions.cmake +++ b/cmake/ProcessOptions.cmake @@ -660,4 +660,4 @@ function( NEST_PROCESS_DEVDOC ) set( BUILD_DOXYGEN_DOCS ON PARENT_SCOPE ) set( BUILD_DOCS ON PARENT_SCOPE ) endif () -endfunction () \ No newline at end of file +endfunction () From 798e8be49b2b426417e635bfa8ff1207dc70fb90 Mon Sep 17 00:00:00 2001 From: Jochen Martin Eppler Date: Wed, 26 Apr 2023 18:04:14 +0200 Subject: [PATCH 3/6] Remove possibility to set custom version suffixes --- CMakeLists.txt | 2 -- cmake/ProcessOptions.cmake | 8 -------- 2 files changed, 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e8dd76af2..d0150a158a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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]") @@ -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() diff --git a/cmake/ProcessOptions.cmake b/cmake/ProcessOptions.cmake index 8d1c58c394..b5f010c8cd 100644 --- a/cmake/ProcessOptions.cmake +++ b/cmake/ProcessOptions.cmake @@ -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" ) From 2beb5c484fbf4d9069230195fd6934267f39edeb Mon Sep 17 00:00:00 2001 From: Jochen Martin Eppler Date: Thu, 27 Apr 2023 10:03:48 +0200 Subject: [PATCH 4/6] Update build_support/version_info.sh Co-authored-by: Robin De Schepper --- build_support/version_info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_support/version_info.sh b/build_support/version_info.sh index 1fc2a63678..1efe5d03ac 100644 --- a/build_support/version_info.sh +++ b/build_support/version_info.sh @@ -38,6 +38,6 @@ if [ ! $? -eq 0 ] || [ ${BRANCH} = "HEAD" ]; then BRANCH="unknown" fi -# Print ingwith semicolons as separators, as this will be interpreted as +# Printing with semicolons as separators, as this will be interpreted as # a list by cmake echo ${HASH}\;${BRANCH}\;${REMOTE} From e04f0cdbbae48dc5fa8e1eeba8cfc4add9d2a643 Mon Sep 17 00:00:00 2001 From: Jochen Martin Eppler Date: Thu, 27 Apr 2023 10:06:39 +0200 Subject: [PATCH 5/6] Update build_support/version_info.sh --- build_support/version_info.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_support/version_info.sh b/build_support/version_info.sh index 1efe5d03ac..7a8daf3091 100644 --- a/build_support/version_info.sh +++ b/build_support/version_info.sh @@ -25,9 +25,9 @@ HASH=$(git rev-parse HEAD) # Might fail if not on a branch, or no remote tracking branch is set -REMOTE_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>&1) +BRANCH_REMOTE=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>&1) if [ $? -eq 0 ]; then - REMOTE=$(echo ${REMOTE_BRANCH} | cut -d\/ -f1) + REMOTE=$(echo ${BRANCH_REMOTE} | cut -d\/ -f1) else REMOTE="unknown" fi From 3bbb3574b9c9510e20276631e02b8ee350b419f8 Mon Sep 17 00:00:00 2001 From: Jochen Martin Eppler Date: Thu, 27 Apr 2023 13:51:38 +0200 Subject: [PATCH 6/6] Update cmake/NestVersionInfo.cmake --- cmake/NestVersionInfo.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/NestVersionInfo.cmake b/cmake/NestVersionInfo.cmake index 689e120181..90df0f9c1a 100644 --- a/cmake/NestVersionInfo.cmake +++ b/cmake/NestVersionInfo.cmake @@ -24,7 +24,7 @@ # 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 tracked remote branch (unset for tarballs) +# NEST_VERSION_GIT_REMOTE, the upstream remote (if any) of the tracked branch (unset for tarballs) # macro(get_version_info)