Solved Git commit date in .pro
-
@ivanicy What's the full error message that you get when you try to build? Your screenshot mentions a "unexpected expression" but the whole error message might include what the compiler thinks the expression is, which can be a useful hint about what exactly is going wrong. Also, if you are building verbosely with the compiler invocation, you'll also see the definition as it is passed to the compiler.
I wouldn't be surprised if the ''s in your git invocation are resulting in an odd path being passed in '--git-dir' Windows?
-
@SGaist Yes, I tried it, but it throws the same error I showed
-
Please add a
message($$GIT_DATE)
in the pro file to debug the output.As @wrosecrans said, there might be a problem running the command or the output is not what you expect.
Regards
-
By the way, why are you passing
--git-dir
and--work-tree
to that command ? -
@aha_1980 The output of the command in the General Messages tab is:
Mon Dec 2 16:42:48 2019 +0100
This is exactly that I want but when I use the variable in a .cpp, it gives me this error
-
@SGaist I am not an expert in this commands. I found an example and it came with those modifiers
-
@wrosecrans When I build the project, The error that it throws is that there is a ")" missing. This is because the compiler can't recognise or can't use the variable. Let me show another command that works perfectly:
GIT_VERSION = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD describe --always --tags) DEFINES += GIT_VERSION=\\\"$$GIT_VERSION\\\"
This command gives the last tag and the number of commits after this tag. And, like I said, works perfectly.
-
Because GIT_VERSION is a string without any spaces.
You need to escape them all to use them in a define on the command line.
GIT_DATE = $$join($$list($$GIT_DATE), "\ ")
-
@SGaist Thank you very much!!! I changed the "\ " to "|" because it puts a blank and it works!
-
Hi @ivanicy,
why did you delete this topic? You should have rather marked it as SOLVED so others know that a solution has been found.
Thanks!
-
@aha_1980 Yes, It was a mistake. It is solved now. Thank you