Skip to content

Commit e0ae780

Browse files
authored
Merge pull request #226 from probonopd/TheAssassin/version-statement
Implement "fancy" version statement
2 parents 2d96719 + f0c58d5 commit e0ae780

File tree

5 files changed

+130
-32
lines changed

5 files changed

+130
-32
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ env:
1111
before_install:
1212
- ./tests/tests-environment.sh
1313

14+
before_script:
15+
# fetch all tags
16+
- git fetch --unshallow
17+
1418
script:
1519
- ./tests/tests-ci.sh
1620

CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,52 @@ cmake_minimum_required(VERSION 3.2)
55

66
project(linuxdeployqt)
77

8+
# read Git revision ID
9+
execute_process(
10+
COMMAND git rev-parse --short HEAD
11+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
12+
OUTPUT_VARIABLE GIT_COMMIT
13+
OUTPUT_STRIP_TRAILING_WHITESPACE
14+
)
15+
16+
# make sure Git revision ID and latest tag is not stored in the CMake cache
17+
# otherwise, one would have to reset the CMake cache on every new commit to make sure the Git commit ID is up to date
18+
unset(GIT_COMMIT CACHE)
19+
unset(GIT_LATEST_TAG CACHE)
20+
21+
# read Git revision ID and latest tag number
22+
execute_process(
23+
COMMAND git rev-parse --short HEAD
24+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
25+
OUTPUT_VARIABLE GIT_COMMIT
26+
OUTPUT_STRIP_TRAILING_WHITESPACE
27+
)
28+
execute_process(
29+
COMMAND git rev-list --tags --skip=1 --max-count=1
30+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
31+
OUTPUT_VARIABLE GIT_TAG_ID
32+
OUTPUT_STRIP_TRAILING_WHITESPACE
33+
)
34+
execute_process(
35+
COMMAND git describe --tags ${GIT_TAG_ID} --abbrev=0
36+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
37+
OUTPUT_VARIABLE GIT_TAG_NAME
38+
OUTPUT_STRIP_TRAILING_WHITESPACE
39+
)
40+
41+
# set version and build number
42+
set(VERSION 1-alpha)
43+
if("$ENV{TRAVIS_BUILD_NUMBER}" STREQUAL "")
44+
set(BUILD_NUMBER "<local dev build>")
45+
else()
46+
set(BUILD_NUMBER "$ENV{TRAVIS_BUILD_NUMBER}")
47+
endif()
48+
49+
# get current date
50+
execute_process(
51+
COMMAND env LC_ALL=C date -u "+%Y-%m-%d %H:%M:%S %Z"
52+
OUTPUT_VARIABLE DATE
53+
OUTPUT_STRIP_TRAILING_WHITESPACE
54+
)
55+
856
add_subdirectory(tools/linuxdeployqt)

tools/linuxdeployqt/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
set(CMAKE_AUTOMOC ON)
22

3+
# expose version data as compiler definition
4+
add_definitions("-DLINUXDEPLOYQT_VERSION=\"${GIT_TAG_NAME}\"")
5+
add_definitions("-DLINUXDEPLOYQT_GIT_COMMIT=\"${GIT_COMMIT}\"")
6+
add_definitions("-DBUILD_DATE=\"${DATE}\"")
7+
add_definitions("-DBUILD_NUMBER=\"${BUILD_NUMBER}\"")
8+
39
find_package(Qt5 REQUIRED COMPONENTS Core)
410

511
add_executable(linuxdeployqt main.cpp shared.cpp)

tools/linuxdeployqt/linuxdeployqt.pro

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ SOURCES += main.cpp \
1515
shared.cpp
1616

1717
DEFINES -= QT_USE_QSTRINGBUILDER #leads to compile errors if not disabled
18+
19+
# versioning
20+
# don't break the quotes -- at the moment, the shell commands are injected into the Makefile to have them run on every
21+
# build and not during configure time
22+
23+
DEFINES += LINUXDEPLOYQT_GIT_COMMIT="'\"$(shell git rev-parse --short HEAD)\"'"
24+
25+
DEFINES += BUILD_DATE="'\"$(shell env LC_ALL=C date -u '+%Y-%m-%d %H:%M:%S %Z')\"'"
26+
27+
equals($$(TRAVIS_BUILD_NUMBER), "") {
28+
DEFINES += BUILD_NUMBER="'\"<local dev build>\"'"
29+
} else {
30+
DEFINES += BUILD_NUMBER="'\"$$(TRAVIS_BUILD_NUMBER)\"'"
31+
}
32+
33+
DEFINES += LINUXDEPLOYQT_VERSION="'\"$(shell git describe --tags $(shell git rev-list --tags --skip=1 --max-count=1) --abbrev=0)\"'"

tools/linuxdeployqt/main.cpp

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <stdlib.h>
3434
#include <QSettings>
3535
#include <QDirIterator>
36+
#include <sstream>
3637

