forked from e0404/matRad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatRad_buildStandalone.m
More file actions
248 lines (216 loc) · 11 KB
/
Copy pathmatRad_buildStandalone.m
File metadata and controls
248 lines (216 loc) · 11 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
function buildResult = matRad_buildStandalone(varargin)
% Compiles the standalone executable & packages installer using Matlab's
% Compiler Toolbox
%
% References
% -
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Copyright 2020-2026 the matRad development team.
%
% This file is part of the matRad project. It is subject to the license
% terms in the LICENSE file found in the top-level directory of this
% distribution and at https://github.com/e0404/matRad/LICENSE.md. No part
% of the matRad project, including this file, may be copied, modified,
% propagated, or distributed except according to the terms contained in the
% LICENSE file.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
matRad_cfg = matRad_rc;
matRadRoot = matRad_cfg.matRadRoot;
standaloneFolder = fullfile(matRadRoot, 'standalone');
% Setup Input Parsing
p = inputParser;
p.addParameter('isRelease', false, @islogical); % By default we compile a snapshot of the current branch
p.addParameter('compileWithRT', false, @islogical); % By default we don't package installers with runtime
p.addParameter('buildDir', fullfile(matRadRoot, 'build'), @(x) ischar(x) || isstring(x)); % Build directory
p.addParameter('verbose', false, @islogical);
p.addParameter('docker', false, @islogical);
p.addParameter('java', false, @islogical);
p.addParameter('python', false, @islogical);
p.addParameter('json', [], @(x) isempty(x) || ischar(x) || isstring(x));
% Parse and manage inputs
p.parse(varargin{:});
isRelease = p.Results.isRelease;
compileWithRT = p.Results.compileWithRT;
buildDir = p.Results.buildDir;
buildDocker = all(p.Results.docker);
buildJava = all(p.Results.java);
buildPython = all(p.Results.python);
json = p.Results.json;
if all(p.Results.verbose)
verbose = 'On';
else
verbose = 'Off';
end
if compileWithRT
rtOption = 'installer';
else
rtOption = 'web';
end
% Display OS for debugging and information
arch = computer('arch');
fprintf('Build Architecture: %s\n', arch);
archcheck = string([ispc, isunix, ismac]).cellstr();
fprintf('pc\t\tunix\tmac\n%s\t%s\t%s\n', archcheck{:});
% Check build directory
try
mkdir(buildDir);
catch ME
error(ME.identifier, 'Could not create build directory %s\n Error:', buildDir, ME.message);
end
% Docker build?
if buildDocker && isunix && ~ismac
warning('Can''t build docker container. Only works on linux!');
buildDocker = false;
end
[~, versionFull] = matRad_version();
if isRelease
vernumApp = sprintf('%d.%d.%d', versionFull.major, versionFull.minor, versionFull.patch);
vernumInstall = vernumApp;
% vernumInstall = sprintf('%d.%d',versionFull.major,versionFull.minor);
else
vernumApp = sprintf('%d.%d.%d.%d', versionFull.major, versionFull.minor, versionFull.patch, versionFull.revision);
vernumInstall = vernumApp;
% vernumInstall = sprintf('%d.%d',versionFull.major,versionFull.minor);
end
% elseif isempty(versionFull.commitID)
% vernum = sprintf('%d.%d.%d.dev',versionFull.major,versionFull.minor,versionFull.patch);
% else
% vernum = sprintf('%d.%d.%d.%s/%s',versionFull.major,versionFull.minor,versionFull.patch,versionFull.branch,versionFull.commitID(1:8));
% end
buildResult.version = vernumInstall;
buildResult.versionDetail = versionFull;
%% Set Options and Compile
try
buildOpts = compiler.build.StandaloneApplicationOptions('matRadGUI.m', ...
'OutputDir', buildDir, ...
'ExecutableIcon', fullfile(standaloneFolder, 'matRad_icon.png'), ...
'AutodetectDataFiles', 'on', ...
'AdditionalFiles', {'matRad', 'thirdParty', 'matRad_rc.m'}, ...
'EmbedArchive', 'on', ...
'ExecutableName', 'matRad', ...
'ExecutableSplashScreen', fullfile(standaloneFolder, 'matRad_splashscreen.png'), ...
'ExecutableVersion', vernumApp, ...
'TreatInputsAsNumeric', 'off', ...
'Verbose', verbose);
if ispc
resultsStandalone = compiler.build.standaloneWindowsApplication(buildOpts);
else
resultsStandalone = compiler.build.standaloneApplication(buildOpts);
end
buildResult.standalone.compiledFiles = resultsStandalone.Files;
catch ME
warning(ME.identifier, 'Failed to compile standalone due to %s', ME.message);
end
%% Package
if ispc
readmeFile = 'readme_standalone_windows.txt';
elseif ismac
readmeFile = 'readme_standalone_mac.txt';
else
readmeFile = 'readme_standalone_linux.txt';
end
installerId = arch;
additionalFiles = {fullfile(matRadRoot, 'AUTHORS.txt'), fullfile(matRadRoot, 'LICENSE.md'), fullfile(standaloneFolder, readmeFile)};
description = ['matRad is an open source software for radiation treatment planning of intensity-modulated photon, ' ...
'proton, and carbon ion therapy started in 2015 in the research group "Radiotherapy Optimization" ', ...
'within the Department of Medical Physics in Radiation Oncology at the German Cancer Research Center - DKFZ.'];
installationNotes = ['matRad contains precompiled libraries and third party software. In some cases, ' ...
'those precompiled libraries may not run out of the box on your system. ' ...
'Please contact us should this be the case. ' ...
'For the third party licenses, check the subfolder in the matRad installation directory.'];
summary = 'matRad is an open source treatment planning system for radiation therapy written in Matlab.';
try
packageOpts = compiler.package.InstallerOptions(resultsStandalone, ...
'AdditionalFiles', additionalFiles, ...
'ApplicationName', 'matRad', ...
'AuthorCompany', 'German Cancer Research Center (DKFZ)', ...
'AuthorEmail', 'contact@matRad.org', ...
'AuthorName', 'matRad development team @ DKFZ', ...
'Description', description, ...
'InstallationNotes', installationNotes, ...
'InstallerIcon', fullfile(standaloneFolder, 'matRad_icon.png'), ...
'InstallerLogo', fullfile(standaloneFolder, 'matRad_installscreen.png'), ...
'InstallerSplash', fullfile(standaloneFolder, 'matRad_splashscreen.png'), ...
'InstallerName', sprintf('matRad_installer_%s_v%s', installerId, vernumApp), ...
'OutputDir', fullfile(buildDir, 'installer'), ...
'RuntimeDelivery', rtOption, ...
'Summary', summary, ...
'Version', vernumInstall, ...
'Verbose', verbose);
compiler.package.installer(resultsStandalone, 'Options', packageOpts);
outFiles = dir([packageOpts.OutputDir filesep packageOpts.InstallerName '.*']);
outFiles = arrayfun(@(f) fullfile(f.folder, f.name), outFiles, 'UniformOutput', false);
buildResult.standalone.installerFiles = outFiles;
catch ME
warning(ME.identifier, 'Failed to package standalone installer due to %s!', ME.message);
end
%% Python
if buildPython
functionFiles = {'matRadGUI.m', ...
'matRad/matRad_generateStf.m', ...
'matRad/matRad_calcDoseForward.m', ...
'matRad/matRad_calcDoseInfluence.m', ...
'matRad/matRad_fluenceOptimization.m', ...
'matRad/matRad_directApertureOptimization.m', ...
'matRad/matRad_sequencing.m', ...
'matRad/matRad_planAnalysis.m'};
sampleGenerationFiles = {'matRad.m'};
try
pythonOpts = compiler.build.PythonPackageOptions(functionFiles, ...
'AdditionalFiles', {'matRad', 'thirdParty', 'matRad_rc.m'}, ...
'SampleGenerationFiles', sampleGenerationFiles, ...
'Verbose', verbose, ...
'PackageName', 'pyMatRad', ...
'OutputDir', fullfile(buildDir, 'python'));
resultsPython = compiler.build.pythonPackage(pythonOpts);
buildResult.python.packageFiles = resultsPython.Files;
catch ME
warning(ME.identifier, 'Java build failed due to %s!', ME.message);
end
end
%% Java
if buildJava
javaOpts = compiler.build.JavaPackageOptions('matRadGUI.m', ...
'AdditionalFiles', {'matRad', 'thirdParty', 'matRad_rc.m'}, ...
'Verbose', verbose);
try
resultsJava = compiler.build.javaPackage(javaOpts);
buildResult.java.packageFiles = resultsJava.Files;
catch ME
warning(ME.identifier, 'Java build failed due to %s!', ME.message);
end
end
%% Docker
if buildDocker
try
if isRelease
imageName = ['matRad:' vernumInstall];
else
imageName = 'matRad:develop';
end
dockerOpts = compiler.package.DockerOptions(results, ...
'AdditionalInstructions', '', ...
'AdditionalPackages', '', ...
'ContainerUser', 'appuser', ...
'DockerContext', fullfile(buildDir, 'docker'), ...
'ExecuteDockerBuild', 'on', ...
'ImageName', imageName);
compiler.package.docker(results, 'Options', dockerOpts);
buildResult.docker.image = dockerOpts.ImageName;
catch ME
warning(ME.identifier, 'Java build failed due to %s!', ME.message);
end
end
if ~isempty(json)
try
fH = fopen(json, 'w');
jsonStr = jsonencode(buildResult, "PrettyPrint", true);
fwrite(fH, jsonStr);
fclose(fH);
catch ME
warning(ME.identifier, 'Could not open JSON file for writing: %s', ME.message);
end
end