Skip to content

Commit

Permalink
version checking: revert previous changes and fix link errors
Browse files Browse the repository at this point in the history
Also:

- change App::mrtrix_command_version to App::exec_uses_mrtrix_version

- record project build date
  • Loading branch information
jdtournier committed May 11, 2018
1 parent e0cf25f commit e571b4c
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ config
build.*
/configure.log
/build.log
/core/library_version.cpp
/src/command_version.cpp
/core/version.cpp
/src/exec_version.cpp
/src/project_version.h
/lib/mrtrix3/_version.py
/test/src/project_version.h
Expand Down
35 changes: 24 additions & 11 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ please run "./configure" prior to invoking this script
''')
sys.exit (1)

if separate_project:
cpp_flags += [ '-DMRTRIX_MODULE' ]

environ = os.environ.copy()
environ.update ({ 'PATH': PATH })
Expand Down Expand Up @@ -542,11 +544,6 @@ if os.path.isdir ('release'):
disp ('WARNING: removing \'release/\' folder - most likely left over from a previous installation\n')
shutil.rmtree ('release')

old_version_file_path = os.path.join(lib_dir, 'version.cpp')
if os.path.isfile (old_version_file_path):
disp ('WARNING: removing file \'' + old_version_file_path + ' - most likely left over from a previous installation\n')
os.remove (old_version_file_path)

for entry in glob.glob (os.path.normpath (os.path.join (target_lib_dir, '*' + lib_suffix))):
if os.path.basename (entry) != libname:
disp ('WARNING: removing "' + entry + '" - most likely left over from a previous installation\n')
Expand Down Expand Up @@ -619,6 +616,9 @@ class Entry:
else: cc_file = self.name
cc_file = modify_path (os.path.join (cmd_dir, os.sep.join (split_path(cc_file)[1:])), add=cpp_suffix)
self.deps = list_cmd_deps(cc_file)
if separate_project:
self.deps = self.deps.union ([ os.path.join (tmp_dir, misc_dir, 'project_version' + obj_suffix) ])
print (self.deps)

skip = False
flags = []
Expand Down Expand Up @@ -1117,28 +1117,41 @@ if len(targets) == 0:


# get git version info:
update_git_version (mrtrix_dir[-1], os.path.join (lib_dir, 'library_version.cpp'), '''
update_git_version (mrtrix_dir[-1], os.path.join (lib_dir, 'version.cpp'), '''
namespace MR {
namespace App {
const char* library_version = "%%%";
const char* mrtrix_version = "%%%";
const char* build_date = __DATE__;
}
}
''')

