Matlab buildtool subprojects
Matlab buildtool uses buildfile.m build plans that can each call other buildfile.m to stitch together Matlab subprojects from a top-level project. An example syntax for a top-level buildfile.m that invokes say Git submodule Matlab project is:
function plan = buildfile
plan = buildplan(localfunctions);
plan.DefaultTasks = "setup";
assert(~isMATLABReleaseOlderThan("R2024b"), "Subprojects with buildtool requires Matlab R2024b or newer")
end
function setupTask(context)
sub1 = fullfile(context.Plan.RootFolder, "MySubproject/buildfile.m")
% Matlab gitrepo() doesn't yet have the ability to run this command after cloning
if ~isfile(sub1)
ok = system("git -C " + context.Plan.RootFolder + " submodule update --init --recursive");
assert(ok == 0, "Failed to update MySubproject Git submodule");
end
buildtool("-buildFile", sub1, "setup")
% assumes that sub1 also has a task named setup that should be run
end