Show git SHA for command line parameter --version

This commit is contained in:
Magne Sjaastad 2024-02-27 12:10:19 +01:00 committed by GitHub
parent 672fbe177b
commit a0ecdf47a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 1 deletions

View File

@ -48,7 +48,7 @@ RiaApplication* createApplication( int& argc, char* argv[] )
{
for ( int i = 1; i < argc; ++i )
{
if ( !qstrcmp( argv[i], "--console" ) || !qstrcmp( argv[i], "--unittest" ) || !qstrcmp( argv[i], "--version" ) )
if ( !qstrcmp( argv[i], "--console" ) || !qstrcmp( argv[i], "--unittest" ) )
{
#ifdef ENABLE_GRPC
return new RiaGrpcConsoleApplication( argc, argv );

View File

@ -34,3 +34,5 @@
#define RESINSIGHT_OCTAVE_VERSION "@OCTAVE_VERSION_STRING@"
#define RESINSIGHT_PYTHON_VERSION "@Python3_VERSION@"
#define RESINSIGHT_GIT_HASH "@RESINSIGHT_GIT_HASH@"

View File

@ -131,6 +131,7 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments( gsl::n
if ( progOpt->option( "version" ) )
{
QString text = QString( STRPRODUCTVER ) + "\n";
text += "SHA " + QString( RESINSIGHT_GIT_HASH ) + "\n";
showFormattedTextInMessageBoxOrConsole( text );

View File

@ -463,6 +463,16 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}
if ( progOpt->option( "version" ) )
{
QString text = QString( STRPRODUCTVER ) + "\n";
text += "SHA " + QString( RESINSIGHT_GIT_HASH ) + "\n";
showFormattedTextInMessageBoxOrConsole( text );
return RiaApplication::ApplicationStatus::EXIT_COMPLETED;
}
// Code generation
// -----------------
if ( cvf::Option o = progOpt->option( "generate" ) )

View File

@ -324,6 +324,12 @@ set(CMAKE_CXX_COMPILER_LAUNCHER ${TEMP_CMAKE_CXX_COMPILER_LAUNCHER})
# ##############################################################################
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(
COMMAND git log -1 --pretty=format:%h
OUTPUT_VARIABLE RESINSIGHT_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)
# Update submodules as needed
option(RESINSIGHT_UPDATE_SUBMODULES "Check submodules during build" ON)
mark_as_advanced(RESINSIGHT_UPDATE_SUBMODULES)