Add methods for accessing the git commit used when compiling

This commit is contained in:
Ray Speth 2017-01-20 18:26:53 -05:00
parent 17c1f9dc14
commit 8e89bbb8d2
12 changed files with 51 additions and 4 deletions

View file

@ -667,6 +667,11 @@ ctversion = StrictVersion(env['cantera_version'])
env['cantera_pure_version'] = '.'.join(str(x) for x in ctversion.version)
env['cantera_short_version'] = '.'.join(str(x) for x in ctversion.version[:2])
try:
env['git_commit'] = getCommandOutput('git', 'rev-parse', '--short', 'HEAD')
except OSError:
env['git_commit'] = '<unknown>'
# Print values of all build options:
print "Configuration variables read from 'cantera.conf' and command line:"
for line in open('cantera.conf'):

View file

@ -213,7 +213,8 @@ if localenv['sphinx_docs']:
'Hydrogen.m', 'Methane.m', 'Nitrogen.m', 'oneatm.m',
'Oxygen.m', 'Water.m'],
'@Utilities': ['adddir.m', 'ck2cti.m', 'cleanup.m', 'geterr.m',
'getDataDirectories.m', 'canteraVersion.m']
'getDataDirectories.m', 'canteraVersion.m',
'canteraGitCommit.m']
}
# These files do not need to be documented in the MATLAB classes because they

View file

@ -129,6 +129,9 @@ void appdelete();
//! @copydoc Application::thread_complete
void thread_complete();
//! Returns the hash of the git commit from which Cantera was compiled, if known
std::string gitCommit();
//! Returns root directory where %Cantera is installed
/*!
* @returns a string containing the name of the base directory where %Cantera is

View file

@ -157,6 +157,7 @@ extern "C" {
CANTERA_CAPI int ct_addCanteraDirectory(size_t buflen, const char* buf);
CANTERA_CAPI int ct_getDataDirectories(int buflen, char* buf, const char* sep);
CANTERA_CAPI int ct_getCanteraVersion(int buflen, char* buf);
CANTERA_CAPI int ct_getGitCommit(int buflen, char* buf);
CANTERA_CAPI int ct_suppress_thermo_warnings(int suppress);
CANTERA_CAPI int ct_clearStorage();

View file

@ -2,7 +2,7 @@
# at http://www.cantera.org/license.txt for license and copyright information.
from ._cantera import *
from ._cantera import __version__, __sundials_version__
from ._cantera import __version__, __sundials_version__, __git_commit__
from .composite import *
from .liquidvapor import *
from .onedim import *

View file

@ -54,6 +54,7 @@ cdef extern from "cantera/base/global.h" namespace "Cantera":
cdef XML_Node* CxxGetXmlFromString "Cantera::get_XML_from_string" (string) except +translate_exception
cdef void Cxx_make_deprecation_warnings_fatal "Cantera::make_deprecation_warnings_fatal" ()
cdef void Cxx_suppress_thermo_warnings "Cantera::suppress_thermo_warnings" (cbool)
cdef string CxxGitCommit "Cantera::gitCommit" ()
cdef extern from "<memory>":
cppclass shared_ptr "std::shared_ptr" [T]:

View file

@ -40,6 +40,8 @@ __sundials_version__ = '.'.join(str(get_sundials_version()))
__version__ = pystr(get_cantera_version())
__git_commit__ = pystr(CxxGitCommit())
def appdelete():
""" Delete all global Cantera C++ objects """
CxxAppdelete()

View file

@ -12,14 +12,20 @@ def applicationSetup(env, subdir, extensions):
env.Append(CPPDEFINES={'CANTERA_DATA': escaped_datadir})
return defaultSetup(env, subdir, extensions)
def globalSetup(env, subdir, extensions):
# Add #define variables unique to global.cpp
env.Append(CPPDEFINES={'GIT_COMMIT': '\\"{0}\\"'.format(env['git_commit'])})
return defaultSetup(env, subdir, extensions)
def baseSetup(env, subdir, extensions):
# All files in base except for application.cpp
return [f for f in defaultSetup(env, subdir, extensions)
if f.name != 'application.cpp']
if f.name != 'application.cpp' and f.name != 'global.cpp']
# (subdir, (file extensions), (extra setup(env)))
libs = [('base', ['cpp'], baseSetup),
('base', ['^application.cpp'], applicationSetup),
('base', ['^global.cpp'], globalSetup),
('thermo', ['cpp'], defaultSetup),
('tpx', ['cpp'], defaultSetup),
('equil', ['cpp','c'], defaultSetup),

View file

@ -93,6 +93,15 @@ void thread_complete()
app()->thread_complete();
}
std::string gitCommit()
{
#ifdef GIT_COMMIT
return GIT_COMMIT;
#else
return "unknown";
#endif
}
XML_Node* get_XML_File(const std::string& file, int debug)
{
return app()->get_XML_File(file, debug);

View file

@ -1428,6 +1428,15 @@ extern "C" {
}
}
int ct_getGitCommit(int buflen, char* buf)
{
try {
return copyString(gitCommit(), buf, buflen);
} catch (...) {
return handleAllExceptions(-1, ERR);
}
}
int ct_suppress_thermo_warnings(int suppress)
{
try {

View file

@ -98,6 +98,14 @@ void ctfunctions(int nlhs, mxArray* plhs[],
plhs[0] = mxCreateString(output_buf);
return;
// get cantera git commit
case 7:
buflen = ct_getGitCommit(0, 0);
output_buf = (char*)mxCalloc(buflen, sizeof(char));
iok = ct_getGitCommit(buflen, output_buf);
plhs[0] = mxCreateString(output_buf);
return;
default:
mexErrMsgTxt("ctfunctions: unknown job");
}

View file

@ -72,7 +72,9 @@ class TestResult(unittest.TextTestResult):
if __name__ == '__main__':
print('\n* INFO: using Cantera module found at this location:')
print('* ', repr(cantera.__file__), '\n')
print('* ', repr(cantera.__file__))
print('* INFO: Cantera version:', cantera.__version__)
print('* INFO: Git commit:', cantera.__git_commit__, '\n')
sys.stdout.flush()
loader = unittest.TestLoader()