update_git_version (mrtrix_dir[-1], os.path.join (mrtrix_dir[-1], misc_dir, 'command_version.cpp'), '''
update_git_version (mrtrix_dir[-1], os.path.join (mrtrix_dir[-1], misc_dir, 'exec_version.cpp'), '''
namespace MR {
namespace App {
const char* command_version = "%%%";
extern const char* executable_uses_mrtrix_version;
void set_executable_uses_mrtrix_version () { executable_uses_mrtrix_version = "%%%"; }
}
}
''')

if separate_project:
if not os.path.exists (misc_dir):
os.mkdir (misc_dir)
git_version_file = os.path.join (misc_dir, 'project_version.h')
update_git_version ('.', git_version_file, '#define MRTRIX_PROJECT_VERSION "%%%"\n');
git_version_file = os.path.join (misc_dir, 'project_version.cpp')
update_git_version ('.', git_version_file, '''
namespace MR {
namespace App {
extern const char* project_version;
extern const char* project_build_date;
void set_project_version () {
project_version = "%%%";
project_build_date = __DATE__;
}
}
}
''')

if not os.path.exists (git_version_file):
with open (git_version_file, 'w'):
pass
Expand Down
4 changes: 2 additions & 2 deletions cmd/tckconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class PLYWriter: public WriterInterface<float> { MEMALIGN(PLYWriter)
out <<
"ply\n"
"format ascii 1.0\n"
"comment written by tckconvert v" << App::library_version << "\n"
"comment written by tckconvert v" << App::mrtrix_version << "\n"
"comment part of the mtrix3 suite of tools (http://www.mrtrix.org/)\n"
"element vertex " << num_vertices << "\n"
"property float32 x\n"
Expand Down Expand Up @@ -552,7 +552,7 @@ RibWriter(const std::string& file, float radius = 0.1, bool dec = false) : out(f
out << "##RenderMan RIB\n"
<< "# Written by tckconvert\n"
<< "# Part of the MRtrix package (http://mrtrix.org)\n"
<< "# version: " << App::library_version << "\n";
<< "# version: " << App::mrtrix_version << "\n";

}

Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ elif system == 'darwin':
report ('OS X deployment target: ' + macosx_version + '\n')
cpp_flags += [ '-DMRTRIX_MACOSX', '-fPIC', '-mmacosx-version-min='+macosx_version ]
ld_flags += [ '-mmacosx-version-min='+macosx_version ]
ld_lib_flags += [ '-dynamiclib', '-install_name', '@rpath/LIBNAME', '-undefined', 'dynamic_lookup' ]
ld_lib_flags += [ '-dynamiclib', '-install_name', '@rpath/LIBNAME' ]
runpath = '-Wl,-rpath,@loader_path/'
lib_suffix = '.dylib'

Expand Down
21 changes: 11 additions & 10 deletions core/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ namespace MR
bool terminal_use_colour = true;

const char* project_version = nullptr;
const char* project_build_date = nullptr;
const char* executable_uses_mrtrix_version = nullptr;

int argc = 0;
const char* const* argv = nullptr;
extern const char* command_version;

bool overwrite_files = false;
void (*check_overwrite_files_func) (const std::string& name) = nullptr;
Expand Down Expand Up @@ -223,8 +224,8 @@ namespace MR
if (!format)
return std::string (NAME) + ": " + cmd_version;

std::string mrtrix_version_string = std::string("MRtrix ") + library_version;
std::string date (build_date);
std::string mrtrix_version_string = std::string("MRtrix ") + mrtrix_version;
std::string date (project_version ? project_build_date : build_date);

std::string topline = mrtrix_version_string +
std::string (std::max (1, 40-size(mrtrix_version_string)-size(App::NAME)/2), ' ') +
Expand Down Expand Up @@ -563,9 +564,9 @@ namespace MR
std::string version_string ()
{
std::string version =
"== " + App::NAME + " " + ( project_version ? project_version : library_version ) + " ==\n" +
"== " + App::NAME + " " + ( project_version ? project_version : mrtrix_version ) + " ==\n" +
str(8*sizeof (size_t)) + " bit " + MRTRIX_BUILD_TYPE + ", built " + build_date
+ ( project_version ? std::string(" against MRtrix ") + library_version : std::string("") )
+ ( project_version ? std::string(" against MRtrix ") + mrtrix_version : std::string("") )
+ ", using Eigen " + str(EIGEN_WORLD_VERSION) + "." + str(EIGEN_MAJOR_VERSION) + "." + str(EIGEN_MINOR_VERSION) + "\n"
"Author(s): " + AUTHOR + "\n" +
COPYRIGHT + "\n";
Expand Down Expand Up @@ -696,7 +697,7 @@ namespace MR
for (size_t i = 0; i < REFERENCES.size(); ++i)
s += indent_newlines (REFERENCES[i]) + "\n\n";
}
s += std::string("---\n\nMRtrix ") + library_version + ", built " + build_date + "\n\n"
s += std::string("---\n\nMRtrix ") + mrtrix_version + ", built " + build_date + "\n\n"
"\n\n**Author:** " + AUTHOR
+ "\n\n**Copyright:** " + COPYRIGHT + "\n\n";

Expand Down Expand Up @@ -1138,10 +1139,10 @@ namespace MR
NAME.erase (NAME.size()-4);
#endif

if (!project_version && strcmp (library_version, command_version) != 0) {
Exception E ("executable version does not match library!");
E.push_back (std::string(" ") + NAME + " version: " + command_version);
E.push_back (std::string(" library version: ") + library_version);
if (strcmp (mrtrix_version, executable_uses_mrtrix_version) != 0) {
Exception E ("executable was compiled for a different version of the MRtrix3 library!");
E.push_back (std::string(" ") + NAME + " version: " + executable_uses_mrtrix_version);
E.push_back (std::string(" library version: ") + mrtrix_version);
E.push_back ("Running ./build again may correct error");
throw E;
}
Expand Down
6 changes: 3 additions & 3 deletions core/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace MR
{


extern const char* library_version;
extern const char* mrtrix_version;
extern const char* build_date;
extern int log_level;
extern int exit_error_code;
extern std::string NAME;
Expand All @@ -51,7 +52,7 @@ namespace MR
extern const char* const* argv;

extern const char* project_version;
extern const char* build_date;
extern const char* project_build_date;


const char* argtype_description (ArgType type);
Expand All @@ -64,7 +65,6 @@ namespace MR




//! \addtogroup CmdParse
// @{

Expand Down
21 changes: 14 additions & 7 deletions core/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@


#include <xmmintrin.h>
#include "command_version.cpp"
#include "project_version.h"
#include "app.h"
#include "exec_version.h"
#ifdef MRTRIX_MODULE
namespace MR {
namespace App {
void set_project_version ();
}
}
#endif

#define MRTRIX_UPDATED_API

#ifdef MRTRIX_AS_R_LIBRARY

extern "C" void R_main (int* cmdline_argc, char** cmdline_argv)
{
#ifdef MRTRIX_PROJECT_VERSION
::MR::App::command_version = ::MR::App::project_version = MRTRIX_PROJECT_VERSION;
::MR::App::set_executable_uses_mrtrix_version();
#ifdef MRTRIX_MODULE
::MR::App::set_project_version();
#endif
SET_MRTRIX_PROJECT_VERSION
::MR::App::DESCRIPTION.clear();
::MR::App::ARGUMENTS.clear();
::MR::App::OPTIONS.clear();
Expand Down Expand Up @@ -75,8 +81,9 @@ int main (int cmdline_argc, char** cmdline_argv)
mxcsr |= (1<<6); // denormals-are-zero
_mm_setcsr (mxcsr);
#endif
#ifdef MRTRIX_PROJECT_VERSION
::MR::App::command_version = ::MR::App::project_version = MRTRIX_PROJECT_VERSION;
::MR::App::set_executable_uses_mrtrix_version();
#ifdef MRTRIX_MODULE
::MR::App::set_project_version();
#endif
try {
::MR::App::init (cmdline_argc, cmdline_argv);
Expand Down
2 changes: 1 addition & 1 deletion core/file/nifti1_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ namespace MR
NH.xyzt_units = SPACE_TIME_TO_XYZT (NIFTI_UNITS_MM, NIFTI_UNITS_SEC);

memset ((char*) &NH.descrip, 0, 80);
std::string version_string = std::string("MRtrix version: ") + App::library_version;
std::string version_string = std::string("MRtrix version: ") + App::mrtrix_version;
if (App::project_version)
version_string += std::string(", project version: ") + App::project_version;
strncpy ( (char*) &NH.descrip, version_string.c_str(), 79);
Expand Down
2 changes: 1 addition & 1 deletion core/file/nifti2_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ namespace MR
Raw::store<float64> (H.intensity_scale(), &NH.scl_slope, is_BE);
Raw::store<float64> (H.intensity_offset(), &NH.scl_inter, is_BE);

std::string version_string = std::string("MRtrix version: ") + App::library_version;
std::string version_string = std::string("MRtrix version: ") + App::mrtrix_version;
if (App::project_version)
version_string += std::string(", project version: ") + App::project_version;
strncpy ( (char*) &NH.descrip, version_string.c_str(), 79);
Expand Down
4 changes: 2 additions & 2 deletions core/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ namespace MR
try {
INFO ("creating image \"" + image_name + "\"...");

H.keyval()["mrtrix_version"] = App::library_version;
H.keyval()["mrtrix_version"] = App::mrtrix_version;
if (App::project_version)
H.keyval()["project_version"] = App::project_version;

std::string cmd = App::argv[0];
for (int n = 1; n < App::argc; ++n)
cmd += std::string(" \"") + App::argv[n] + "\"";
cmd += std::string (" (version=") + App::library_version;
cmd += std::string (" (version=") + App::mrtrix_version;
if (App::project_version)
cmd += std::string (", project=") + App::project_version;
cmd += ")";
Expand Down
14 changes: 7 additions & 7 deletions src/dwi/tractography/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace MR
class Properties : public std::map<std::string, std::string> { MEMALIGN(Properties)
public:

Properties () {
Properties () {
set_timestamp();
}

Expand All @@ -45,7 +45,7 @@ namespace MR
}

void set_version_info () {
(*this)["mrtrix_version"] = App::library_version;
(*this)["mrtrix_version"] = App::mrtrix_version;
if (App::project_version)
(*this)["project_version"] = App::project_version;
}
Expand All @@ -56,13 +56,13 @@ namespace MR
std::multimap<std::string, std::string> roi;


void clear () {
std::map<std::string, std::string>::clear();
void clear () {
std::map<std::string, std::string>::clear();
seeds.clear();
include.clear();
exclude.clear();
mask.clear();
comments.clear();
comments.clear();
roi.clear();
}

Expand All @@ -75,7 +75,7 @@ namespace MR
};


inline void check_timestamps (const Properties& a, const Properties& b, const std::string& type)
inline void check_timestamps (const Properties& a, const Properties& b, const std::string& type)
{
Properties::const_iterator stamp_a = a.find ("timestamp");
Properties::const_iterator stamp_b = b.find ("timestamp");
Expand All @@ -88,7 +88,7 @@ namespace MR



inline void check_counts (const Properties& a, const Properties& b, const std::string& type, bool abort_on_fail)
inline void check_counts (const Properties& a, const Properties& b, const std::string& type, bool abort_on_fail)
{
Properties::const_iterator count_a = a.find ("count");
Properties::const_iterator count_b = b.find ("count");
Expand Down
12 changes: 10 additions & 2 deletions src/command_version.h → src/exec_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,13 @@
* For more details, see http://www.mrtrix.org/
*/

// File intentionally left empty; build script is responsible for writing
// corresponding file src/command_version.cpp
#ifndef __exec_version_h__
#define __exec_version_h__

namespace MR {
namespace App {
void set_executable_uses_mrtrix_version ();
}
}

#endif
2 changes: 1 addition & 1 deletion src/gui/mrview/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ namespace MR
void Window::about_slot ()
{
std::string message =
std::string ("<h1>MRView</h1>The MRtrix viewer, version ") + MR::App::library_version + "<br>"
std::string ("<h1>MRView</h1>The MRtrix viewer, version ") + MR::App::mrtrix_version + "<br>"
"<em>" + str (8*sizeof (size_t)) + " bit "
#ifdef NDEBUG
"release"
Expand Down
17 changes: 0 additions & 17 deletions src/project_version.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/surface/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ namespace MR
if (binary) {

File::OFStream out (path, std::ios_base::binary | std::ios_base::out);
const std::string string = std::string ("mrtrix_version: ") + App::library_version;
const std::string string = std::string ("mrtrix_version: ") + App::mrtrix_version;
char header[80];
strncpy (header, string.c_str(), 80);
out.write (header, 80);
Expand Down Expand Up @@ -701,7 +701,7 @@ namespace MR
void Mesh::save_obj (const std::string& path) const
{
File::OFStream out (path);
out << "# mrtrix_version: " << App::library_version << "\n";
out << "# mrtrix_version: " << App::mrtrix_version << "\n";
out << "o " << name << "\n";
for (VertexList::const_iterator v = vertices.begin(); v != vertices.end(); ++v)
out << "v " << str((*v)[0]) << " " << str((*v)[1]) << " " << str((*v)[2]) << " 1.0\n";
Expand Down
Loading

0 comments on commit e571b4c

Please sign in to comment.