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

Orgad Shaneh orgads at gmail.com
Mon Sep 9 09:36:54 CEST 2013


On Mon, Sep 9, 2013 at 10:30 AM, Joerg Bornemann
<joerg.bornemann at digia.com>wrote:

> 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/
>
> _______________________________________________
> QBS mailing list
> QBS at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qbs
>

If there's a way to pass environment variables, you can also set GIT_DIR
(but then again, you need access to product.sourceDirectory).

- Orgad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20130909/49e9dd4a/attachment.html>


More information about the Qbs mailing list