Git commit date in .pro
-
Hello!! I am trying to use a commit date in my code. I am using this command:
GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -1 --format=%cd) DEFINES += GIT_DATE=\\\"$$GIT_DATE\\\"
When I use this variable in a .cpp, it seems that some of the command doesn't like qt, because it behaves as if it did not recognize the variable.
If I don't include the "-1" in the command, the error dissappears but the program doesn't compile I think because the output of the command is too long.
How can I fix it??
Thank you very much!
-
Hi,
What about:
GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --format=%cd)
?
-
Hello!! I am trying to use a commit date in my code. I am using this command:
GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -1 --format=%cd) DEFINES += GIT_DATE=\\\"$$GIT_DATE\\\"
When I use this variable in a .cpp, it seems that some of the command doesn't like qt, because it behaves as if it did not recognize the variable.
If I don't include the "-1" in the command, the error dissappears but the program doesn't compile I think because the output of the command is too long.
How can I fix it??
Thank you very much!
@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?
-
Hi,
What about:
GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --format=%cd)
?
-
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 ? -
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
-
@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?
@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), "\ ")
-
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!