padv.builtin.task.GenerateCode Class
Namespace: padv.builtin.task
Superclasses: padv.Task
Task for generating code with Embedded Coder
Description
This class requires CI/CD Automation for Simulink Check.
The padv.builtin.task.GenerateCode
class provides a task that can generate
code by using Embedded Coder®.
You can add the task to your process model by using the
method addTask
. After you add the task to your process model, you can run the
task from the Process Advisor app or by using the function
runprocess
.
To view the source code for this built-in task, in the MATLAB® Command Window, enter:
open padv.builtin.task.GenerateCode
The padv.builtin.task.GenerateCode
class is a handle
class.
Creation
Description
creates a task for generating code with Embedded Coder.task
= padv.builtin.task.GenerateCode()
sets certain properties using one or more name-value arguments. For example, task
= padv.builtin.task.GenerateCode(Name=Value
)task
= padv.builtin.task.GenerateCode(Name = "MyCodeGenTask")
creates a task with
the specified name.
You can use this syntax to set property values for
TreatAsRefModel
, InputQueries
,
Name
, Title
,
IterationQuery
, InputDependencyQuery
,
DescriptionText
, DescriptionCSH
,
Licenses
, LaunchToolAction
, and
LaunchToolText
.
The padv.builtin.task.GenerateCode
class also has other properties, but you cannot set
those properties during task creation.
Properties
The GenerateCode
class inherits properties from padv.Task
. The properties listed in
Specialized Inherited Properties are padv.Task
properties that the GenerateCode
task overrides.
The task also has properties for specifying:
General Embedded Coder Options for generating code using the function
slbuild
. For more information on theslbuild
arguments, seeslbuild
.
Specialized Inherited Properties
Name
— Unique identifier for task in process
"padv.builtin.task.GenerateCode"
(default) | string
Unique identifier for task in process, specified as a string.
Example: "MyCodeGenerationTask"
Data Types: string
Title
— Human-readable name that appears in Process Advisor app
"Generate Code"
(default) | string
Human-readable name that appears in Process Advisor app, specified as a string.
Example: "My Code Generation Task"
Data Types: string
DescriptionText
— Task description
"This task uses Embedded Coder to generate code for models. By default, this task runs on all models in the project."
(default) | string
Task description, specified as a string.
When you point to a task in Process Advisor and click the information icon, the tooltip shows the task description.
Example: "This task uses Embedded Coder to generate code for models. By
default, this task runs on all models in the project."
Data Types: string
DescriptionCSH
— Path to task documentation
path to GenerateCode
documentation (default) | string
Path to task documentation, specified as a string.
When you point to a task in Process Advisor, click the ellipsis (...), and click Help, Process Advisor opens the task documentation.
Example: fullfile(pwd,"taskHelpFiles","myTaskDocumentation.pdf")
Data Types: string
RequiredIterationArtifactType
— Artifact type that task can run on
"sl_model_file"
(default) | ...
Type of artifact, specified as one or more of the values listed in this table. To specify multiple values, use an array.
Category | Artifact Type | Description |
---|---|---|
MATLAB | "m_class" | MATLAB class |
"m_file" | MATLAB file | |
"m_func" | MATLAB function | |
"m_method" | MATLAB class method | |
"m_property" | MATLAB class property | |
Model Advisor | "ma_config_file" | Model Advisor configuration file |
"ma_justification_file" | Model Advisor justification file | |
Process Advisor | "padv_dep_artifacts" | Related artifacts that current artifact depends on |
"padv_output_file" | Process Advisor output file | |
Project | "project" | Current project file |
Requirements | "mwreq_item" | Requirement (since R2024b) |
| Requirement (for R2024a and earlier) | |
"sl_req_file" | Requirement file | |
"sl_req_table" | Requirements Table | |
Stateflow® | "sf_chart" | Stateflow chart |
"sf_graphical_fcn" | Stateflow graphical function | |
"sf_group" | Stateflow group | |
"sf_state" | Stateflow state | |
"sf_state_transition_chart" | Stateflow state transition chart | |
"sf_truth_table" | Stateflow truth table | |
Simulink® | "sl_block_diagram" | Block diagram |
"sl_data_dictionary_file" | Data dictionary file | |
"sl_embedded_matlab_fcn" | MATLAB function | |
"sl_block_diagram" | Block diagram | |
"sl_library_file" | Library file | |
"sl_model_file" | Simulink model file | |
"sl_protected_model_file" | Protected Simulink model file | |
"sl_subsystem" | Subsystem | |
"sl_subsystem_file" | Subsystem file | |
System Composer™ | "zc_block_diagram" | System Composer architecture |
"zc_component" | System Composer architecture component | |
"zc_file" | System Composer architecture file | |
Tests | "harness_info_file" | Harness info file |
"sl_harness_block_diagram" | Harness block diagram | |
"sl_harness_file" | Test harness file | |
"sl_test_case" | Simulink Test™ case | |
"sl_test_case_result" | Simulink Test case result | |
"sl_test_file" | Simulink Test file | |
"sl_test_iteration" | Simulink Test iteration | |
"sl_test_iteration_result" | Simulink Test iteration result | |
"sl_test_report_file" | Simulink Test result report | |
"sl_test_result_file" | Simulink Test result file | |
"sl_test_resultset" | Simulink Test result set | |
"sl_test_seq" | Test Sequence | |
"sl_test_suite" | Simulink Test suite | |
"sl_test_suite_result" | Simulink Test suite result |
Example: "sl_model_file"
Example: ["sl_model_file "zc_file"]
IterationQuery
— Find artifacts that task iterates over
padv.builtin.query.FindModels
(default) | padv.Query
object | name of padv.Query
object
Query that finds the artifacts that the task iterates over, specified as a
padv.Query
object or the name of a padv.Query
object. When you specify IterationQuery
, the task runs one time
for each artifact returned by the query. In the Process
Advisor app, the artifacts returned by IterationQuery
appear under task title.
For more information about task iterations, see Overview of Process Model.
Example: padv.builtin.query.FindProjectFile
InputDependencyQuery
— Finds artifact dependencies for task inputs
padv.Query
object | name of padv.Query
object
Query that finds artifact dependencies for task inputs, specified as a
padv.Query
object or the name of a padv.Query
object.
The build system runs the query specified by
InputDependencyQuery
to find the dependencies for the task
inputs, since those dependencies can impact if task results are up-to-date.
For more information about task inputs, see Overview of Process Model.
Example: padv.builtin.query.GetDependentArtifacts
Licenses
— List of licenses that task requires
["matlab_coder" "real-time_workshop"]
(default) | string
List of licenses that the task requires, specified as a string.
Data Types: string
LaunchToolAction
— Function that launches tool
@launchToolAction
(default) | function handle
Function that launches a tool, specified as the function handle.
When you point to a task in the Process Advisor app, you can click the ellipsis (...) to see more options. For built-in tasks, you have the option to launch a tool associated with the task.
For the task GenerateCode
, you can launch the Embedded
Coder app.
Data Types: function_handle
LaunchToolText
— Description of action that LaunchToolAction
property performs
"Open Embedded Coder"
(default) | string
Description of the action that the LaunchToolAction
property
performs, specified as a string.
Data Types: string
InputQueries
— Inputs to task
padv.Query
object | name of padv.Query
object | array of padv.Query
objects
Inputs to the task, specified as:
a
padv.Query
objectthe name of
padv.Query
objectan array of
padv.Query
objectsan array of names of
padv.Query
objects
By default, the task GenerateCode
gets the current model that the
task is iterating over by using the built-in query
padv.builtin.query.GetIterationArtifact
.
OutputDirectory
— Location for standard task outputs
path to code generation folder (default) | string
Location for standard task outputs, specified as a string.
By default, the task padv.builtin.task.GenerateCode
uses the path to the code generation
folder specified by the parameter
CodeGenFolder.
Data Types: string
CacheDirectory
— Location for additional cache files
path to simulation cache folder (default) | string
Location for additional cache files that the task generates, specified as a string. The cache directory can contain temporary files that do not need to be either saved in the task results or archived by a CI system.
By default, the task padv.builtin.task.GenerateCode
uses the path to the code generation
folder specified by the parameter
CacheFolder.
Data Types: string
TreatAsRefModel
— Setting that controls whether task generates reference model code or top model code
[]
(default) | true
or 1
| false
or 0
Setting that controls whether the task generates reference model code or top model code, specified as either:
[]
— Allow the task to automatically identify whether a model is a top model or a reference model before generating code.1
(true
) — Only generate reference model code.0
(false
) — Only generate top model code.
By default, the task automatically identifies whether a model is a top model or a
reference model before generating code. But you can specify
TreatAsRefModel
as true
or
false
if you want to override that behavior and only generate
reference model code or top model code.
Example: true
Data Types: logical
GenerateCodeOnly
— Generate code versus an executable file
false
or 0
(default) | true
or 1
Generate code versus an executable file, specified as a numeric or logical
1
(true
) or 0
(false
).
By default, the task generates code only and does not build an executable file.
Example: true
Data Types: logical
ObfuscateCode
— Generate obfuscated C code
false
or 0
(default) | true
or 1
Generate obfuscated C code, specified as a numeric or logical 1
(true
) or 0
(false
).
Example: true
Data Types: logical
UpdateThisModelReferenceTarget
— Conditional rebuild option for model reference build
"IfOutOfDateOrStructuralChange"
(default) | "Force"
| "IfOutOfDate"
Conditional rebuild option for model reference build, specified as either:
"Force"
"IfOutOfDateOrStructuralChange"
"IfOutOfDate"
Example: "IfOutOfDate"
ForceTopModelBuild
— Force top model of model hierarchy to build
false
or 0
(default) | true
or 1
Force top model of model hierarchy to build, specified as a numeric or logical
1
(true
) or 0
(false
).
Example: true
Data Types: logical
IncludeModelReferenceSimulationTargets
— Build model reference simulation targets
false
or 0
(default) | true
or 1
Build model reference simulation targets, specified as a numeric or logical
1
(true
) or 0
(false
).
Example: true
Data Types: logical
GenerateTraceReport
— Generate code traceability report
0
(false
) (default) | 1
(true
)
Generate code traceability report, specified as a numeric or logical
0
(false
) or 1
(true
). The traceability report can help you navigate more easily
between the generated code and the source
model.
To specify the name of the code traceability report, you can use the task property
TraceReportName
.
Example: 1
Data Types: logical
TraceReportName
— Name of code traceability report
"$ITERATIONARTIFACT$_CodeTrace.xlsx"
(default) | string
Name of code traceability report, specified as a string. The name must include the
Excel® spreadsheet file extension .xlsx
.
To generate a code traceability report, specify the task property
GenerateTraceReport
as 1
(true
). The built-in tasks use tokens, like
$ITERATIONARTIFACT$
, as placeholders for dynamic path resolution
during run-time. For more information, see Dynamically Resolve Paths with Tokens.
Example: "$ITERATIONARTIFACT$_TraceReport.xlsx"
Data Types: string
GenerateExternalCodeCache
— Setting to collect only SLXC files as task outputs
false
or 0
(default) | true
or 1
Setting to collect only SLXC files as task outputs, specified as a numeric or
logical 1
(true
) or 0
(false
).
Example: true
Data Types: logical
ExternalCodeCacheDirectory
— Location to save SLXC file
fullfile('$DEFAULTOUTPUTDIR$', "$ITERATIONARTIFACT$", "external_code_cache")
(default) | string
Location to save SLXC file, specified as a string.
The built-in tasks use tokens, like $DEFAULTOUTPUTDIR$
, as
placeholders for dynamic path resolution during run-time. For more information, see
Dynamically Resolve Paths with Tokens.
Data Types: string
TrackAllGeneratedCode
— Track all code files
false
or 0
(default) | true
or 1
Track all code files, not just
model.c
and model.h
files, specified as a
numeric or logical 1
(true
) or
0
(false
).
Example: true
Data Types: logical
Methods
Specialized Public Methods
This class overrides the following inherited methods.
run | Generate code using Embedded Coder Note You do not need to manually invoke this method. When you run a task using
the Process Advisor app or the
The function taskResult = run(obj, input) ... end |
dryRun |
Dry run the task to validate task inputs and generate
representative task outputs without actually running the task. The function taskResult = dryRun(obj, input) ... end |
launchToolAction | Launch the Embedded Coder app. Process Advisor uses this method when you open the tool associated with a task. |
Examples
Add Code Generation Task to Process
Add a task that can generate code for each model in the project using Embedded Coder.
Open the process model for your project. If you do not have a process model, open the Process Advisor app to automatically create a process model.
In the process model file, add the GenerateCode
task to your process
model by using the addTask
method.
codegenTask = pm.addTask(padv.builtin.task.GenerateCode);
You can reconfigure the task behavior by using the task properties. For example, to rebuild models if the build process detects changes in known dependencies of the model:
codegenTask.UpdateThisModelReferenceTarget = 'IfOutOfDate';
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)