Skip to content

Commit f79606b

Browse files
committed
Add version number to plugin
Like in linuxdeploy, it's always printed, so every log should contain a version number from now on.
1 parent e7cb179 commit f79606b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
find_package(Threads)
22

3+
# read Git revision ID
4+
# WARNING: this value will be stored in the CMake cache
5+
# to update it, you will have to reset the CMake cache
6+
# (doesn't matter for CI builds like Travis for instance, where there's no permanent CMake cache)
7+
execute_process(
8+
COMMAND git rev-parse --short HEAD
9+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
10+
OUTPUT_VARIABLE GIT_COMMIT
11+
OUTPUT_STRIP_TRAILING_WHITESPACE
12+
)
13+
14+
# set version and build number
15+
set(VERSION 1-alpha)
16+
if(DEFINED ENV{GITHUB_RUN_NUMBER})
17+
set(BUILD_NUMBER "GitHub actions build $ENV{GITHUB_RUN_NUMBER}")
18+
else()
19+
set(BUILD_NUMBER "<local dev build>")
20+
endif()
21+
22+
# get current date
23+
execute_process(
24+
COMMAND env LC_ALL=C date -u "+%Y-%m-%d %H:%M:%S %Z"
25+
OUTPUT_VARIABLE DATE
26+
OUTPUT_STRIP_TRAILING_WHITESPACE
27+
)
28+
329
# TODO: CMake <= 3.7 (at least!) doesn't allow for using OBJECT libraries with target_link_libraries
430
add_library(linuxdeploy-plugin-qt_util STATIC util.cpp util.h)
531
target_include_directories(linuxdeploy-plugin-qt_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
@@ -8,6 +34,12 @@ target_link_libraries(linuxdeploy-plugin-qt_util linuxdeploy_core args Threads::
834
add_executable(linuxdeploy-plugin-qt main.cpp qt-modules.h qml.cpp qml.h deployment.h)
935
target_link_libraries(linuxdeploy-plugin-qt linuxdeploy_core args nlohmann_json::nlohmann_json linuxdeploy-plugin-qt_util Threads::Threads)
1036
set_target_properties(linuxdeploy-plugin-qt PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
37+
target_compile_definitions(linuxdeploy-plugin-qt
38+
PRIVATE -DLD_GIT_COMMIT="${GIT_COMMIT}"
39+
PRIVATE -DLD_VERSION="${VERSION}"
40+
PRIVATE -DLD_BUILD_NUMBER="${BUILD_NUMBER}"
41+
PRIVATE -DLD_BUILD_DATE="${DATE}"
42+
)
1143

1244
if(STATIC_BUILD)
1345
message(WARNING "static builds enabled")

src/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ int main(const int argc, const char *const *const argv) {
4242
args::Flag pluginType(parser, "", "Print plugin type and exit", {"plugin-type"});
4343
args::Flag pluginApiVersion(parser, "", "Print plugin API version and exit", {"plugin-api-version"});
4444

45+
args::Flag printVersion(parser, "", "Print plugin version and exit", {"plugin-version"});
46+
4547
try {
4648
parser.ParseCLI(argc, argv);
4749
} catch (const args::ParseError &) {
@@ -59,6 +61,15 @@ int main(const int argc, const char *const *const argv) {
5961
return 0;
6062
}
6163

64+
// always show version statement
65+
std::cerr << "linuxdeploy-plugin-qt version " << LD_VERSION
66+
<< " (git commit ID " << LD_GIT_COMMIT << "), "
67+
<< LD_BUILD_NUMBER << " built on " << LD_BUILD_DATE << std::endl;
68+
69+
if (printVersion) {
70+
return 0;
71+
}
72+
6273
if (!appDirPath) {
6374
ldLog() << LD_ERROR << "--appdir parameter required" << std::endl;
6475
std::cout << std::endl << parser;

0 commit comments

Comments
 (0)