Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit e0a2774

Browse files
pramodknrnhines
andauthored
Implement support for version from last git commit and bugfix for PR #390 (#392)
* Implement support for version from last git commit - coreneuron version was printed as "version id unimplemented" - add cmake module GitRevision.cmake to find git commit information - this commit adds support to print project version along with git commit and it's date. e.g. Version : 0.21.0 bd747a8 (14-09-2020 16:03) * Added --version CLI flag - Use git show instead of git show to be compatible with older git (e.g. on BB5) * Avoid nrn_abort when --help is called * Bug fix for merged pull request #390 : tid and ith args were mixed * For BB5 Jenkins, exclude problematic agent bb5-07 (has strange PGI compiler issue) Co-authored-by: Michael Hines <[email protected]>
1 parent cc85723 commit e0a2774

File tree

11 files changed

+98
-15
lines changed

11 files changed

+98
-15
lines changed

CMake/GitRevision.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# For now use simple approach to get version information as git is
2+
# often avaialble on the machine where we are building from source
3+
4+
find_package(Git)
5+
6+
if(GIT_FOUND)
7+
# get last commit sha1
8+
execute_process(
9+
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
10+
WORKING_DIRECTORY ${CORENEURON_PROJECT_SOURCE_DIR}
11+
OUTPUT_VARIABLE GIT_REVISION_SHA1
12+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
13+
# get last commit date
14+
execute_process(
15+
COMMAND ${GIT_EXECUTABLE} show -s --format=%ci
16+
WORKING_DIRECTORY ${CORENEURON_PROJECT_SOURCE_DIR}
17+
OUTPUT_VARIABLE GIT_REVISION_DATE
18+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
19+
set(CN_GIT_REVISION "${GIT_REVISION_SHA1} (${GIT_REVISION_DATE})")
20+
else()
21+
set(CN_GIT_REVISION "unknown")
22+
endif()

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ include(SetRpath)
6363
include(CTest)
6464
include(AddRandom123Submodule)
6565
include(AddCLI11Submodule)
66+
include(GitRevision)
6667

6768
add_subdirectory(${CORENEURON_PROJECT_SOURCE_DIR}/external/CLI11)
6869

@@ -104,6 +105,15 @@ if(CORENEURON_AS_SUBPROJECT)
104105
set(CORENRN_ENABLE_UNIT_TESTS OFF)
105106
endif()
106107

108+
# =============================================================================
109+
# Project version from git and project directories
110+
# =============================================================================
111+
set(CN_PROJECT_VERSION ${PROJECT_VERSION})
112+
113+
# generate file with version number from git and nrnunits.lib file path
114+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/coreneuron/config/config.cpp.in
115+
${PROJECT_BINARY_DIR}/coreneuron/config/config.cpp @ONLY)
116+
107117
# =============================================================================
108118
# Include cmake modules after cmake options
109119
# =============================================================================

coreneuron/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ file(GLOB_RECURSE CORENEURON_CUDA_FILES "*.cu")
3535
file(GLOB SCOPMATH_CODE_FILES "sim/scopmath/*.cpp")
3636
file(COPY ${CORENEURON_PROJECT_SOURCE_DIR}/external/Random123/include/Random123
3737
DESTINATION ${CMAKE_BINARY_DIR}/include)
38+
list(APPEND CORENEURON_CODE_FILES ${PROJECT_BINARY_DIR}/coreneuron/config/config.cpp)
3839

3940
set(DIMPLIC_CODE_FILE "mechanism/mech/dimplic.cpp")
4041
set(ENGINEMECH_CODE_FILE "mechanism/mech/enginemech.cpp")

coreneuron/apps/corenrn_parameters.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ THE POSSIBILITY OF SUCH DAMAGE.
2828

2929
#include "coreneuron/apps/corenrn_parameters.hpp"
3030

31+
3132
namespace coreneuron {
33+
34+
extern std::string cnrn_version();
35+
3236
corenrn_parameters::corenrn_parameters(){
3337

3438
app.set_config("--read-config", "", "Read parameters from ini file", false)
@@ -100,6 +104,8 @@ corenrn_parameters::corenrn_parameters(){
100104
sub_output -> add_option("-o, --outpath", this->outpath, "Path to place output data files.", true);
101105
sub_output -> add_option("--checkpoint", this->checkpointpath, "Enable checkpoint and specify directory to store related files.");
102106

107+
app.add_flag("-v, --version", this->show_version, "Show version information and quit.");
108+
103109
CLI::retire_option(app, "--show");
104110
};
105111

@@ -111,13 +117,21 @@ void corenrn_parameters::parse (int argc, char** argv) {
111117
nrn_nobanner_ = 1;
112118
}
113119
} catch (const CLI::ExtrasError &e) {
114-
std::cerr << "Single-dash arguments such as -mpi are deleted, please check ./coreneuron_exec --help for more information. \n" << std::endl;
120+
// in case of parsing errors, show message with exception
121+
std::cerr << "CLI parsing error, see nrniv-core --help for more information. \n" << std::endl;
115122
app.exit(e);
116123
throw e;
117124

118125
} catch (const CLI::ParseError &e) {
126+
// use --help is also ParseError; in this case exit by showing all options
119127
app.exit(e);
120-
throw e;
128+
exit(0);
129+
}
130+
131+
// is user has asked for version info, print it and exit
132+
if (show_version) {
133+
std::cout << "CoreNEURON Version : " << cnrn_version() << std::endl;
134+
exit(0);
121135
}
122136
};
123137

coreneuron/apps/corenrn_parameters.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ struct corenrn_parameters {
8585
bool gpu=false; /// Enable GPU computation.
8686
bool binqueue=false; /// Use bin queue.
8787

88+
bool show_version=false; /// Print version and exit.
89+
8890
verbose_level verbose{verbose_level::DEFAULT}; /// Verbosity-level
8991

9092
double tstop=100; /// Stop time of simulation in msec

coreneuron/apps/main1.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
3737
#include <memory>
3838
#include <vector>
3939

40+
#include "coreneuron/config/config.h"
4041
#include "coreneuron/engine.h"
4142
#include "coreneuron/utils/randoms/nrnran123.h"
4243
#include "coreneuron/nrnconf.h"
@@ -339,12 +340,12 @@ void handle_forward_skip(double forwardskip, int prcellgid) {
339340
t = savet;
340341
dt2thread(-1.);
341342

342-
// clear spikes generated during forward skip (with negative time)
343+
// clear spikes generated during forward skip (with negative time)
343344
clear_spike_vectors();
344345
}
345346

346-
const char* nrn_version(int) {
347-
return "version id unimplemented";
347+
std::string cnrn_version() {
348+
return coreneuron::version::to_string();
348349
}
349350

350351
// bsize = 0 then per step transfer
@@ -428,12 +429,7 @@ using namespace coreneuron;
428429

429430
extern "C" void mk_mech_init(int argc, char** argv) {
430431
// read command line parameters and parameter config files
431-
try {
432-
corenrn_param.parse(argc, argv);
433-
}
434-
catch (...) {
435-
nrn_abort(1);
436-
}
432+
corenrn_param.parse(argc, argv);
437433

438434
#if NRNMPI
439435
if (corenrn_param.mpi_enable) {

coreneuron/config/config.cpp.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "coreneuron/config/config.h"
2+
3+
/// Git version of the project
4+
const std::string coreneuron::version::GIT_REVISION = "@CN_GIT_REVISION@";
5+
6+
/// CoreNEURON version
7+
const std::string coreneuron::version::CORENEURON_VERSION = "@CN_PROJECT_VERSION@";

coreneuron/config/config.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
/**
4+
* \dir
5+
* \brief Global project configurations
6+
*
7+
* \file
8+
* \brief Version information
9+
*/
10+
11+
#include <string>
12+
13+
namespace coreneuron {
14+
15+
/**
16+
* \brief Project version information
17+
*/
18+
struct version {
19+
/// git revision id
20+
static const std::string GIT_REVISION;
21+
22+
/// project tagged version in the cmake
23+
static const std::string CORENEURON_VERSION;
24+
25+
/// return version string (version + git id) as a string
26+
static std::string to_string() {
27+
return CORENEURON_VERSION + " " + GIT_REVISION;
28+
}
29+
};
30+
31+
} // namespace coreneuron

coreneuron/io/mk_mech.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace coreneuron {
4949
extern int nrn_nobanner_;
5050

5151
// NB: this should go away
52-
extern const char* nrn_version(int);
52+
extern std::string cnrn_version();
5353
std::map<std::string, int> mech2type;
5454

5555
extern "C" {
@@ -140,7 +140,7 @@ static void mk_mech(std::istream& s) {
140140
if (nrnmpi_myid < 1 && nrn_nobanner_ == 0) {
141141
fprintf(stderr, " \n");
142142
fprintf(stderr, " %s\n", banner);
143-
fprintf(stderr, " %s\n", nrn_version(1));
143+
fprintf(stderr, " Version : %s\n", cnrn_version().c_str());
144144
fprintf(stderr, " \n");
145145
fflush(stderr);
146146
}

coreneuron/network/netpar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ double set_mindelay(double maxdelay) {
654654
}
655655
PreSyn* ps;
656656
InputPreSyn* psi;
657-
netpar_tid_gid2ps(ith, gid, &ps, &psi);
657+
netpar_tid_gid2ps(tid, gid, &ps, &psi);
658658
if (psi) {
659659
chk = true;
660660
} else if (all) {

0 commit comments

Comments
 (0)