Create a task that uses two named inputs to analyze program files and two named outputs to store the lists of files and products required to run the program files. Tasks with specified inputs or outputs support incremental builds.
Open the example and then navigate to the named_io_example
folder, which contains a build file.
This code shows the contents of the build file. The build file has a task that analyzes program files and stores the lists of files and products required to run the program files:
To specify the program files and the mode of the dependency analysis, the task uses the inputs named FilesToAnalyze
and IncludeIndirectDependencies
. The Inputs
property of the task is a TaskInputs
object that contains the named inputs.
To specify where to write the lists of required files and products, the task uses the outputs named FileList
and ProductList
. The Outputs
property of the task is a TaskOutputs
object that contains the named outputs.
function plan = buildfile
plan = buildplan(localfunctions);
% Specify the program files to analyze and whether to include indirect dependencies
plan("dependencies").Inputs.FilesToAnalyze = files(plan,"source/**/*.m");
plan("dependencies").Inputs.IncludeIndirectDependencies = false;
% Specify where to write the lists of required files and products
plan("dependencies").Outputs.FileList = files(plan,"fileList.txt");
plan("dependencies").Outputs.ProductList = files(plan,"productList.txt");
end
function dependenciesTask(context)
% Determine required files and products
files = context.Task.Inputs.FilesToAnalyze.paths;
if context.Task.Inputs.IncludeIndirectDependencies
[fList,pList] = matlab.codetools.requiredFilesAndProducts(files);
else
[fList,pList] = matlab.codetools.requiredFilesAndProducts(files,"toponly");
end
writelines(fList,context.Task.Outputs.FileList.paths)
writelines({pList.Name},context.Task.Outputs.ProductList.paths)
end
Run the "dependencies"
task. The task analyzes the code in the source
folder and any of its subfolders, and writes the lists of the required files and products to separate text files.
** Starting dependencies
** Finished dependencies
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.
** Skipped dependencies: up-to-date
Add a file to the source
folder, and then rerun the task. The build tool runs the task because one of the inputs of the task has changed between consecutive builds.
** Starting dependencies
** Finished dependencies