Skip to content

Commit

Permalink
Print out commit info
Browse files Browse the repository at this point in the history
  • Loading branch information
nkh-lab committed May 5, 2023
1 parent 55efe73 commit 28dc181
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 9 deletions.
7 changes: 5 additions & 2 deletions app-cli/src/GetRelayWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

using namespace nkhlab::lightargparser;
using namespace nkhlab::cpputils;
using namespace nkhlab::usbrelaymodule::config;

namespace {
const char* kAllRelays = "";
Expand Down Expand Up @@ -97,7 +96,11 @@ bool GetRelayWorker::Run(int argc, char const** argv, std::string& out)
std::string GetRelayWorker::DoVersionText()
{
return StringHelper::Sprintf(
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch);
TextUserInterface::kVersion,
config::kProjectVerMajor,
config::kProjectVerMinor,
config::kProjectVerPatch,
config::kGitCommitHash);
}

std::string GetRelayWorker::DoHelpText()
Expand Down
3 changes: 2 additions & 1 deletion app-cli/src/SetRelayWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ std::string SetRelayWorker::DoVersionText()
TextUserInterface::kVersion,
config::kProjectVerMajor,
config::kProjectVerMinor,
config::kProjectVerPatch);
config::kProjectVerPatch,
config::kGitCommitHash);
}

std::string SetRelayWorker::DoHelpText()
Expand Down
3 changes: 2 additions & 1 deletion app-cli/src/TextUserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace appcli {
// clang-format off

const char* TextUserInterface::kVersion =
"v%d.%d.%d\n"
"Version: %d.%d.%d\n"
"Commit: %s\n"
"Copyright (C) 2023 https://github.com/nkh-lab\n"
"This is free software under GPL-3.0 license.\n";

Expand Down
4 changes: 2 additions & 2 deletions app-cli/tests/unit/GetRelayWorkerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST_F(GetRelayWorkerTest, VersionShortArg)
EXPECT_EQ(
out,
StringHelper::Sprintf(
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch));
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch, kGitCommitHash));
EXPECT_TRUE(ret);
}

Expand All @@ -113,7 +113,7 @@ TEST_F(GetRelayWorkerTest, VersionLongArg)
EXPECT_EQ(
out,
StringHelper::Sprintf(
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch));
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch, kGitCommitHash));
EXPECT_TRUE(ret);
}

Expand Down
4 changes: 2 additions & 2 deletions app-cli/tests/unit/SetRelayWorkerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TEST_F(SetRelayWorkerTest, VersionShortArg)
EXPECT_EQ(
out,
StringHelper::Sprintf(
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch));
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch, kGitCommitHash));
EXPECT_TRUE(ret);
}

Expand All @@ -93,7 +93,7 @@ TEST_F(SetRelayWorkerTest, VersionLongArg)
EXPECT_EQ(
out,
StringHelper::Sprintf(
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch));
TextUserInterface::kVersion, kProjectVerMajor, kProjectVerMinor, kProjectVerPatch, kGitCommitHash));
EXPECT_TRUE(ret);
}

Expand Down
7 changes: 6 additions & 1 deletion app-gui/src/widgets/WidgetAboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ constexpr char kProjectUrl[] = "https://github.com/nkh-lab/usb-relay-module";

constexpr char kAboutText[] =
"Version: %d.%d.%d\n"
"Commit: %s\n"
"\n"
"Copyright (C) 2023 https://github.com/nkh-lab\n"
"This is free software under GPL-3.0 license.\n";
Expand All @@ -45,7 +46,11 @@ WidgetAboutDialog::WidgetAboutDialog(wxWindow* parent)
this,
wxID_ANY,
StringHelper::Sprintf(
kAboutText, config::kProjectVerMajor, config::kProjectVerMinor, config::kProjectVerPatch));
kAboutText,
config::kProjectVerMajor,
config::kProjectVerMinor,
config::kProjectVerPatch,
config::kGitCommitHash));

wxButton* ok_btn = new wxButton(this, wxID_OK, "OK");

Expand Down
7 changes: 7 additions & 0 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

set(CONFIG_LIB "libusbrelaymodule-config")

execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

file(GLOB CFG_FILES "include/*.h.in")

foreach(CFG_FILE IN LISTS CFG_FILES)
Expand Down
1 change: 1 addition & 0 deletions config/include/Config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace config {
constexpr int kProjectVerMajor = @PROJECT_VERSION_MAJOR@;
constexpr int kProjectVerMinor = @PROJECT_VERSION_MINOR@;
constexpr int kProjectVerPatch = @PROJECT_VERSION_PATCH@;
constexpr char kGitCommitHash[] = "@GIT_COMMIT_HASH@";
// clang-format on

} // namespace config
Expand Down

0 comments on commit 28dc181

Please sign in to comment.