Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Git commit date in .pro

Git commit date in .pro

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    What about:

    GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --format=%cd)
    

    ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    ivanicyI 1 Reply Last reply
    1
    • ivanicyI ivanicy

      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.

      648859d3-9134-4706-9d66-f66ee6dd1c55-image.png

      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!

      W Offline
      W Offline
      wrosecrans
      wrote on last edited by
      #3

      @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?

      ivanicyI 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        What about:

        GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --format=%cd)
        

        ?

        ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #4

        @SGaist Yes, I tried it, but it throws the same error I showed

        aha_1980A 1 Reply Last reply
        0
        • ivanicyI ivanicy

          @SGaist Yes, I tried it, but it throws the same error I showed

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @ivanicy

          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

          Qt has to stay free or it will die.

          ivanicyI 1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            By the way, why are you passing --git-dir and --work-tree to that command ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            ivanicyI 1 Reply Last reply
            0
            • aha_1980A aha_1980

              @ivanicy

              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

              ivanicyI Offline
              ivanicyI Offline
              ivanicy
              wrote on last edited by
              #7

              @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

              1 Reply Last reply
              0
              • SGaistS SGaist

                By the way, why are you passing --git-dir and --work-tree to that command ?

                ivanicyI Offline
                ivanicyI Offline
                ivanicy
                wrote on last edited by
                #8

                @SGaist I am not an expert in this commands. I found an example and it came with those modifiers

                1 Reply Last reply
                0
                • W wrosecrans

                  @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?

                  ivanicyI Offline
                  ivanicyI Offline
                  ivanicy
                  wrote on last edited by
                  #9

                  @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.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    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), "\ ")
                    

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    ivanicyI 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      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), "\ ")
                      
                      ivanicyI Offline
                      ivanicyI Offline
                      ivanicy
                      wrote on last edited by
                      #11

                      @SGaist Thank you very much!!! I changed the "\ " to "|" because it puts a blank and it works!

                      aha_1980A 1 Reply Last reply
                      0
                      • ivanicyI ivanicy

                        @SGaist Thank you very much!!! I changed the "\ " to "|" because it puts a blank and it works!

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        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!

                        Qt has to stay free or it will die.

                        ivanicyI 1 Reply Last reply
                        1
                        • aha_1980A aha_1980

                          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!

                          ivanicyI Offline
                          ivanicyI Offline
                          ivanicy
                          wrote on last edited by
                          #13

                          @aha_1980 Yes, It was a mistake. It is solved now. Thank you

                          1 Reply Last reply
                          2

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved