Launch a compilation by programming

In continuous integration systems, every time code is submitted, or on an hourly basis, a compilation of the source code is automatically launched. This approach allows you to check merges on the code management server.

Starting from 4D v19, a new command allows you to launch code compilation, so you can set up this type of system.

Launch a compilation by programming

What is continuous integration?

Continuous integration consists in checking, each time source code is modified, that the result of the modifications does not produce regressions in the developed application. The main goal is to detect integration problems as early as possible during development.

New command

The new command Compile Project allows to compile:

  • the current project
  • a project other than the current project


If the compilation is successful, the command returns a status object with a success property. Otherwise, it returns a status object with a list of errors.

Compile THE current project

Compiling the current project with the default settings is very simple:

var $status : Object
$status:=Compile project() 


You can also override the compilation options by passing an object with the new values. Here are the options you can override:

  • compilation target
  • type inference
  • default type for numerics or buttons
  • generate symbols
  • generate typing methods
  • components to use in the compilation


For example, every time code is submitted on the source control server, you can launch a simple syntax check to verify the merged code.

var $options; $status : Object
$options:=New object()
$options.targets:=New collection()
$status:=Compile project($options)


If your application uses components, you’ll need to pass the list of compiled components in the options object.

var $options; $status : Object
var $component : 4D.File
$options:=New object()
$options.components:=Folder("/PACKAGE/Components").files(fk recursive).query("extension = .4dz")
$status:=Compile project($options

Compile another project

It’s possible to compile an application from another project. Just pass the project file to the command:

var $file : 4D.File
$file:=Folder(fk documents folder).file("Databases/myApp/Project/myApp.4DProject")
$status:=Compile project($file)

Compilation error management

The command returns a status object that tells you whether the compilation is successful or not. If the compilation fails, 4D returns the collection of error messages, the implicated methods, and the line number of the error.

Then, thanks to the new parameter of the METHOD OPEN PATH command, you can open the method in the code editor and place the cursor on the error line.

For example, it’s possible to display the error collection in a list box and then add a button that opens the method of the error selected in the list:

METHOD OPEN PATH(Form.selected.code.path;Form.selected.line)

Stay tuned! We have more blog posts on continuous integration coming up!

Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.