From 2c4c59684b0a2efcb7efce76acb4eaabfeddefcf Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 26 Jan 2018 13:18:01 +0100 Subject: [PATCH 1/8] "Fancy" version statement (C++ part) Also introduces a hint for users about the single quote parameters this tool provides, most other CLI tools use double quotes for non-single-char parameters. --- tools/linuxdeployqt/main.cpp | 88 +++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 32 deletions(-) diff --git a/tools/linuxdeployqt/main.cpp b/tools/linuxdeployqt/main.cpp index 2707cf6..afbc3e9 100644 --- a/tools/linuxdeployqt/main.cpp +++ b/tools/linuxdeployqt/main.cpp @@ -33,6 +33,7 @@ #include #include #include +#include int main(int argc, char **argv) { @@ -43,41 +44,61 @@ int main(int argc, char **argv) QString firstArgument = QString::fromLocal8Bit(argv[1]); - if (argc < 2 || firstArgument.startsWith("-")) { - qDebug() << "Usage: linuxdeployqt [options]"; - qDebug() << ""; - qDebug() << "Options:"; - qDebug() << " -verbose=<0-3> : 0 = no output, 1 = error/warning (default),"; - qDebug() << " 2 = normal, 3 = debug"; - qDebug() << " -no-plugins : Skip plugin deployment"; - qDebug() << " -appimage : Create an AppImage (implies -bundle-non-qt-libs)"; - qDebug() << " -no-strip : Don't run 'strip' on the binaries"; - qDebug() << " -bundle-non-qt-libs : Also bundle non-core, non-Qt libraries"; - qDebug() << " -executable= : Let the given executable use the deployed libraries"; - qDebug() << " too"; - qDebug() << " -qmldir= : Scan for QML imports in the given path"; - qDebug() << " -always-overwrite : Copy files even if the target file exists"; - qDebug() << " -qmake= : The qmake executable to use"; - qDebug() << " -no-translations : Skip deployment of translations."; - qDebug() << " -extra-plugins= : List of extra plugins which should be deployed,"; - qDebug() << " separated by comma."; - qDebug() << ""; - qDebug() << "linuxdeployqt takes an application as input and makes it"; - qDebug() << "self-contained by copying in the Qt libraries and plugins that"; - qDebug() << "the application uses."; - qDebug() << ""; - qDebug() << "By default it deploys the Qt instance that qmake on the $PATH points to."; - qDebug() << "The '-qmake' option can be used to point to the qmake executable"; - qDebug() << "to be used instead."; - qDebug() << ""; - qDebug() << "Plugins related to a Qt library are copied in with the library."; + // print version statement + std::stringstream version; + version << "linuxdeployqt " << LINUXDEPLOYQT_VERSION + << " (commit " << LINUXDEPLOYQT_GIT_COMMIT << "), " + << "build " << BUILD_NUMBER << " built on " << BUILD_DATE; + qInfo().noquote() << QString::fromStdString(version.str()); + + // due to the structure of the argument parser, we have to check all arguments at first to check whether the user + // wants to get the version only + // TODO: replace argument parser with position independent, less error prone version + for (int i = 0; i < argc; i++ ) { + QString argument = argv[i]; + if (argument == "-version" || argument == "-V" || argument == "--version") { + // can just exit normally, version has been printed above + return 0; + } + } + + if (argc < 2 || (firstArgument.startsWith("-"))) { + qInfo() << ""; + qInfo() << "Usage: linuxdeployqt [options]"; + qInfo() << ""; + qInfo() << "Options:"; + qInfo() << " -verbose=<0-3> : 0 = no output, 1 = error/warning (default),"; + qInfo() << " 2 = normal, 3 = debug"; + qInfo() << " -no-plugins : Skip plugin deployment"; + qInfo() << " -appimage : Create an AppImage (implies -bundle-non-qt-libs)"; + qInfo() << " -no-strip : Don't run 'strip' on the binaries"; + qInfo() << " -bundle-non-qt-libs : Also bundle non-core, non-Qt libraries"; + qInfo() << " -executable= : Let the given executable use the deployed libraries"; + qInfo() << " too"; + qInfo() << " -qmldir= : Scan for QML imports in the given path"; + qInfo() << " -always-overwrite : Copy files even if the target file exists"; + qInfo() << " -qmake= : The qmake executable to use"; + qInfo() << " -no-translations : Skip deployment of translations."; + qInfo() << " -extra-plugins= : List of extra plugins which should be deployed,"; + qInfo() << " separated by comma."; + qInfo() << " -version : Print version statement and exit."; + qInfo() << ""; + qInfo() << "linuxdeployqt takes an application as input and makes it"; + qInfo() << "self-contained by copying in the Qt libraries and plugins that"; + qInfo() << "the application uses."; + qInfo() << ""; + qInfo() << "By default it deploys the Qt instance that qmake on the $PATH points to."; + qInfo() << "The '-qmake' option can be used to point to the qmake executable"; + qInfo() << "to be used instead."; + qInfo() << ""; + qInfo() << "Plugins related to a Qt library are copied in with the library."; /* TODO: To be implemented qDebug() << "The accessibility, image formats, and text codec"; qDebug() << "plugins are always copied, unless \"-no-plugins\" is specified."; */ - qDebug() << ""; - qDebug() << "See the \"Deploying Applications on Linux\" topic in the"; - qDebug() << "documentation for more information about deployment on Linux."; + qInfo() << ""; + qInfo() << "See the \"Deploying Applications on Linux\" topic in the"; + qInfo() << "documentation for more information about deployment on Linux."; return 1; } @@ -389,8 +410,11 @@ int main(int argc, char **argv) } else if (argument.startsWith("-extra-plugins=")) { LogDebug() << "Argument found:" << argument; int index = argument.indexOf("="); - extraQtPlugins = QString(argument.mid(index+1)).split(","); + extraQtPlugins = QString(argument.mid(index + 1)).split(","); } else if (argument.startsWith("-")) { + LogError() << "Error: arguments must not start with --, only -" << "\n"; + return 1; + } else { LogError() << "Unknown argument" << argument << "\n"; return 1; } From 84a7f6b37fe09a098bb11d5d252cf4a615319a51 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 26 Jan 2018 13:18:39 +0100 Subject: [PATCH 2/8] "Fancy" version statement (CMake part) --- CMakeLists.txt | 48 ++++++++++++++++++++++++++++++ tools/linuxdeployqt/CMakeLists.txt | 6 ++++ 2 files changed, 54 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e75be4..4e1f593 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,4 +5,52 @@ cmake_minimum_required(VERSION 3.2) project(linuxdeployqt) +# read Git revision ID +execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +# make sure Git revision ID and latest tag is not stored in the CMake cache +# otherwise, one would have to reset the CMake cache on every new commit to make sure the Git commit ID is up to date +unset(GIT_COMMIT CACHE) +unset(GIT_LATEST_TAG CACHE) + +# read Git revision ID and latest tag number +execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND git rev-list --tags --skip=1 --max-count=1 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_TAG_ID + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND git describe --tags ${GIT_TAG_ID} --abbrev=0 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_TAG_NAME + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +# set version and build number +set(VERSION 1-alpha) +if("$ENV{TRAVIS_BUILD_NUMBER}" STREQUAL "") + set(BUILD_NUMBER "") +else() + set(BUILD_NUMBER "$ENV{TRAVIS_BUILD_NUMBER}") +endif() + +# get current date +execute_process( + COMMAND env LC_ALL=C date -u "+%Y-%m-%d %H:%M:%S %Z" + OUTPUT_VARIABLE DATE + OUTPUT_STRIP_TRAILING_WHITESPACE +) + add_subdirectory(tools/linuxdeployqt) diff --git a/tools/linuxdeployqt/CMakeLists.txt b/tools/linuxdeployqt/CMakeLists.txt index 9c9b81c..8a6c204 100644 --- a/tools/linuxdeployqt/CMakeLists.txt +++ b/tools/linuxdeployqt/CMakeLists.txt @@ -1,5 +1,11 @@ set(CMAKE_AUTOMOC ON) +# expose version data as compiler definition +add_definitions("-DLINUXDEPLOYQT_VERSION=\"${GIT_TAG_NAME}\"") +add_definitions("-DLINUXDEPLOYQT_GIT_COMMIT=\"${GIT_COMMIT}\"") +add_definitions("-DBUILD_DATE=\"${DATE}\"") +add_definitions("-DBUILD_NUMBER=\"${BUILD_NUMBER}\"") + find_package(Qt5 REQUIRED COMPONENTS Core) add_executable(linuxdeployqt main.cpp shared.cpp) From b3d31bbc8449c666501144e95dfb55dea0a29b04 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 26 Jan 2018 20:37:38 +0100 Subject: [PATCH 3/8] "Fancy" version statement (qmake part) After some highly annoying and time consuming tinkering with quotes and escaping, the embedding of versioning data seems to work as intended now. --- tools/linuxdeployqt/linuxdeployqt.pro | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/linuxdeployqt/linuxdeployqt.pro b/tools/linuxdeployqt/linuxdeployqt.pro index 26f115e..f131a11 100644 --- a/tools/linuxdeployqt/linuxdeployqt.pro +++ b/tools/linuxdeployqt/linuxdeployqt.pro @@ -15,3 +15,19 @@ SOURCES += main.cpp \ shared.cpp DEFINES -= QT_USE_QSTRINGBUILDER #leads to compile errors if not disabled + +# versioning +# don't break the quotes -- at the moment, the shell commands are injected into the Makefile to have them run on every +# build and not during configure time + +DEFINES += LINUXDEPLOYQT_GIT_COMMIT="'\"$(shell git rev-parse --short HEAD)\"'" + +DEFINES += BUILD_DATE="'\"$(shell env LC_ALL=C date -u '+%Y-%m-%d %H:%M:%S %Z')\"'" + +equals($$(TRAVIS_BUILD_NUMBER), "") { + DEFINES += BUILD_NUMBER="'\"\"'" +} else { + DEFINES += BUILD_NUMBER="'\"$$(TRAVIS_BUILD_NUMBER)\"'" +} + +DEFINES += LINUXDEPLOYQT_VERSION="'\"$(shell git describe --tags $(shell git rev-list --tags --skip=1 --max-count=1) --abbrev=0)\"'" From b244e57d57f5fe549853645a0a9c32094039349e Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 26 Jan 2018 21:35:33 +0100 Subject: [PATCH 4/8] Try to fetch tags for versioning --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index f51440c..8e71d71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,10 @@ env: before_install: - ./tests/tests-environment.sh +before_script: + # populate tags + - git fetch --tags + script: - ./tests/tests-ci.sh From 4caf6aa00b10207db9f8d4d10bc943f17ddf9f49 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 26 Jan 2018 21:40:34 +0100 Subject: [PATCH 5/8] Try to fetch tags for versioning, mk. 2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8e71d71..e5c46e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_install: before_script: # populate tags - - git fetch --tags + - git fetch origin script: - ./tests/tests-ci.sh From 28c98dd72badb985ad3ff4783a871cbf51836008 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 26 Jan 2018 21:48:30 +0100 Subject: [PATCH 6/8] Try to fetch tags for versioning, mk. 3 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e5c46e0..dee1820 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,8 @@ before_install: before_script: # populate tags - git fetch origin + - git rev-list --tags --skip=1 --max-count=1 + - git describe --tags $(git rev-list --tags --skip=1 --max-count=1) --abbrev=0 script: - ./tests/tests-ci.sh From d28481c8126a692316127c526befc2c6a270c709 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 26 Jan 2018 21:53:58 +0100 Subject: [PATCH 7/8] Try to fetch tags for versioning, mk. 4 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dee1820..f35de57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ before_install: before_script: # populate tags - git fetch origin + - git fetch --unshallow - git rev-list --tags --skip=1 --max-count=1 - git describe --tags $(git rev-list --tags --skip=1 --max-count=1) --abbrev=0 From f0c58d56b96f17569d0ed56b69443965ede59914 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 26 Jan 2018 22:02:32 +0100 Subject: [PATCH 8/8] Try to fetch tags for versioning, mk. 5 --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f35de57..4ff221e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,8 @@ before_install: - ./tests/tests-environment.sh before_script: - # populate tags - - git fetch origin + # fetch all tags - git fetch --unshallow - - git rev-list --tags --skip=1 --max-count=1 - - git describe --tags $(git rev-list --tags --skip=1 --max-count=1) --abbrev=0 script: - ./tests/tests-ci.sh