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

Andy asmaloney at gmail.com
Fri Jul 6 18:02:20 CEST 2018


Another thing I didn't mention is that if you want to avoid rebuilding
files, the script can be smarter.

Generate to a temporary file and only copy it over the existing one if it
is different.

I didn't bother for my setup because the header is only included in one
place and only rebuilds a small file.

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



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

> Thanks guys! Actually I think a combination of both your suggestions might
> work better than what I have currently. What I don’t like about my current
> setup is that the thing that generates the .h file is an executable – it
> has to be compiled to work. The only real advantage of that is that it is
> written in Qt, so it’s cross platform in that sense, but the disadvantage
> is that it doesn’t exist on a developer’s machine until it itself is
> compiled. So moving to a script is probably safer. The work it is doing is
> basically exactly the same as what you have described below.
>
>
>
> So my current thought it to use Orgad’s commands in the .pro file, but
> have two scripts checked in to the project: a bash .sh file for
> Linux/Mac, and an equivalent .bat file for Windows, and properly platform
> scope the
>
>   git_ver.commands = your-app-that-generates-the-version-header
>
> command in the .pro file. That way I can avoid introducing a Cygwin
> dependency for the Windows users and still get that Git revision
> information compiled in automatically.
>
>
>
> *Sean Murphy*
>
> Sr. Project Engineer
>
> Walbro LLC
>
> 4144 Doerr Rd
>
> Cass City, MI 48726
>
> ph. 989 872 7274
>
> cell 734 223 8975
>
> fax. 989 872 3782
>
> smurphy at walbro.com
>
>
>
> *Confidentiality Notice:* The materials contained within this e-mail
> transmission (including all attachments) are private and confidential and
> the property of the sender. The information contained in the materials is
> privileged and intended only for the named addressee(s). If you are not the
> intended addressee, be advised that any unauthorized disclosure, copying,
> distribution or the taking of any action in reliance on the contents of
> this material is strictly prohibited. If you have received this e-mail
> transmission in error, please immediately notify the sender by telephone at
> 989-872-7274 or send an e-mail to smurphy at walbro.com and thereafter
> destroy the e-mail you received and all copies thereof.
>
>
>
> *From:* Andy <asmaloney at gmail.com>
> *Sent:* Friday, July 06, 2018 11:04 AM
> *To:* Murphy, Sean <smurphy at walbro.com>
> *Cc:* qt-creator <qt-creator at qt-project.org>
> *Subject:* Re: [Qt-creator] How to put custom build steps into Git?
>
>
>
> 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
>
>
>
> Click here
> <https://www.mailcontrol.com/sr/zKzqaFWSOmnGX2PQPOmvUihCLhWP7Wj9Y0v96vjA5EQF7ehvCj0SGQIR3mYxpY8g4Qm!sxyzaeH3KeH4!zzvzA==>
> to report this email as spam.
> _______________________________________________
> 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/db070e84/attachment.html>


More information about the Qt-creator mailing list