Wednesday, August 15, 2012

Improve Your Build Process

An under-utilized feature of Real Studio is Build Automation.  Build automation is a way for you to have certain tasks (called Build Steps) run automatically each time you run or build your project.

The available build steps are: Copy Files and Run Script.

Right now, Build Automation is a feature of Real Studio Web and Enterprise editions, but starting with Real Studio 2012 Release 2, it will be available to everyone.

Copy Files

Use this step to copy files that your application needs to a location it can easily find at run-time.  You can copy files to a variety of locations, but the most common are Bundle Parent folder and the Resources folder.

The Bundle Parent folder copies the specified files alongside your built application (or application bundle on OS X).  You might do this for certain types of support files.

But more typically, you will use the Resources folder.  This copies the specified files to a Resources folder that is alongside the built application.  On OS X, it uses the Resources folder within the application bundle.

You can copy any file that you want your application to have available when it runs.  This could be help files, pictures that you do not want included in the project or really anything.  It is particularly useful with web applications so that you can make sure any other files needed for the web app are included in the same folder.

To add a Copy Files build step, use Project -> Add -> Build Automation -> Copy Files.  Then you can click the small circle icon for the Files property to open the Files dialog and drag the files you want to copy to it.

In order for a build step to work, you have to add it to the Build Automation section of the project.  In this section there are entries for each target platform and below them a "Build" entry.  This allows you to have separate steps that do different things for each platform and to have steps that run before your application is built and steps that run after it is built.

Scripts that copy files should run after the application is built, so you would copy it after the "Build" entry.

Build Automation in Project List

Run Script

The Script build step allows you to run an IDE Script, which are powerful ways to control the IDE and run external tools.

Here's one thing you might find useful: Saving your project automatically when you click Run.

To do this, add a new Script step to your project (Project -> Add -> Build Automation -> New IDE Script).  Click on the Script property to open the Edit Script dialog and enter this script:

DoCommand "SaveFile"

This tells the IDE to save the current project.

In order for this build step to run *before* the build is done, you now need to drag it before the "Build" item in the Project List.

Another useful command for Run Script is DoShellCommand, which allows you to run a shell command.  For example, with OS X you could use DoCommandShell to code sign your application after it is built:

Call DoShellCommand "codesign -f -s ""Developer ID Application: YourName""  """"" 

I hope you find some great uses for Build Automation!


Anthony said...

I love Build Automation in most cases. Makes things much simpler. I have noticed an oddity that I haven't taken the time to report, though. If I setup build automation in OS X to copy two directories (which are stored on a share network drive), then do the build on Windows, the IDE just creates blank files with those names in the build directory. I do 99% of my building in OS X, so it's not been a big issue for me.

Unknown said...

This is probably a common question but I can't confirm it in my version of RS until the new plan comes in.

Is it possible to have multiple build scripts, depending on target? We currently have debug and build but I can see different scripts for "build for UAT" and "build for deployment". I can even see multiple deployment builds (MAS vs non-MAS, basic vs full, etc).

Is this currently possible or at all in the plan? If not, is it possibel to have the build automation ask you and take action depending on responses?