[QBS] Retreive git describe result to set cpp.defines value

Raphael Cotty R.Cotty at cascade-technologies.com
Mon Sep 9 19:50:01 CEST 2013


Thanks, it works.

Is there a way to get the list of undocumented features?

Regards

Raph
________________________________________
From: Joerg Bornemann [joerg.bornemann at digia.com]
Sent: 09 September 2013 09:30
To: Raphael Cotty
Cc: qbs at qt-project.org
Subject: Re: [QBS] Retreive git describe result  to set cpp.defines value

On 07/09/2013 16:17, Raphael Cotty wrote:

> I am porting a large project using cmake to qbs.
> We use cmake EXECUTE_PROCESS to retrieve the the git tag value and set a
> variable with it.
> The variable is then used to create a #define.

There's the Probe item which can be used for things like that.
The following example adds a GITREV define that contains the latest
commit id of your repository.

---snip---
import qbs 1.0
import qbs.Process

Application {
     Probe {
         id: revprobe
         property string revision

         configure: {
             revision = "I don't know";
             var p = new Process();
             if (p.exec("git.exe", ["rev-parse", "HEAD"]) === 0)
                 revision = p.readStdOut().trim();
         }
     }

     Depends { name: "cpp" }
     cpp.defines: ['GITREV="' + revprobe.revision + '"']
     files: ["main.cpp"]
}
---snap---

Seems that we should eventually document the Probe items...

I just noticed two small problems: this example will only work correctly
if qbs is called from the source directory. To make this work correctly,
we have to tell git where the repository is by either

1) setting the working dir of the Process object - a feature we've
forgotten to provide (QBS-385).
2) or calling git with the --git-dir opion and pass
product.sourceDirectory, which is not accessible within Probe items
unfortunately (QBS-386).


Best Regards,

Joerg

--
Joerg Bornemann
Digia, Qt
http://qt.digia.com/




More information about the Qbs mailing list