Skip to content

Commit e4271c2

Browse files
committed
buildfile: validate arguments
1 parent 58f584b commit e4271c2

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

buildfile.m

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
Tag="python", ...
6969
SourceFiles=pkg_root, RunOnlyImpactedTests=true,...
7070
TestResults="TestResults_python.xml", Strict=true);
71-
71+
7272
addons = matlab.addons.installedAddons;
7373
if contains(addons.Name, "Matlab Test")
7474
plan("coverage") = matlab.buildtool.tasks.TestTask(test_root, ...
@@ -189,6 +189,13 @@ function build_exe(context)
189189

190190

191191
function [comp, shell] = get_compiler(lang)
192+
arguments (Input)
193+
lang (1,1) string {mustBeMember(lang, ["c", "c++", "fortran"])}
194+
end
195+
arguments (Output)
196+
comp string {mustBeScalarOrEmpty}
197+
shell string {mustBeScalarOrEmpty}
198+
end
192199

193200
lang = lower(lang);
194201

@@ -211,7 +218,6 @@ function build_exe(context)
211218
if isempty(comp)
212219
disp("set CC environment variable to the C compiler path, or do 'mex -setup c'")
213220
end
214-
otherwise, error("language not known " + lang)
215221
end
216222
else
217223
comp = co.Details.CompilerExecutable;
@@ -238,10 +244,18 @@ function build_exe(context)
238244

239245

240246
function [comp, shell, outFlag] = get_build_cmd(lang)
247+
arguments (Input)
248+
lang (1,1) string {mustBeMember(lang, ["c", "c++", "fortran"])}
249+
end
250+
arguments (Output)
251+
comp string {mustBeScalarOrEmpty}
252+
shell string {mustBeScalarOrEmpty}
253+
outFlag (1,1) string
254+
end
241255

242256
[comp, shell] = get_compiler(lang);
243257

244-
if contains(shell, "Visual Studio") || contains(comp, "ifx.exe")
258+
if any(contains(shell, "Visual Studio")) || endsWith(comp, "ifx.exe")
245259
outFlag = "/Fo" + tempdir + " /link /out:";
246260
else
247261
outFlag = "-o";
@@ -251,9 +265,12 @@ function build_exe(context)
251265

252266

253267
function srcs = get_mex_sources(build_all)
254-
arguments
268+
arguments (Input)
255269
build_all (1,1) logical = false
256270
end
271+
arguments (Output)
272+
srcs cell
273+
end
257274

258275
srcs = {
259276
"src/remove.cpp", ...
@@ -272,6 +289,10 @@ function build_exe(context)
272289

273290

274291
function [compiler_opt, linker_opt] = get_compiler_options()
292+
arguments (Output)
293+
compiler_opt (1,:) string
294+
linker_opt (1,1) string
295+
end
275296

276297
cxx = mex.getCompilerConfigurations('c++');
277298
flags = cxx.Details.CompilerFlags;
@@ -318,8 +339,9 @@ function build_exe(context)
318339

319340

320341
function comp = get_fortran_compiler()
321-
322-
disp("set FC environment variable to the Fortran compiler path, or do 'mex -setup fortran'")
342+
arguments (Output)
343+
comp string {mustBeScalarOrEmpty}
344+
end
323345

324346
if ismac()
325347
p = '/opt/homebrew/bin/';
@@ -331,13 +353,14 @@ function build_exe(context)
331353
if isempty(p)
332354
p = getenv("MW_MINGW64_LOC");
333355
end
334-
if ~isempty(p) && ~endsWith(p, ["bin", "bin/"])
356+
if ~endsWith(p, ["bin", "bin/"])
335357
p = p + "/bin";
336358
end
337359
else
338360
p = '';
339361
end
340362

363+
comp = string.empty;
341364
for fc = ["flang", "gfortran", "ifx"]
342365
comp = stdlib.which(fc, p);
343366
if ~isempty(comp)
@@ -347,4 +370,6 @@ function build_exe(context)
347370
end
348371
end
349372

373+
disp("to hint Fortran compiler, setenv('FC', <Fortran compiler path>), or do 'mex -setup fortran'")
374+
350375
end

test/is_capable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function is_capable(tc, f)
5757

5858
elseif contains(n, ".native.")
5959

60-
if endsWith(n, "set_permissions")
60+
if endsWith(n, ["is_exe", "is_readable", "is_writable", "set_permissions"])
6161
tc.assumeFalse(isMATLABReleaseOlderThan('R2025a'))
6262
end
6363

0 commit comments

Comments
 (0)