[Qt-creator] How to put custom build steps into Git?

Andy asmaloney at gmail.com
Fri Jul 6 17:03:38 CEST 2018


For my git info, I am using what feels like a hacky way to avoid having to
add pre-build steps on every single project configuration. Might help?

In my .pro:

# Get our build info from git

OTHER_FILES += "$$PWD/gen_header.sh"


!build_pass {

    UNUSED_RESULT = $$system(bash "$$PWD/gen_header.sh")

}


And then the contents of gen_header.sh:

#!/bin/bash


(

  echo '// Generated by gen_header.sh - do not edit'

  echo

  echo  '#define GIT_VERSION_LONG "'`git describe --long`'"'

  echo  '#define GIT_VERSION_HASH "'`git log --pretty=format:'%h' -n 1`'"'

  echo

  echo  '#define GIT_BUILD_DATE_LONG "'`git log -n 1 --format=%ai`'"'

  echo  '#define GIT_BUILD_DATE_SHORT "'`git log -n 1 --format=%ad
--date=short`'"'

) > gitVersion.h


On Windows I have cygwin installed, so bash may be found. Maybe this trades
one type of config for another, but I already use cygwin for many things so
I have it installed on all my Windows build machines.

Another limitation is that it executes every build, but I'm willing to deal
with that for the convenience.

(Just saw Orgad's response - that might be cleaner?)

---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney <https://twitter.com/asmaloney>



On Fri, Jul 6, 2018 at 10:48 AM Murphy, Sean <smurphy at walbro.com> wrote:

> > That is something that should be done by the build system IMHO
>
> Can you expand on this part? By build system, I assume you mean qmake?
> If that's what you meant, I'm all for doing it that way as well, how would
> I
> go about adding what I'm looking for into the .pro file?
>
> Basically, in our current setup, we're all using qmake as the build
> system,
> so if there's a solution that works via qmake variables, I'm totally fine
> with
> that too, I just haven't found them yet if they exist. If it matters,
> we're
> currently targeting Windows (using mingw compiler) and Mac desktops,
> but have plans for Android and iOS down the road, so I'd like to have this
> be something that is set up once, and then each developer gets it for free
> when they clone the Git repo.
>
> As it stands right now, each developer has to manually set these up. Hell,
> I even have to manually set it up if I clone my repository on my own
> machine. I usually have our release branch checked out in one directory,
> and then I clone from there into other directories to create feature
> branches. So on that cloned repo, I've temporarily lost those build
> settings
> until I manually re-add them to that cloned directory's .pro.user file,
> either by manually copying the previous .pro.user file over, or by using
> the Projects pane in Qt Creator to add the steps back in.
>
> I'm also totally open to being told my approach is just completely wrong,
> as long as someone has a better approach!
>
> Thanks,
> Sean
>
>
>
> This message has been scanned for malware by Forcepoint.
> www.forcepoint.com
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qt-creator
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20180706/24ce57aa/attachment.html>


More information about the Qt-creator mailing list