forked from ranford/Mass-Spring-Damper
-
Notifications
You must be signed in to change notification settings - Fork 6
/
buildfile.m
168 lines (125 loc) · 4.19 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
function plan = buildfile
plan = buildplan(localfunctions);
plan("test").Dependencies = ["mex", "pcode","setup"];
plan("toolbox").Dependencies = ["lint", "test", "doc"];
plan("doc").Dependencies = "docTest";
plan("docTest").Dependencies = "setup";
plan("install").Dependencies = "integTest";
plan("integTest").Dependencies = "toolbox";
plan("lintAll") = matlab.buildtool.Task("Description","Find code issues in source and tests");
plan("lintAll").Dependencies = ["lint", "lintTests"];
plan.DefaultTasks = "integTest";
end
function setupTask(context)
% Setup paths for the build
addpath(fullfile(context.Plan.RootFolder,"toolbox"));
addpath(fullfile(context.Plan.RootFolder,"toolbox","doc"));
end
function lintTask(~)
% Find static code issues
issues = codeIssues(["toolbox", "pcode"]);
if ~isempty(issues.Issues)
disp(formattedDisplayText(issues.Issues,"SuppressMarkup",true));
disp("Detected code issues in source")
end
if ~isempty(issues.SuppressedIssues)
disp(formattedDisplayText(issues.SuppressedIssues,"SuppressMarkup",true));
disp("Detected suppressed issues in source")
end
end
function mexTask(~)
% Compile mex files
mex mex/convec.c -outdir toolbox/;
end
function docTask(~)
% Generate the doc pages
connector.internal.startConnectionProfile("loopbackHttps");
com.mathworks.matlabserver.connector.api.Connector.ensureServiceOn();
export("toolbox/doc/GettingStarted.mlx","toolbox/doc/GettingStarted.html");
end
function docTestTask(~)
% Test the doc and examples
results = runtests("tests/doc");
disp(results);
assertSuccess(results);
end
function testTask(~)
% Run the unit tests
results = runtests("tests");
disp(results);
assertSuccess(results);
end
function lintTestsTask(~)
% Find code issues in test code
issues = codeIssues("tests");
if ~isempty(issues.Issues)
disp(formattedDisplayText(issues.Issues,"SuppressMarkup",feature("hotlinks")));
disp("Detected code issues in tests")
end
if ~isempty(issues.SuppressedIssues)
disp(formattedDisplayText(issues.SuppressedIssues,"SuppressMarkup",feature("hotlinks")));
disp("Detected suppressed issues in tests")
end
end
function toolboxTask(~)
% Create an mltbx toolbox package
dir toolbox/*.mex*
matlab.addons.toolbox.packageToolbox("Mass-Spring-Damper.prj","release/Mass-Spring-Damper.mltbx");
end
function pcodeTask(context)
% Obfuscate m-files
% Grab the help text for the pcoded function to generate a help-only m-file
mfile = "pcode/springMassDamperDesign.m";
helpText = deblank(string(help(mfile)));
helpText = split(helpText,newline);
helpText = replaceBetween(helpText, 1, 1, "%"); % Add comment symbols
% Write the file
fid = fopen("toolbox/springMassDamperDesign.m","w");
closer = onCleanup(@() fclose(fid));
fprintf(fid, "%s\n", helpText);
% Now pcode the file
startDir = cd("toolbox/");
cleaner = onCleanup(@() cd(startDir));
pcode(fullfile(context.Plan.RootFolder,"pcode/springMassDamperDesign.m"));
end
function cleanTask(~)
% Clean all derived artifacts
derivedFiles = [...
"toolbox/springMassDamperDesign.m"
"toolbox/springMassDamperDesign.p"
"toolbox/convec." + mexext
"toolbox/doc/GettingStarted.html"
"release/Mass-Spring-Damper.mltbx"
];
arrayfun(@deleteFile, derivedFiles);
end
function integTestTask(~)
% Run integration tests
import matlab.addons.toolbox.installToolbox;
import matlab.addons.toolbox.uninstallToolbox;
sourceFile = which("simulateSystem");
% Remove source
sourcePaths = cellstr(fullfile(pwd, ["toolbox", "toolbox" + filesep + "doc"]));
origPath = rmpath(sourcePaths{:});
pathCleaner = onCleanup(@() path(origPath));
% Install Toolbox
tbx = installToolbox("release/Mass-Spring-Damper.mltbx");
tbxCleaner = onCleanup(@() uninstallToolbox(tbx));
assert(~strcmp(sourceFile,which("simulateSystem")), ...
"Did not setup integ environment toolbox correctly");
results = runtests("tests","IncludeSubfolders",true);
disp(results);
assertSuccess(results);
clear pathCleaner tbxCleaner;
assert(strcmp(sourceFile,which("simulateSystem")), ...
"Did not restore integ environment correctly");
end
function installTask(~)
% Install the toolbox locally
matlab.addons.toolbox.installToolbox("release/Mass-Spring-Damper.mltbx");
end
function deleteFile(file)
if exist(file,"file")
delete(file);
end
end