diff --git a/CMake/GitRevision.cmake b/CMake/GitRevision.cmake new file mode 100644 index 000000000..371bce340 --- /dev/null +++ b/CMake/GitRevision.cmake @@ -0,0 +1,22 @@ +# For now use simple approach to get version information as git is +# often avaialble on the machine where we are building from source + +find_package(Git) + +if(GIT_FOUND) + # get last commit sha1 + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --format=%h + WORKING_DIRECTORY ${CORENEURON_PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REVISION_SHA1 + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + # get last commit date + execute_process( + COMMAND ${GIT_EXECUTABLE} show -s --format=%ci + WORKING_DIRECTORY ${CORENEURON_PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REVISION_DATE + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CN_GIT_REVISION "${GIT_REVISION_SHA1} (${GIT_REVISION_DATE})") +else() + set(CN_GIT_REVISION "unknown") +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index b372e11a6..63ed64196 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ include(SetRpath) include(CTest) include(AddRandom123Submodule) include(AddCLI11Submodule) +include(GitRevision) add_subdirectory(${CORENEURON_PROJECT_SOURCE_DIR}/external/CLI11) @@ -104,6 +105,15 @@ if(CORENEURON_AS_SUBPROJECT) set(CORENRN_ENABLE_UNIT_TESTS OFF) endif() +# ============================================================================= +# Project version from git and project directories +# ============================================================================= +set(CN_PROJECT_VERSION ${PROJECT_VERSION}) + +# generate file with version number from git and nrnunits.lib file path +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/coreneuron/config/config.cpp.in + ${PROJECT_BINARY_DIR}/coreneuron/config/config.cpp @ONLY) + # ============================================================================= # Include cmake modules after cmake options # ============================================================================= diff --git a/coreneuron/CMakeLists.txt b/coreneuron/CMakeLists.txt index d36eb483f..9c7321944 100644 --- a/coreneuron/CMakeLists.txt +++ b/coreneuron/CMakeLists.txt @@ -35,6 +35,7 @@ file(GLOB_RECURSE CORENEURON_CUDA_FILES "*.cu") file(GLOB SCOPMATH_CODE_FILES "sim/scopmath/*.cpp") file(COPY ${CORENEURON_PROJECT_SOURCE_DIR}/external/Random123/include/Random123 DESTINATION ${CMAKE_BINARY_DIR}/include) +list(APPEND CORENEURON_CODE_FILES ${PROJECT_BINARY_DIR}/coreneuron/config/config.cpp) set(DIMPLIC_CODE_FILE "mechanism/mech/dimplic.cpp") set(ENGINEMECH_CODE_FILE "mechanism/mech/enginemech.cpp") diff --git a/coreneuron/apps/corenrn_parameters.cpp b/coreneuron/apps/corenrn_parameters.cpp index fbaba08a8..0b33d83fa 100644 --- a/coreneuron/apps/corenrn_parameters.cpp +++ b/coreneuron/apps/corenrn_parameters.cpp @@ -28,7 +28,11 @@ THE POSSIBILITY OF SUCH DAMAGE. #include "coreneuron/apps/corenrn_parameters.hpp" + namespace coreneuron { + +extern std::string cnrn_version(); + corenrn_parameters::corenrn_parameters(){ app.set_config("--read-config", "", "Read parameters from ini file", false) @@ -100,6 +104,8 @@ corenrn_parameters::corenrn_parameters(){ sub_output -> add_option("-o, --outpath", this->outpath, "Path to place output data files.", true); sub_output -> add_option("--checkpoint", this->checkpointpath, "Enable checkpoint and specify directory to store related files."); + app.add_flag("-v, --version", this->show_version, "Show version information and quit."); + CLI::retire_option(app, "--show"); }; @@ -111,13 +117,21 @@ void corenrn_parameters::parse (int argc, char** argv) { nrn_nobanner_ = 1; } } catch (const CLI::ExtrasError &e) { - std::cerr << "Single-dash arguments such as -mpi are deleted, please check ./coreneuron_exec --help for more information. \n" << std::endl; + // in case of parsing errors, show message with exception + std::cerr << "CLI parsing error, see nrniv-core --help for more information. \n" << std::endl; app.exit(e); throw e; } catch (const CLI::ParseError &e) { + // use --help is also ParseError; in this case exit by showing all options app.exit(e); - throw e; + exit(0); + } + + // is user has asked for version info, print it and exit + if (show_version) { + std::cout << "CoreNEURON Version : " << cnrn_version() << std::endl; + exit(0); } }; diff --git a/coreneuron/apps/corenrn_parameters.hpp b/coreneuron/apps/corenrn_parameters.hpp index 8d018f6a8..5daec072a 100644 --- a/coreneuron/apps/corenrn_parameters.hpp +++ b/coreneuron/apps/corenrn_parameters.hpp @@ -85,6 +85,8 @@ struct corenrn_parameters { bool gpu=false; /// Enable GPU computation. bool binqueue=false; /// Use bin queue. + bool show_version=false; /// Print version and exit. + verbose_level verbose{verbose_level::DEFAULT}; /// Verbosity-level double tstop=100; /// Stop time of simulation in msec diff --git a/coreneuron/apps/main1.cpp b/coreneuron/apps/main1.cpp index ce72989e9..87d402a75 100644 --- a/coreneuron/apps/main1.cpp +++ b/coreneuron/apps/main1.cpp @@ -37,6 +37,7 @@ THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "coreneuron/config/config.h" #include "coreneuron/engine.h" #include "coreneuron/utils/randoms/nrnran123.h" #include "coreneuron/nrnconf.h" @@ -339,12 +340,12 @@ void handle_forward_skip(double forwardskip, int prcellgid) { t = savet; dt2thread(-1.); - // clear spikes generated during forward skip (with negative time) + // clear spikes generated during forward skip (with negative time) clear_spike_vectors(); } -const char* nrn_version(int) { - return "version id unimplemented"; +std::string cnrn_version() { + return coreneuron::version::to_string(); } // bsize = 0 then per step transfer @@ -428,12 +429,7 @@ using namespace coreneuron; extern "C" void mk_mech_init(int argc, char** argv) { // read command line parameters and parameter config files - try { - corenrn_param.parse(argc, argv); - } - catch (...) { - nrn_abort(1); - } + corenrn_param.parse(argc, argv); #if NRNMPI if (corenrn_param.mpi_enable) { diff --git a/coreneuron/config/config.cpp.in b/coreneuron/config/config.cpp.in new file mode 100644 index 000000000..62e51e03e --- /dev/null +++ b/coreneuron/config/config.cpp.in @@ -0,0 +1,7 @@ +#include "coreneuron/config/config.h" + +/// Git version of the project +const std::string coreneuron::version::GIT_REVISION = "@CN_GIT_REVISION@"; + +/// CoreNEURON version +const std::string coreneuron::version::CORENEURON_VERSION = "@CN_PROJECT_VERSION@"; diff --git a/coreneuron/config/config.h b/coreneuron/config/config.h new file mode 100644 index 000000000..06d75c9fe --- /dev/null +++ b/coreneuron/config/config.h @@ -0,0 +1,31 @@ +#pragma once + +/** + * \dir + * \brief Global project configurations + * + * \file + * \brief Version information + */ + +#include + +namespace coreneuron { + +/** + * \brief Project version information + */ +struct version { + /// git revision id + static const std::string GIT_REVISION; + + /// project tagged version in the cmake + static const std::string CORENEURON_VERSION; + + /// return version string (version + git id) as a string + static std::string to_string() { + return CORENEURON_VERSION + " " + GIT_REVISION; + } +}; + +} // namespace coreneuron diff --git a/coreneuron/io/mk_mech.cpp b/coreneuron/io/mk_mech.cpp index 4fb93be54..a29fee2ee 100644 --- a/coreneuron/io/mk_mech.cpp +++ b/coreneuron/io/mk_mech.cpp @@ -49,7 +49,7 @@ namespace coreneuron { extern int nrn_nobanner_; // NB: this should go away -extern const char* nrn_version(int); +extern std::string cnrn_version(); std::map mech2type; extern "C" { @@ -140,7 +140,7 @@ static void mk_mech(std::istream& s) { if (nrnmpi_myid < 1 && nrn_nobanner_ == 0) { fprintf(stderr, " \n"); fprintf(stderr, " %s\n", banner); - fprintf(stderr, " %s\n", nrn_version(1)); + fprintf(stderr, " Version : %s\n", cnrn_version().c_str()); fprintf(stderr, " \n"); fflush(stderr); } diff --git a/coreneuron/network/netpar.cpp b/coreneuron/network/netpar.cpp index 13fdf9e6d..4681b5f21 100644 --- a/coreneuron/network/netpar.cpp +++ b/coreneuron/network/netpar.cpp @@ -654,7 +654,7 @@ double set_mindelay(double maxdelay) { } PreSyn* ps; InputPreSyn* psi; - netpar_tid_gid2ps(ith, gid, &ps, &psi); + netpar_tid_gid2ps(tid, gid, &ps, &psi); if (psi) { chk = true; } else if (all) { diff --git a/tests/jenkins/Jenkinsfile b/tests/jenkins/Jenkinsfile index 03124e1a9..bd5d6d1be 100644 --- a/tests/jenkins/Jenkinsfile +++ b/tests/jenkins/Jenkinsfile @@ -1,6 +1,6 @@ pipeline { agent { - label 'bb5' + label 'bb5 && !bb5-07' } parameters { string(name: 'sha1', defaultValue: 'master',