Yeah, thatâs what my current .exe does, it grabs the information from Git and parses the previously existing version.h (if one exists), only over-writing that header file if the Git information has changed from whatâs in the file. Thus preventing a recompile of the much larger .cpp file that includes the version.h file.
I also only put this in the Release target, as I really donât care about this info when Iâm building in debug mode. But that can be scoped in/out in the .pro file as well.
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
***@walbro.com<mailto:***@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 ***@walbro.com<mailto:***@walbro.com> and thereafter destroy the e-mail you received and all copies thereof.
From: Andy <***@gmail.com>
Sent: Friday, July 06, 2018 12:02 PM
To: Murphy, Sean <***@walbro.com>
Cc: qt-creator <qt-***@qt-project.org>
Subject: Re: [Qt-creator] How to put custom build steps into Git?
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 <***@walbro.com<mailto:***@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
***@walbro.com<mailto:***@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 ***@walbro.com<mailto:***@walbro.com> and thereafter destroy the e-mail you received and all copies thereof.
From: Andy <***@gmail.com<mailto:***@gmail.com>>
Sent: Friday, July 06, 2018 11:04 AM
To: Murphy, Sean <***@walbro.com<mailto:***@walbro.com>>
Cc: qt-creator <qt-***@qt-project.org<mailto:qt-***@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
Post by Tobias HungerThat 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<http://www.forcepoint.com>
_______________________________________________
Qt-creator mailing list
Qt-***@qt-project.org<mailto:Qt-***@qt-project.org>
http://lists.qt-project.org/mailman/listinfo/qt-creator
Click here<https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ==> to report this email as spam.
_______________________________________________
Qt-creator mailing list
Qt-***@qt-project.org<mailto:Qt-***@qt-project.org>
http://lists.qt-project.org/mailman/listinfo/qt-creator