Cross-platform build number or date access?


#1

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.

Anyone have something they’d be willing to share?


#2

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.

Rail


#3

Sure, but I’m looking for something automatic and not manual.


#4

You can use

String date (__DATE__);
String time (__TIME__);

which will be replaced by the compiler. But watch out, if it is in a sourcefile, that was compiled before into an object file, it will not be updated.

See: https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
or MSDN: https://msdn.microsoft.com/en-us/library/b0084kay.aspx


#5

I prefer to have an option (which can be enabled) to generate a log, then use Logger::writeToLog

When a user starts my Installer app for instance it starts the log with:

Build:                        1.0.0
Compilation Date:             16 Mar 2017
User Name:                    Rail Jon Rogut
Operating System:             Mac OSX 10.11.6 - [64 Bit]
Operating System Language:    en, Display Language: en
System Memory:                32,768 MB
CPU:                          GenuineIntel - 3,400 MHz, 8 cores
Has MMX Instruction set:      YES
Has SSE Instruction set:      YES
Has SSE2 Instruction set:     YES
Has SSE3 Instruction set:     YES
Has SSSE3 Instruction set:    YES
Has AVX Instruction set:      YES

To get the compilation time:

Logger::writeToLog (String ("Compilation Date:").paddedRight (' ', iPaddingLength) + Time::getCompilationDate().toString (true, false));

Rail


#6

Interesting…

I’ve somehow never used logs before. Maybe this is the time.

Beta testers making me crazy.


#7

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.


#8

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;
}

#9

If you use Jenkins (or similar) to do your builds then you can drop in a pre-build script that gets the git tag and populates a .h file with it.


#10

You can also use a shell script to populate a preprocessor definition. In Makefile syntax it looks like this

GIT_VERSION := $(shell git rev-parse --short HEAD)

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

-DGIT_VERSION=\"$(GIT_VERSION)\"