From f19daf1ada04fbc7226c8e9d8a77dd4973ae1eb2 Mon Sep 17 00:00:00 2001 From: Pat Date: Mon, 14 Mar 2022 15:02:45 +0000 Subject: [PATCH] packaging: add git commit info (#5049) * packaging: generate git commit info Signed-off-by: Patrick Stephens * packaging: print git commit info Signed-off-by: Patrick Stephens * packaging: print git commit info Signed-off-by: Patrick Stephens * packaging: tidy up comments Signed-off-by: Patrick Stephens --- .dockerignore | 3 ++- CMakeLists.txt | 12 ++++++++++++ dockerfiles/Dockerfile | 1 + include/fluent-bit/flb_version.h.in | 2 ++ src/fluent-bit.c | 3 ++- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 1da2076e4af..6b6ee2dfb3e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ -.git +# We need the git commit info +# .git build/** dockerfiles/** diff --git a/CMakeLists.txt b/CMakeLists.txt index 186ce0cb1c4..0414bd99648 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -317,6 +317,18 @@ if(CMAKE_SYSTEM_NAME MATCHES "Darwin") endif() endif() +# Extract Git commit information for debug output. +# Note that this is only set when cmake is run, the intent here is to use in CI for verification of releases so is acceptable. +# For a better solution see https://jonathanhamberg.com/post/cmake-embedding-git-hash/ but this is simple and easy. +find_package(Git) +# If we do not have Git or this is not a Git repo or another error this just is ignored and we have no output at runtime. +execute_process(COMMAND + "${GIT_EXECUTABLE}" log -1 --format=%H + WORKING_DIRECTORY "${FLB_ROOT}" + OUTPUT_VARIABLE FLB_GIT_HASH + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) +message(STATUS "Git hash: ${FLB_GIT_HASH}") + # Optional features like Stream Processor and Record Accessor needs Flex # and Bison to generate it parsers. find_package(FLEX 2) diff --git a/dockerfiles/Dockerfile b/dockerfiles/Dockerfile index b432e309e65..6b18d744063 100644 --- a/dockerfiles/Dockerfile +++ b/dockerfiles/Dockerfile @@ -38,6 +38,7 @@ RUN apt-get update && \ curl \ ca-certificates \ cmake \ + git \ make \ tar \ libssl-dev \ diff --git a/include/fluent-bit/flb_version.h.in b/include/fluent-bit/flb_version.h.in index e07267ebe5b..027e192fe43 100644 --- a/include/fluent-bit/flb_version.h.in +++ b/include/fluent-bit/flb_version.h.in @@ -33,4 +33,6 @@ FLB_VERSION_PATCH) #define FLB_VERSION_STR "@FLB_VERSION_STR@" +#define FLB_GIT_HASH "@FLB_GIT_HASH@" + #endif diff --git a/src/fluent-bit.c b/src/fluent-bit.c index 01842639e21..bbef7339623 100644 --- a/src/fluent-bit.c +++ b/src/fluent-bit.c @@ -97,6 +97,7 @@ static void flb_version() #else printf("Fluent Bit v%s\n", FLB_VERSION_STR); #endif + printf("Git commit: %s\n", FLB_GIT_HASH); exit(EXIT_SUCCESS); } @@ -111,7 +112,7 @@ static void flb_banner() fprintf(stderr, "%sFluent Bit v%s%s\n", ANSI_BOLD, FLB_VERSION_STR, ANSI_RESET); #endif - + fprintf(stderr, "* Git commit: %s\n", FLB_GIT_HASH); fprintf(stderr, "* %sCopyright (C) 2015-2021 The Fluent Bit Authors%s\n", ANSI_BOLD ANSI_YELLOW, ANSI_RESET); fprintf(stderr, "* Fluent Bit is a CNCF sub-project under the "