From 44476241d101337d89bd9b7c88ec1280039d5167 Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Fri, 19 Jul 2024 13:22:22 -0700 Subject: [PATCH] Improve the logged version string and add clboss-status "info" The logged version now looks like: plugin-clboss: clboss v0.13.2 (v0.13.2-rc1-3-g44832e2) A new "info" chunk is added to clboss-status: "info": { "version": "v0.13.2", "git_commit_hash": "44832e2258069641a6149bdc90b7e5fc12219f77", "git_describe": "v0.13.2-rc1-3-g44832e2" }, --- .gitignore | 1 + Boss/Mod/Initiator.cpp | 22 ++++++++++++++++++++-- Makefile.am | 12 +++++++++++- generate_commit_hash.sh | 4 ++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100755 generate_commit_hash.sh diff --git a/.gitignore b/.gitignore index a1a812b..a129057 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ auxdir test_* !test_*.cpp !test_*.c +/commit_hash.h diff --git a/Boss/Mod/Initiator.cpp b/Boss/Mod/Initiator.cpp index e3ef223..c6735aa 100644 --- a/Boss/Mod/Initiator.cpp +++ b/Boss/Mod/Initiator.cpp @@ -1,3 +1,4 @@ +#include"commit_hash.h" #include"Boss/Mod/Initiator.hpp" #include"Boss/Mod/Rpc.hpp" #include"Boss/Msg/CommandRequest.hpp" @@ -7,6 +8,8 @@ #include"Boss/Msg/Init.hpp" #include"Boss/Msg/ManifestOption.hpp" #include"Boss/Msg/Option.hpp" +#include"Boss/Msg/ProvideStatus.hpp" +#include"Boss/Msg/SolicitStatus.hpp" #include"Boss/Signer.hpp" #include"Boss/log.hpp" #include"Ev/ThreadPool.hpp" @@ -144,6 +147,19 @@ public: { assert(open_rpc_socket); + bus.subscribe< Msg::SolicitStatus + >([this](Msg::SolicitStatus const&) { + auto info = Json::Out() + .start_object() + .field( "version", "v" + std::string(PACKAGE_VERSION) ) + .field( "git_commit_hash", std::string(GIT_COMMIT_HASH) ) + .field( "git_describe", std::string(GIT_DESCRIBE) ) + .end_object() + ; + return bus.raise(Msg::ProvideStatus{ + "info", std::move(info) + }); + }); bus.subscribe([this](Boss::Msg::CommandRequest const& c) { if (c.command != "init") return Ev::lift(); @@ -219,8 +235,10 @@ public: } return Boss::log( bus, Info - , "%s" - , PACKAGE_STRING + , "%s v%s (%s)" + , PACKAGE_NAME + , PACKAGE_VERSION + , GIT_DESCRIBE ) + std::move(pre_act) /* Now construct the RPC socket. */ diff --git a/Makefile.am b/Makefile.am index 4565aaa..c64ed4a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -566,7 +566,9 @@ EXTRA_DIST = \ reproducible/README.md \ reproducible/build.sh \ reproducible/continue.sh \ - reproducible/manifest.scm.template + reproducible/manifest.scm.template \ + generate_commit_hash.sh \ + commit_hash.h AM_CXXFLAGS = -Wall -Werror $(PTHREAD_CFLAGS) $(libev_CFLAGS) $(SQLITE3_CFLAGS) $(CURL_CFLAGS) $(CLBOSS_CXXFLAGS) LDADD = libclboss.la $(PTHREAD_LIBS) $(libev_LIBS) $(SQLITE3_LIBS) $(CURL_LIBS) @@ -668,3 +670,11 @@ CLEANFILES = $(noinst_SCRIPTS) create-tarball: create-tarball.in Makefile sed -e 's/[@]PACKAGE_VERSION[@]/$(PACKAGE_VERSION)/' < $(srcdir)/create-tarball.in > create-tarball chmod +x create-tarball + +BUILT_SOURCES = commit_hash.h +CLEANFILES += commit_hash.h + +commit_hash.h: + ./generate_commit_hash.sh + +clboss libclboss.la: $(BUILT_SOURCES) diff --git a/generate_commit_hash.sh b/generate_commit_hash.sh new file mode 100755 index 0000000..3568825 --- /dev/null +++ b/generate_commit_hash.sh @@ -0,0 +1,4 @@ +# generate_commit_hash.sh +echo "#pragma once" > commit_hash.h +echo "#define GIT_COMMIT_HASH \"$(git rev-parse HEAD)\"" >> commit_hash.h +echo "#define GIT_DESCRIBE \"$(git describe --tags --long --always --match=v*.* --dirty)\"" >> commit_hash.h