-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathbuildfile.m
150 lines (124 loc) · 4.69 KB
/
buildfile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function plan = buildfile
%% Define and run tasks.
% Copyright 2023 The MathWorks, Inc.
top_folder = currentProject().RootFolder;
test_definitions = [
fullfile(top_folder, "BEV", "Test", "BEV_UnitTest_MQC.m")
...
fullfile(top_folder, "Components", "BatteryHighVoltage", "Test", "BatteryHV_UnitTest.m")
fullfile(top_folder, "Components", "BatteryHighVoltage", "Test", "BatteryHV_UnitTest_MQC.m")
...
fullfile(top_folder, "Components", "BEVController", "Test", "BEVController_UnitTest_MQC.m")
...
fullfile(top_folder, "Components", "ControllerAndEnvironment", "Test", "CtrlEnv_UnitTest_MQC.m")
...
fullfile(top_folder, "Components", "MotorDriveUnit", "Test", "MotorDriveUnit_UnitTest_MQC.m")
...
fullfile(top_folder, "Components", "Vehicle1D", "Test", "Vehicle1D_UnitTest.m")
fullfile(top_folder, "Components", "Vehicle1D", "Test", "Vehicle1D_UnitTest_MQC.m")
fullfile(top_folder, "Components", "Vehicle1D", "Test", "Vehicle1DPerformanceDesignApp_uitest.m")
...
fullfile(top_folder, "Components", "VehicleSpeedReference", "VehSpdRef_harness_model_test.m")
fullfile(top_folder, "Components", "VehicleSpeedReference", "SimulationCases", "VehSpdRef_Case_test.m")
...
fullfile(top_folder, "Test", "BEVProject_UnitTest_MQC.m")
];
% This function runs tasks such as identifing code issues,
% running tests, or performing your custom tasks.
% To see available tasks, run the following command in MATLAB Command Window.
%
% buildtool -tasks
%
% This function uses MATLAB build tool API, which was first released in R2022b.
% Incremental builds are supported since R2023a.
% Task for running tests is supported since R2023b.
% For information about MATLAB build tool, see the documentation:
%
% - Overview of MATLAB Build Tool
% https://mathworks.com/help/matlab/matlab_prog/overview-of-matlab-build-tool.html
%
% - Improve Performance with Incremental Builds
% https://mathworks.com/help/matlab/matlab_prog/improve-performance-with-incremental-builds.html
%
% - Task for running tests
% https://mathworks.com/help/matlab/ref/matlab.buildtool.tasks.testtask-class.html
% buildtool -tasks
% buildtool CodeIssues
% buildtool CheckProject
% buildtool Test
% buildtool Clean
% buildtool CodeIssues CheckProject Test
%%
% Create a build plan from task functions.
%
% `localfunctions` returns a cell array of function handles
% to all local functions in the current file.
%
% For information about buildplan, see the documentation:
% - https://mathworks.com/help/matlab/ref/buildplan.html
%
plan = buildplan(localfunctions);
% Add a task to identify code issues.
plan("CodeIssues") = matlab.buildtool.tasks.CodeIssuesTask( ...
Results = "cache/buildtool-results/code-issues.sarif");
plan("CheckProject").Dependencies = "CodeIssues";
% Add a task to run tests.
plan("Test") = matlab.buildtool.tasks.TestTask( ...
SourceFiles = pwd, ...
TestResults = [
"cache/buildtool-results/test-results.xml"
"cache/buildtool-results/test-results.pdf"
], ...
CodeCoverageResults = [
"cache/buildtool-results/code-coverage.html"
"cache/buildtool-results/code-coverage.xml"
] );
plan("Test").Dependencies = "CodeIssues";
plan("Test").Tests = test_definitions;
plan("Clean") = matlab.buildtool.tasks.CleanTask;
% plan("LiveScriptToJupyterNotebook").Inputs = "**/*.mlx";
% plan("LiveScriptToJupyterNotebook").Outputs = ...
% replace(plan("LiveScriptToJupyterNotebook").Inputs, ".mlx", ".ipynb");
plan.DefaultTasks = [
"CodeIssues"
"CheckProject"
"Test"
];
end % function
%% Local functions == task functions
% Task functions are local functions in the build file (this file).
%
% - Function name must end with the word "Task", which is case insensitive.
% The build tool generates task names from task function names
% by removing the "Task" suffix.
% For example, a task function `testTask` results in a task named "test".
%
% - A task function must accept a TaskContext object as its first input,
% even if the task ignores it.
%
% - The build tool treats the first help text line,
% often called the H1 line, of the task function as the task description.
%{
function LiveScriptToMarkdownTask(context)
%% Export Live Scripts to Markdown files
%
% buildtool LiveScriptToMarkdown
arguments
context (1,1) matlab.buildtool.TaskContext
end
mlxFiles = context.Task.Inputs.paths;
mdFiles = context.Task.Outputs.paths;
for idx = 1:numel(mlxFiles)
disp("Generating Markdown file from Live Script:")
disp(" " + mlxFiles(idx))
LiveScript_Utility.CheckAndGenerateMarkdown(mlxFiles(idx))
% export(mlxFiles(idx), mdFiles(idx), Run=true);
end % for
end % function
%}
function CheckProjectTask(~)
%% Run MATLAB project integrity checks
%
% buildtool CheckProject
BEVProject_CheckProject
end % function