Neat Build Script Trick

Background
Like many developers I have constants set up in my application, so that when the application is built it either displays a “Test Version” dialog or it trigger what ever activation system that app uses. Normally, I’d have to remember to set that constant when I go build and then I also set the app’s “Stage Code” from Alpha, Beta or Development to Final.

Using a build script, I now only have to change the app’s “Stage Code”
So I created a neat build script that executes before the “Build” action, it checks the “Stage Code” and then sets the app’s constants accordingly. So now I only need to change one thing.

if PropertyValue( "App.StageCode" ) <> "3" then ConstantValue( "App.kDevBuild" ) = "True" else ConstantValue( "App.kDevBuild" ) = "False" end if

And I only have it fire when on “Release”.

In my app object, I have the constant “kDevBuild” as a boolean and in the open event I have code similar to below.

[code] #if not debugBuild then
// - We don’t need this unless we’re “Building”.
#if not kDevBuild then
// - Fire Registration

#else
 // - Display "Test Version Dialog"

#endif

#endif
[/code]

Nice trick, thanks for sharing Sam.

You’re welcome

One “trick” that I have been trying to figure out…

Is there a way to have an app contain a constant the always resolves to the date/time that the app was compiled?

In the VB6 days… I had a tiny app run when I booted that created an include file “today_date=format(now,“mdy”)” (or something like that)

[quote=24019:@Dave S]One “trick” that I have been trying to figure out…

Is there a way to have an app contain a constant the always resolves to the date/time that the app was compiled?

In the VB6 days… I had a tiny app run when I booted that created an include file “today_date=format(now,“mdy”)” (or something like that)[/quote]

Not easily. Xojo does not expose any way of getting the date to application scripting. I think there is a FR out there asking for this, but I can’t seem to find it. Anyway, the only way to do it now would be to get the date from a shell script.

An example of how to do this on an OS X box:

[code]Dim now As String
now = DoShellCommand(“date”)

ConstantValue(“kAppBuildDate”) = now[/code]

This will not be a true date value, but a string, for example on OS X Wed Jul 31 10:16:29 EDT 2013. You could of course parse that and reconstruct the date how you see fit. I am unsure of the equivalent code on Windows.

There’s an app property, “app.BuildDate”. Which is accessible from a running app, so perhaps it’s accessible from Build Scripts.

Oh, I forgot all about that, was going down the road of making a script, ha! I believe .BuildDate is exactly what Dave is looking for. Just access App.BuildDate in your application, and have fun!

Here’s quick one-liner you can put in a Build Script step to automatically save your project before it gets built:

DoCommand("SaveFile")

Just drag it before the Build action for your current OS target.

One I use on all my projects: https://github.com/jcowgar/xojo-ide-scripts-misc/blob/master/Set%20Application%20Versioning.xojo_script

This one gets the git revision, adds it as App.GitRevision, but it also updates the ShortVersion and LongVersion strings automatically based on the MajorVersion, MinorVersion, BugVersion, and NonReleaseVersion properties.

Thanks guys. Any more tips and tricks on IDE scripts would be very welcomed. It’s an area of Xojo that I haven’t ventured into too much mostly because I am not aware of what all it can do.