Pulling git revision during build (with QT Creator)
-
wrote on 20 Feb 2018, 14:59 last edited by
I would like the version application to include the git commit. I have added the following to my .pro file:
VERSION_MAJOR=0
VERSION_MINOR=1
VERSION_BUILD='$(shell cd $$PWD;git rev-list HEAD --count)'
DEFINES += VERSION_NUMBER="\"$$sprintf("%1.%2.%3", $$VERSION_MAJOR, $$VERSION_MINOR, $$VERSION_BUILD)\""The seems to work in OS X but not in windows. Do I need to install a separate shell applications on my Windows compiling computer or is one included with QT Creator?
-
Hi
as far as i know, no git.exe is include in Qt / Creator installers. -
wrote on 20 Feb 2018, 15:25 last edited by
I agree with @mrjj. @mgreenish do you have git working fine in Windows so far?
-
I agree with @mrjj. @mgreenish do you have git working fine in Windows so far?
wrote on 20 Feb 2018, 21:13 last edited by@Pablo-J.-Rogina I do have git working on windows, yes. But I guess I don't know how the command is passed to Windows, if Qt does a transition of the 'shell' command based on the OS or if it is passed as-is irrespective of the OS.
-
Hi,
On Windows, it might very well be
git.exe
. -
wrote on 20 Feb 2018, 21:36 last edited by
What's the difference between using
$(shell
and the replace function
$$system(
Is there any difference? The only comparison of the two I found said that $$system wasn't run on every build.
-
@mgreenish: Is
git.exe
in yourPATH
environment variable?When I experimented with including the Git hash into the executable, I used:
SHA1 = $$system(git rev-parse --short=8 HEAD)
I can't directly tell you what's the difference between $shell and $$system, but there are functions that are run on every
make
and some are run on everyqmake
. -
wrote on 21 Feb 2018, 16:34 last edited by
@aha_1980 Yes, git.exe seems to be included in my path. I can open a command window in Windows, cd to the project directory and type in the following command:
git rev-list HEAD --count
I get the expect result as output. As such, it must be included in the path.
-
wrote on 21 Feb 2018, 16:43 last edited by
In any case, neither
VERSION_BUILD='$(shell git rev-list HEAD --count)'
nor
VERSION_BUILD=$$system(git rev-list HEAD --count)
seem to work. The current version number that shows up is 0.1. so the sprintf statement seems to be formatted correctly and likely the problem is with the assignment of VERSION_BUILD.
-
wrote on 21 Feb 2018, 17:32 last edited by
@mgreenish said in Pulling git revision during build (with QT Creator):
git.exe seems to be included in my path. I can open a command window in Windows, cd to the project directory and type in the following command
Could you please start Qt Creator from that same command window and try. I guess you may not have the same PATH values in Qt Creator if started from Windows menu
-
wrote on 26 Apr 2021, 07:58 last edited by
Hi.
Please, check my repo. Set Qt App version from git.