-
Notifications
You must be signed in to change notification settings - Fork 2
/
package_toolbox.m
49 lines (40 loc) · 1.18 KB
/
package_toolbox.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
function package_toolbox
% Packages this toolbox as a Matlab Toolbox .mltbx file
%
% package_toolbox
%
% The project must be loaded on to the Matlab path in order for this to work.
tbxInfo = toolbox_info;
tbxName = tbxInfo.name;
if ~isfolder('dist')
mkdir('dist');
end
% Munge the project file
% Toolboxes don't support "-<pre>" suffixes in versions
tbxVer = tbxInfo.version;
baseTbxVer = regexprep(tbxVer, '-.*', '');
prjInFile = sprintf('%s.prj.in', tbxName);
prjFile = sprintf('%s.prj', tbxName);
prjTxt = fileread(prjInFile);
prjTxt = strrep(prjTxt, '${PROJECT_VERSION}', baseTbxVer);
spew(prjFile, prjTxt);
% I can't control the output file name from the project file, so we have to move
% it ourselves
builtFile = [tbxName '.mltbx'];
targetFile = sprintf('dist/%s-%s.mltbx', tbxName, tbxVer);
if isfile(targetFile)
delete(targetFile);
end
matlab.addons.toolbox.packageToolbox(prjFile);
movefile(builtFile, targetFile);
delete(prjFile);
fprintf('%s packaged to %s\n', tbxName, targetFile);
end
function spew(file, txt)
[fid,msg] = fopen(file, 'w');
RAII.fid = onCleanup(@() fclose(fid));
if fid < 1
error('Failed opening file %s for writing: %s', file, msg);
end
fprintf(fid, '%s', txt);
end