Skip to main content
Version: Next

Compile project

Compile project {( {projectFile}{;}{options} )} -> Function result

ParameterTypeDescription
projectFile4D.File🡒.4DProject file to compile
optionsObject🡒Object that specifies compilation options
Function resultObject🡐Object containing information on the compilation status

Description

Compile project allows you to compile the current host project or the project specified in the projectFile parameter. For more information on compilation, see the Compilation page on developer.4d.com.

By default, the command uses the compiler options defined in the Structure Settings. You can override them by passing an options parameter. The following syntaxes are supported:

  • Compile project(): compiles the opened project using the options defined in the Structure Settings
  • Compile project(options): compiles the opened project. The options defined override the Structure Settings
  • Compile project(projectFile): compiles the projectFile 4DProject using the options defined in the Structure Settings
  • Compile project(projectFile; options): compiles the projectFile 4DProject and the options defined override the Structure Settings

Note: Binary databases cannot be compiled using this command.

Unlike the Compiler window, this command requires that you explicitly designate the component(s) to compile. When compiling a project with Compile project, you need to declare its components using the components property of the options parameter. Keep in mind that the components must already be compiled (binary components are supported).

The resulting compiled code will be stored in the DerivedData or Libraries folder of the project, depending on the targets property of the options parameter. If you want to create .4dz files, you still need to manually zip the compiled project or use the build application feature.

If you pass an empty collection in targets, Compile project will execute a syntax check without compiling.

Compilation errors, if any, are returned as objects in the errors collection.

Note: You cannot call this command when another compilation is running (for example, a compilation launched from the Compilation window).

options Parameter

The options parameter is an object. Here are the available compilation options:

PropertyTypeDescription
componentsCollectionCollection of 4D.File objects to dependent components (must be already compiled)
defaultTypeForButtonsIntegerPossible value: Is real or Is longint
defaultTypeForNumericsIntegerPossible value: Is real or Is longint
generateSymbolsBooleanTrue to generate symbol information in the .symbols returned object
generateSyntaxFileBooleanTrue to generate a syntax file for code completion in the \Resources\en.lproj folder of the project
generateTypingMethodsString"reset" or "append" to generate typing methods. If value is "append", existing variable declarations won't be modified (compiler window behavior). If value is "reset" existing variable declarations are removed beforehand.
plugins4D.Folder objectPlug-ins folder to be used instead of the Plugins folder of the current project. This property is only available with the projectFile syntax.
targetsCollection of stringspossible values: "x86_64_generic", "arm64_macOS_lib". Pass an empty collection to execute syntax check only
typeInferenceString"all": Type all variables, "locals": Process and interprocess are typed, "none": All variables are typed
warningsCollection of objectsDefines the warnings state
[].majorNumberWarning main number, before the dot
[].minorNumberWarning second number, after the dot
[].enabledBooleanWarning activation state

Note: When the warnings attribute is not defined in the options object, the Compile project command uses the default warning generation statuses defined in the settings.

Function result

The object returned by Compile project has up to three properties:

PropertyTypeDescription
successBooleanTrue if the save action is successful, False otherwise.
Available only in case of error or warning:
errorsCollection of objectscollection of objects describing compilation errors or warnings
isErrorBooleanError if True, warning otherwise
messageStringError message
codeObjectcode object
lineNumberLine number of error in the code. For class methods, line number in the function
lineInFileNumberLine number in the file (different from "line" for class methods, and takes into account the %attributes prefix line)
Available only if generateSymbols option is set to True:
symbolsObject
interprocessVariablesObjectList of all interprocess variables
variablesCollectionCollection of variable objects
sizeNumber
processVariablesObjectList of all process variables
variablesCollectionCollection of variable objects
sizeNumber
localVariablesCollection of objectsList of local variables per method
codeObjectcode object
variablesCollectionCollection of variable objects
methodsCollection of objectsList of methods
codeObjectcode object
callCountNumberNumber of times this method has been called
paramsCollectionCollection of parameter types (Value type numerical codes)
threadSafeBooleanIndicates if this method is thread safe

For more information, see Compilation tools.

variable objects

interprocessVariables.variables and processVariables.variables contain objects with the following structure:

PropertyTypeDescription
nameStringName of the variable
typenumberType of the variable (like Value type command)
arrayDimensionnumberFor arrays only: 1 for mono dimension arrays, 2 for two-dimension arrays
codeObjectFor process and interprocess variables: descriptor of where the variable has been defined
code object

The code property in methods[ ].code and errors[ ].code is an object with the following properties:

PropertyTypeDescription
typeString"projectMethod", "formObjectMethod", <li<"formmethod",< li=""> "databaseMethod", "triggerMethod", "executeOnServer" (when calling a project method with the Execute on Server attribute.), "executeFormula" (when executing a formula via PROCESS 4D TAGS or the evaluation of a formula in a 4D Write Pro document.)"class""classFunction"</li<"formmethod",<>
pathStringMethod path (same format as METHOD OPEN PATH)
file4D.FileMethod file
Returned depending on the value of the type property:
methodNameStringProject method
tableNumberNumber of the table (returned for a trigger, a table form method or a table form object method)
formNameStringForm name (returned for a form method)
objectNameStringForm object name (returned for an object method)
classNameStringClass name
functionNameStringClass function name
databaseMethodNumberDatabase method index

Warning

To perform a syntax check only, pass an empty collection to the targets parameter:

 var $options;$status : Object
 $options:=New object
 $options.targets:=New collection //Empty collection for syntax checking
 $status:=Compile project($options)

Compile the current project using the compiler options of the Structure Settings only:

 var $status : Object
 $status:=Compile project

On a Silicon Mac, compile the current project to ARM only:

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

Compile a project other than the current project:

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

Compile a project and declare its component:

 var $options;$status : Object
 var $component : 4D.File
 $options:=New object
 $component:=Folder(fk documents folder).file("Components/myComponent.4dz")
 $options.components:=New collection($component)
 $status:=Compile project($options)

Disable warnings 518.1 and 518.2 when compiling your project:

var $options:={}$options.warnings:=[]$options.warnings.push({major: 518; minor: 1; enabled: False})$options.warnings.push({major: 518; minor: 2; enabled: False})var $result:=Compile project($options)

See also

BUILD APPLICATION