Skip to content

Commit

Permalink
Clean and android support
Browse files Browse the repository at this point in the history
  • Loading branch information
dragly committed Oct 30, 2016
1 parent 4feebba commit 684597b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
48 changes: 33 additions & 15 deletions CuteVersioning.pri
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
# Find git install
win32 {
GIT_BIN = $$system(where git)
CUTEVERSIONING_GIT_BIN = $$system(where git)
}
unix|max {
GIT_BIN = $$system(which git)
CUTEVERSIONING_GIT_BIN = $$system(which git)
}

GIT_LATEST_TAG = "git-not-found"
GIT_DESCRIPTION = "git-not-found"
GIT_DIRTY = true
CUTEVERSIONING_GIT_LATEST_TAG = "git-not-found"
CUTEVERSIONING_GIT_DESCRIPTION = "git-not-found"
CUTEVERSIONING_GIT_DIRTY = true

!isEmpty(GIT_BIN) {
GIT_LATEST_TAG = $$system(git --git-dir $$GIT_DIR --work-tree $$GIT_WORK_TREE describe --always --tags --abbrev=0)
GIT_DESCRIPTION = $$system(git --git-dir $$GIT_DIR --work-tree $$GIT_WORK_TREE describe --always --tags --long)
GIT_STATUS = $$system(git --git-dir $$GIT_DIR --work-tree $$GIT_WORK_TREE status --porcelain --untracked-files=no)
isEmpty(GIT_STATUS) {
GIT_DIRTY=false
# If git is found, run git describe
!isEmpty(CUTEVERSIONING_GIT_BIN) {
CUTEVERSIONING_GIT_LATEST_TAG = $$system(git --git-dir $$CUTEVERSIONING_GIT_DIR --work-tree $$CUTEVERSIONING_GIT_WORK_TREE describe --always --tags --abbrev=0)
CUTEVERSIONING_GIT_DESCRIPTION = $$system(git --git-dir $$CUTEVERSIONING_GIT_DIR --work-tree $$CUTEVERSIONING_GIT_WORK_TREE describe --always --tags --long)
CUTEVERSIONING_GIT_STATUS = $$system(git --git-dir $$CUTEVERSIONING_GIT_DIR --work-tree $$CUTEVERSIONING_GIT_WORK_TREE status --porcelain --untracked-files=no)
isEmpty(CUTEVERSIONING_GIT_STATUS) {
CUTEVERSIONING_GIT_DIRTY=false
}
}

# Write header file
HEADER_OUTPUT = \
"$${LITERAL_HASH}include <QString>"\
"$${LITERAL_HASH}include <QVersionNumber>"\
""\
"namespace CuteVersioning {"\
"const QString latestTag = \"$${GIT_LATEST_TAG}\";"\
"const QString identifier = \"$${GIT_DESCRIPTION}\";"\
"const bool dirty = $${GIT_DIRTY};"\
"const QString latestTag = \"$${CUTEVERSIONING_GIT_LATEST_TAG}\";"\
"const QString identifier = \"$${CUTEVERSIONING_GIT_DESCRIPTION}\";"\
"const bool dirty = $${CUTEVERSIONING_GIT_DIRTY};"\
"const QVersionNumber versionNumber = QVersionNumber::fromString(latestTag);"\
"}"\
write_file($$PWD/CuteVersioning/version.h, HEADER_OUTPUT)
# Write AndroidManifest.xml
android {
$$CUTEVERSIONING_REPLACE_ANDROID_VERSION_NAME {
!isEmpty(ANDROID_PACKAGE_SOURCE_DIR) {
ANDROID_RESULT = $$system(cat $${ANDROID_PACKAGE_SOURCE_DIR}/AndroidManifest.xml | \
sed -e 's/android:versionName=\\"[^\\"]*/android:versionName=\\"$${CUTEVERSIONING_GIT_LATEST_TAG}/' \
> $${ANDROID_PACKAGE_SOURCE_DIR}/AndroidManifest-tmp.xml && \
mv $${ANDROID_PACKAGE_SOURCE_DIR}/AndroidManifest-tmp.xml $${ANDROID_PACKAGE_SOURCE_DIR}/AndroidManifest.xml)
}
}
}

# Triggers to enable this every build
qmakeforce.target = dummy
unix {
qmakeforce.commands = touch $$PWD/CuteVersioning.pri # hack to force qmake to run every time
qmakeforce.commands = touch $$PWD/dummy.pri # hack to force qmake to run every time
} win32 {
# TODO support for forced qmake run on Windows
}
Expand All @@ -55,3 +71,5 @@ SOURCES += \
$$PWD/src/quickversion.cpp

INCLUDEPATH += $$PWD

include(dummy.pri)
3 changes: 3 additions & 0 deletions dummy.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is only included to have it updated
# automatically, which in turn makes sure qmake
# runs for every build.

0 comments on commit 684597b

Please sign in to comment.