Skip to content

Commit

Permalink
ECC-1904: API function to get the git branch
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Aug 15, 2024
1 parent 14cdab4 commit 837c9af
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/eccodes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/eccodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
1 change: 1 addition & 0 deletions src/eccodes_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions src/grib_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
6 changes: 6 additions & 0 deletions src/grib_api_version.cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@";
Expand Down
1 change: 1 addition & 0 deletions tools/codes_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down

0 comments on commit 837c9af

Please sign in to comment.