Any qmake experts out there?

Lubomir I. Ivanov neolit123 at gmail.com
Wed Jan 28 13:49:15 PST 2015


On 28 January 2015 at 21:04, Linus Torvalds
<torvalds at linux-foundation.org> wrote:
> The subsurface version generation code is wrong, and I don't know
> enough about qmake to fix it.
>
> Isubsurface-gen-version.pridoes this:
>
>    exists(.git/HEAD): {
>         win32: SET_GIT_DIR = set GIT_DIR
>         else: SET_GIT_DIR = GIT_DIR
>         GIT_HEAD = .git/HEAD
>         VERSION_SCRIPT = $$PWD/scripts/get-version
>    ...
>
> and qmake will generate dependencies in .git/HEAD etc. But that's
> actually completely bogus, as shows by this trivial situation:
>
>     git gc --prune=now
>
> which will pack things and actually remioves the .git/refs/master
> file, because it's just going to be one entry in the packed ref file
> (.git/packed-refs). Which then results in
>
>     make: *** No rule to make target '.git/refs/heads/master', needed
> by 'ssrf-version.h'.  Stop.
>
> because qmake has decided that there's that hard dependency on that
> internal git file that pruning and packing the repository got rid of
> as unnecessary.
>
> The proper way to get the git version is to just do
>
>      # get raw SHA1
>      git rev-parse HEAD
>
>      # get "description" of it
>      git describe --tags --abbrev=12
>
> but actually accessing the .git/HEAD file directly is very wrong. But
> I have no idea how to do git commands in the *.pri file, and handling
> failure gracefully (in case it's not a git repository etc).
>

just gave it a shot but couldn't get it to work - attached test .pro file,

i was able to check if git is installed and if PWD is a repository,
but for some reason my rule to write the version.h is not generated in
the Makefile.
also not sure what would the rule dependencies be. perhaps we should
just generate version.h on each "make" call, then again i have no idea
how to do that from qmake either.

with QMAKE_EXTRA_TARGETS it works but with QMAKE_EXTRA_COMPILERS it doesn't.
anyone?

lubomir
--
-------------- next part --------------
################################################################################
# for debugging
################################################################################

TEMPLATE = app
TARGET = test
INCLUDEPATH += .

# Input
SOURCES += main.c

VERSION = 4.3

################################################################################
# this bellow can potentially go in subsurface-gen-version.pri
# except it doesn't work...
################################################################################

VERSION_FILE = ssrf-version.h
macx: VER_OS = darwin
unix: !macx: VER_OS = linux
win32: VER_OS = win

GIT_HEAD = .git/HEAD

# null differs on win32/unix
#
equals($$QMAKE_HOST.os, "Windows"):NUL=NUL
else:NUL=/dev/null

# check for git and if in a repository
#
HAS_GIT = $$system(git --version 2> NUL)
!isEmpty(HAS_GIT) {
	# could be a better way...
	IS_GIT_REPO = $$system(git log 2> NUL)
	contains(IS_GIT_REPO, "commit") {
		FULL_VERSION = $$system("sh ./scripts/get-version linux")
	} else {
		warning("invalid git repository")
	}
} else {
	warning("git not found")
}

# fallback
#
isEmpty(FULL_VERSION) {
	# This is probably a package
	exists(.gitversion): {
		FULL_VERSION = $$system("cat .gitversion")
	} else {
		FULL_VERSION = $$VERSION
	}
}

# at this point a Makefile rule can be created
#
# message("version found $$FULL_VERSION")

CANONICAL_VERSION = $$system("sh ./scripts/get-version full $$FULL_VERSION")
OS_USABLE_VERSION = $$system("sh ./scripts/get-version $$VER_OS $$FULL_VERSION")

version_h.depends = $$GIT_HEAD
version_h.commands = echo \\$${LITERAL_HASH}define VERSION_STRING \\\"$$OS_USABLE_VERSION\\\" > ${QMAKE_FILE_OUT}
version_h.commands += $$escape_expand(\\n)$$escape_expand(\\t)
version_h.commands += echo GIT_VERSION_STRING \\\"$$FULL_VERSION\\\" >> ${QMAKE_FILE_OUT}
version_h.commands += $$escape_expand(\\n)$$escape_expand(\\t)
version_h.commands += echo \\$${LITERAL_HASH}define CANONICAL_VERSION_STRING \\\"$$CANONICAL_VERSION\\\" >> ${QMAKE_FILE_OUT}
version_h.input = $$GIT_HEAD
version_h.output = $$VERSION_FILE
version_h.variable_out = GENERATED_FILES
version_h.CONFIG = ignore_no_exist
QMAKE_EXTRA_COMPILERS += version_h

QMAKE_CLEAN += $$VERSION_FILE


More information about the subsurface mailing list