From 837c9afc4e0a891e85cbaef69aa1d1aaed11374e Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 15 Aug 2024 12:28:29 +0100 Subject: [PATCH] ECC-1904: API function to get the git branch --- CMakeLists.txt | 9 +++++++++ src/eccodes.cc | 5 +++++ src/eccodes.h | 1 + src/eccodes_prototypes.h | 1 + src/grib_api.h | 2 ++ src/grib_api_version.cc.in | 6 ++++++ tools/codes_info.cc | 1 + 7 files changed, 25 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 062da488a..48315d7cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -379,6 +379,15 @@ 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 + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" ) + ecbuild_info("ecCodes branch = ${eccodes_GIT_BRANCH}" ) +endif() + ############################################################################### # contents diff --git a/src/eccodes.cc b/src/eccodes.cc index 779690790..4dc7868b9 100644 --- a/src/eccodes.cc +++ b/src/eccodes.cc @@ -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(); diff --git a/src/eccodes.h b/src/eccodes.h index 0c8f7193c..2c5aff7e2 100644 --- a/src/eccodes.h +++ b/src/eccodes.h @@ -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); /** diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index e0582076d..80d383526 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -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 */ diff --git a/src/grib_api.h b/src/grib_api.h index 09601899f..cd035ea9b 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -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 * diff --git a/src/grib_api_version.cc.in b/src/grib_api_version.cc.in index 8fb7ea836..3f902f65a 100644 --- a/src/grib_api_version.cc.in +++ b/src/grib_api_version.cc.in @@ -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@"; diff --git a/tools/codes_info.cc b/tools/codes_info.cc index a73dcde14..17529017c 100644 --- a/tools/codes_info.cc +++ b/tools/codes_info.cc @@ -40,6 +40,7 @@ static void print_debug_info(grib_context* context) #ifdef HAVE_AEC aec = 1; #endif + grib_context_log(context, GRIB_LOG_DEBUG, "Git branch: %s", grib_get_git_branch()); grib_context_log(context, GRIB_LOG_DEBUG, "Git SHA1: %s", grib_get_git_sha1()); grib_context_log(context, GRIB_LOG_DEBUG, "Build date: %s", codes_get_build_date()); grib_context_log(context, GRIB_LOG_DEBUG, "Features:");