I’m looking for a cross-platform JUCE way to access either a build time/date or build number inside my plugin, so I can display it in an about box. It would help tremendously when talking to a user, if you know what I mean…
ProjectInfo has projectName and versionNumber, but that’s not enough and it would be great to not have to run Projucer every time to update a number.
I’m guessing it may involve a shell script, but it would be great if there was some cross-platform way to do this.
You can change those in JuceHeader.h – I don’t think you have to run ProJucer to change them – but I only use ProJucer to initialize a project and then never use it again.
You could also auto generate a header with the git ref, that way you can see exactly which commit something was built with and it’s cross platform. If you use git tags you can get your whole version number this way.
git rev-parse --short HEAD
6d35642
git describe --always
4.2.3-650-g6d35642
Come to think of it, it would make a nice Projucer feature to have something like this added to the AppConfig header if it detects the .jucer being saved is under source control.
I added the following code to writeAppConfig() in jucer_ProjectSaver.h, seems to work well for me. This way you can use the JUCE_GIT_HASH_SHORT preprocessor definition as a kind of build number. The only issue with this is if you are committing the AppConfig.h as part of the project because of some code in the user code section. We got around this at work by adding a new text entry field to the Projucer that replaces the user code section of the AppConfig.h so we never have to commit the AppConfig.h to a project. Maybe this could also be added to the Projucer? it would have be done in a way that doesn’t break compatibility but that should be possible without too much trouble.
out << newLine;
{
StringArray command;
command.add ("git");
command.add ("rev-parse");
command.add ("--short");
command.add ("HEAD");
ChildProcess c;
String gitHashShort;
if (c.start (command, ChildProcess::wantStdOut))
{
c.waitForProcessToFinish (10000);
if (c.getExitCode() == 0)
gitHashShort = c.readAllProcessOutput().trim();
}
out << "//==============================================================================" << newLine;
out << "#define JUCE_GIT_HASH_SHORT " << gitHashShort.quoted() << newLine;
}
but the basic idea it to run a shell script somewhere in your build system to get the git version. Then you can add it to your compilation via the flag