3738
int main(int argc, char **argv)
3839
{
@@ -43,41 +44,61 @@ int main(int argc, char **argv)
4344

4445
QString firstArgument = QString::fromLocal8Bit(argv[1]);
4546

46-
if (argc < 2 || firstArgument.startsWith("-")) {
47-
qDebug() << "Usage: linuxdeployqt <app-binary|desktop file> [options]";
48-
qDebug() << "";
49-
qDebug() << "Options:";
50-
qDebug() << " -verbose=<0-3> : 0 = no output, 1 = error/warning (default),";
51-
qDebug() << " 2 = normal, 3 = debug";
52-
qDebug() << " -no-plugins : Skip plugin deployment";
53-
qDebug() << " -appimage : Create an AppImage (implies -bundle-non-qt-libs)";
54-
qDebug() << " -no-strip : Don't run 'strip' on the binaries";
55-
qDebug() << " -bundle-non-qt-libs : Also bundle non-core, non-Qt libraries";
56-
qDebug() << " -executable=<path> : Let the given executable use the deployed libraries";
57-
qDebug() << " too";
58-
qDebug() << " -qmldir=<path> : Scan for QML imports in the given path";
59-
qDebug() << " -always-overwrite : Copy files even if the target file exists";
60-
qDebug() << " -qmake=<path> : The qmake executable to use";
61-
qDebug() << " -no-translations : Skip deployment of translations.";
62-
qDebug() << " -extra-plugins=<list> : List of extra plugins which should be deployed,";
63-
qDebug() << " separated by comma.";
64-
qDebug() << "";
65-
qDebug() << "linuxdeployqt takes an application as input and makes it";
66-
qDebug() << "self-contained by copying in the Qt libraries and plugins that";
67-
qDebug() << "the application uses.";
68-
qDebug() << "";
69-
qDebug() << "By default it deploys the Qt instance that qmake on the $PATH points to.";
70-
qDebug() << "The '-qmake' option can be used to point to the qmake executable";
71-
qDebug() << "to be used instead.";
72-
qDebug() << "";
73-
qDebug() << "Plugins related to a Qt library are copied in with the library.";
47+
// print version statement
48+
std::stringstream version;
49+
version << "linuxdeployqt " << LINUXDEPLOYQT_VERSION
50+
<< " (commit " << LINUXDEPLOYQT_GIT_COMMIT << "), "
51+
<< "build " << BUILD_NUMBER << " built on " << BUILD_DATE;
52+
qInfo().noquote() << QString::fromStdString(version.str());
53+
54+
// due to the structure of the argument parser, we have to check all arguments at first to check whether the user
55+
// wants to get the version only
56+
// TODO: replace argument parser with position independent, less error prone version
57+
for (int i = 0; i < argc; i++ ) {
58+
QString argument = argv[i];
59+
if (argument == "-version" || argument == "-V" || argument == "--version") {
60+
// can just exit normally, version has been printed above
61+
return 0;
62+
}
63+
}
64+
65+
if (argc < 2 || (firstArgument.startsWith("-"))) {
66+
qInfo() << "";
67+
qInfo() << "Usage: linuxdeployqt <app-binary|desktop file> [options]";
68+
qInfo() << "";
69+
qInfo() << "Options:";
70+
qInfo() << " -verbose=<0-3> : 0 = no output, 1 = error/warning (default),";
71+
qInfo() << " 2 = normal, 3 = debug";
72+
qInfo() << " -no-plugins : Skip plugin deployment";
73+
qInfo() << " -appimage : Create an AppImage (implies -bundle-non-qt-libs)";
74+
qInfo() << " -no-strip : Don't run 'strip' on the binaries";
75+
qInfo() << " -bundle-non-qt-libs : Also bundle non-core, non-Qt libraries";
76+
qInfo() << " -executable=<path> : Let the given executable use the deployed libraries";
77+
qInfo() << " too";
78+
qInfo() << " -qmldir=<path> : Scan for QML imports in the given path";
79+
qInfo() << " -always-overwrite : Copy files even if the target file exists";
80+
qInfo() << " -qmake=<path> : The qmake executable to use";
81+
qInfo() << " -no-translations : Skip deployment of translations.";
82+
qInfo() << " -extra-plugins=<list> : List of extra plugins which should be deployed,";
83+
qInfo() << " separated by comma.";
84+
qInfo() << " -version : Print version statement and exit.";
85+
qInfo() << "";
86+
qInfo() << "linuxdeployqt takes an application as input and makes it";
87+
qInfo() << "self-contained by copying in the Qt libraries and plugins that";
88+
qInfo() << "the application uses.";
89+
qInfo() << "";
90+
qInfo() << "By default it deploys the Qt instance that qmake on the $PATH points to.";
91+
qInfo() << "The '-qmake' option can be used to point to the qmake executable";
92+
qInfo() << "to be used instead.";
93+
qInfo() << "";
94+
qInfo() << "Plugins related to a Qt library are copied in with the library.";
7495
/* TODO: To be implemented
7596
qDebug() << "The accessibility, image formats, and text codec";
7697
qDebug() << "plugins are always copied, unless \"-no-plugins\" is specified.";
7798
*/
78-
qDebug() << "";
79-
qDebug() << "See the \"Deploying Applications on Linux\" topic in the";
80-
qDebug() << "documentation for more information about deployment on Linux.";
99+
qInfo() << "";
100+
qInfo() << "See the \"Deploying Applications on Linux\" topic in the";
101+
qInfo() << "documentation for more information about deployment on Linux.";
81102

82103
return 1;
83104
}
@@ -389,8 +410,11 @@ int main(int argc, char **argv)
389410
} else if (argument.startsWith("-extra-plugins=")) {
390411
LogDebug() << "Argument found:" << argument;
391412
int index = argument.indexOf("=");
392-
extraQtPlugins = QString(argument.mid(index+1)).split(",");
413+
extraQtPlugins = QString(argument.mid(index + 1)).split(",");
393414
} else if (argument.startsWith("-")) {
415+
LogError() << "Error: arguments must not start with --, only -" << "\n";
416+
return 1;
417+
} else {
394418
LogError() << "Unknown argument" << argument << "\n";
395419
return 1;
396420
}

0 commit comments

Comments
 (0)