ECC-1904: API function to get the git branch

This commit is contained in:
shahramn 2024-08-16 16:20:19 +01:00
parent 3b8edc3bbe
commit fa2b5ab3c3
7 changed files with 32 additions and 1 deletions

View File

@ -379,6 +379,16 @@ if( HAVE_FORTRAN AND CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_Fortr
ecbuild_add_fortran_flags("-fallow-argument-mismatch")
endif()
if(GIT_FOUND AND NOT ${GIT_EXECUTABLE} STREQUAL "")
ecbuild_info("Found git: ${GIT_EXECUTABLE} (found version \"${GIT_VERSION_STRING}\")")
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE eccodes_GIT_BRANCH
RESULT_VARIABLE nok ERROR_VARIABLE error
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" )
ecbuild_info("ecCodes branch = ${eccodes_GIT_BRANCH}" )
endif()
###############################################################################
# contents

View File

@ -28,6 +28,11 @@ const char* codes_get_git_sha1()
{
return grib_get_git_sha1();
}
const char* codes_get_git_branch()
{
return grib_get_git_branch();
}
const char* codes_get_package_name(void)
{
return grib_get_package_name();

View File

@ -1264,6 +1264,7 @@ long codes_get_api_version(void);
*/
const char* codes_get_git_sha1(void);
const char* codes_get_git_branch(void);
const char* codes_get_build_date(void);
/**

View File

@ -942,6 +942,7 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value,
/* grib_api_version.cc */
const char* grib_get_git_sha1(void);
const char* grib_get_git_branch(void);
const char* codes_get_build_date(void);
/* grib_bits_any_endian.cc */

View File

@ -1259,6 +1259,8 @@ long grib_get_api_version(void);
*/
const char* grib_get_git_sha1(void);
const char* grib_get_git_branch(void);
/**
* Get the package name
*

View File

@ -13,6 +13,12 @@ const char* grib_get_git_sha1(void)
{
return "@eccodes_GIT_SHA1@";
}
const char* grib_get_git_branch(void)
{
return "@eccodes_GIT_BRANCH@";
}
const char* codes_get_build_date(void)
{
return "@eccodes_BUILD_DATE@";

View File

@ -40,7 +40,13 @@ static void print_debug_info(grib_context* context)
#ifdef HAVE_AEC
aec = 1;
#endif
grib_context_log(context, GRIB_LOG_DEBUG, "Git SHA1: %s", grib_get_git_sha1());
const char* git_branch = grib_get_git_branch();
const char* git_sha1 = grib_get_git_sha1();
if (strlen(git_branch) > 0)
grib_context_log(context, GRIB_LOG_DEBUG, "Git branch: %s", git_branch);
if (strlen(git_sha1) > 0)
grib_context_log(context, GRIB_LOG_DEBUG, "Git SHA1: %s", git_sha1);
grib_context_log(context, GRIB_LOG_DEBUG, "Build date: %s", codes_get_build_date());
grib_context_log(context, GRIB_LOG_DEBUG, "Features:");
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_AEC=%d", aec);