Main Content

matlab.buildtool.TaskContext Class

Namespace: matlab.buildtool

Context provided when task runs

Since R2022b

Description

The matlab.buildtool.TaskContext class provides context-specific information to task actions. When the build runner runs a task, it creates a TaskContext object that contains information about the task as well as the plan being run. Actions of the running task have access to this information.

The build runner instantiates this class. You cannot create an object of the class directly.

The matlab.buildtool.TaskContext class is a handle class.

Properties

expand all

Copy of the task being run by the build runner, returned as a matlab.buildtool.Task object. This object provides access to properties of the task being run. Modifying the object does not affect the original task.

Attributes:

GetAccess
public
SetAccess
immutable

Copy of the plan being run by the build runner, returned as a matlab.buildtool.Plan object. This object provides access to properties of the plan being run. Modifying the object does not affect the original plan.

Attributes:

GetAccess
public
SetAccess
immutable

Examples

collapse all

Create a task named "pcode" that uses the context provided by the build runner to access its inputs. (For illustrative purposes, the "pcode" task in this example is created using a task function. The recommended practice is to create the task using the matlab.buildtool.tasks.PcodeTask class.)

Open the example and then navigate to the task_context_example folder, which contains a build file.

cd task_context_example

This code shows the contents of the build file.

function plan = buildfile
% Create a plan from the task function
plan = buildplan(localfunctions);

% Specify the inputs and outputs of the "pcode" task
plan("pcode").Inputs = "source/**/*.m";
plan("pcode").Outputs = plan("pcode").Inputs.replace(".m",".p");
end

function pcodeTask(context)
% Create P-code files
filePaths = context.Task.Inputs.paths;
pcode(filePaths{:},"-inplace")
end

Run the "pcode" task. The task obfuscates its inputs and creates the P-code files in the same folders as the inputs.

buildtool pcode
** Starting pcode
** Finished pcode

Run the task again. The build tool skips the task because none of the inputs or outputs of the task have changed since the last run.

buildtool pcode
** Skipped pcode: up-to-date

Add a file to the source folder, and then rerun the task. The build tool runs the task because the inputs of the task have changed between consecutive builds.

fclose(fopen(fullfile("source","newFile.m"),"w"));
buildtool pcode
** Starting pcode
** Finished pcode

Version History

Introduced in R2022b