-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_dist_package.m
57 lines (44 loc) · 2.25 KB
/
build_dist_package.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
function build_dist_package()
% Build the MATLAB toolbox distribution package.
% The release version is copied form the project file into the 'Contents.m' file.
% Docs on Toolbox Distribution:
% web(fullfile(docroot, 'matlab/creating-help.html?s_tid=CRUX_lftnav'))
cfdir = fileparts( mfilename('fullpath') ); % Get script directory
disp("Looking for project file");
prj_file_struct = dir(fullfile(cfdir, "*.prj")); % determine the prj file name, returns a struct
prj_file_full = fullfile(prj_file_struct(1).folder, prj_file_struct(1).name);
disp("... done: " + prj_file_full);
[~, prjbase] = fileparts(prj_file_full); % extract project base name form project file name
%% Check MATLAB and related tools, e.g.:
disp("Checking MATLAB version");
assert( ~verLessThan('MATLAB', '9.5'), 'MATLAB R2018b or higher is required' );
disp("... done");
%% Update Contents.m file
disp("Extracting toolbox version from " + prj_file_full);
tver = matlab.addons.toolbox.toolboxVersion(prj_file_full); % extract version from project file
disp("... done: version " + tver);
% read all lines of the Contents file
disp("Reading Contents.m");
contents_file_full = fullfile(cfdir, "tbx", "Contents.m");
lines = splitlines(string(fileread(contents_file_full))); % string array of lines
disp("... done");
% use file date of project file
disp("Getting file date of " + prj_file_full)
d = datetime(prj_file_struct(1).datenum, 'ConvertFrom', 'datenum', 'Format', 'dd-MMM-yyyy');
date_str = string(d);
disp("... done: " + date_str);
release_num = tver; % reuse version number as release number
% New version line for the Contents.m file
lines(2) = "% Version " + tver + " " + release_num + " " + date_str;
disp("Setting version information in Contents.m");
fileID = fopen(contents_file_full, 'w');
assert(fileID > -1);
fwrite(fileID, strtrim(lines.join(newline))); % write modified lines into Contents.m file
fclose(fileID); % close file
disp("... done: " + lines(2));
%% Package
mltbx = fullfile(cfdir, [prjbase '-' tver '.mltbx']);
disp("Creating package " + mltbx);
matlab.addons.toolbox.packageToolbox(prj_file_full, mltbx);
disp("... done");
end