Skip to content

Commit

Permalink
packaging: add git commit info (#5049)
Browse files Browse the repository at this point in the history
* packaging: generate git commit info

Signed-off-by: Patrick Stephens <[email protected]>

* packaging: print git commit info

Signed-off-by: Patrick Stephens <[email protected]>

* packaging: print git commit info

Signed-off-by: Patrick Stephens <[email protected]>

* packaging: tidy up comments

Signed-off-by: Patrick Stephens <[email protected]>
  • Loading branch information
patrick-stephens authored Mar 14, 2022
1 parent 30a54ef commit f19daf1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.git
# We need the git commit info
# .git
build/**
dockerfiles/**
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ RUN apt-get update && \
curl \
ca-certificates \
cmake \
git \
make \
tar \
libssl-dev \
Expand Down
2 changes: 2 additions & 0 deletions include/fluent-bit/flb_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
FLB_VERSION_PATCH)
#define FLB_VERSION_STR "@FLB_VERSION_STR@"

#define FLB_GIT_HASH "@FLB_GIT_HASH@"

#endif
3 changes: 2 additions & 1 deletion src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 "
Expand Down

0 comments on commit f19daf1

Please sign in to comment.