1111
1212if isMATLABReleaseOlderThan(" R2023b" )
1313 plan(" test" ) = matlab .buildtool .Task(Actions = @legacy_test );
14- else
14+ elseif isMATLABReleaseOlderThan( " R2024a " )
1515 plan(" test" ) = matlab .buildtool .tasks .TestTask(" test" , Strict= false );
16+ else
1617 % can't use SourceFiles= if "mex" Task was run, even if plan("test").DisableIncremental = true;
1718 % this means incremental tests can't be used with MEX files (as of R2024b)
19+ plan(" test" ) = matlab .buildtool .tasks .TestTask(" test" , Strict= false , TestResults= " TestResults.xml" );
20+ end
1821
22+ if ~isMATLABReleaseOlderThan(" R2023b" )
1923 plan(" clean" ) = matlab .buildtool .tasks .CleanTask ;
2024end
2125
26+ plan(" build_c" ) = matlab .buildtool .Task(Actions = @subprocess_build_c );
27+ plan(" build_fortran" ) = matlab .buildtool .Task(Actions = @subprocess_build_fortran );
28+ plan(" test" ).Dependencies = [" build_c" , " build_fortran" ];
29+
2230if ~isMATLABReleaseOlderThan(" R2024a" )
2331 plan(" check" ) = matlab .buildtool .tasks .CodeIssuesTask(pkg_name , IncludeSubfolders= true , ...
2432 WarningThreshold= 0 , Results= " CodeIssues.sarif" );
@@ -68,7 +76,7 @@ function legacy_mex(context, compiler_opt, linker_opt)
6876
6977
7078function legacy_test(context )
71- r = runtests(fullfile( context .Plan .RootFolder , " test" ) , Strict= false );
79+ r = runtests(context .Plan .RootFolder + " / test" , Strict= false );
7280% Parallel Computing Toolbox takes more time to startup than is worth it for this task
7381
7482assert(~isempty(r ), " No tests were run" )
@@ -78,7 +86,7 @@ function legacy_test(context)
7886
7987function publishTask(context )
8088% publish HTML inline documentation strings to individual HTML files
81- outdir = fullfile( context .Plan .RootFolder , " docs" ) ;
89+ outdir = context .Plan .RootFolder + " / docs" ;
8290
8391publish_gen_index_html(" stdlib" , ...
8492 " A standard library of functions for Matlab." , ...
@@ -87,6 +95,68 @@ function publishTask(context)
8795end
8896
8997
98+ function subprocess_build_c(context )
99+
100+ td = context .Plan .RootFolder + " /test" ;
101+ src_c = td + " /main.c" ;
102+ exe = td + " /printer_c.exe" ;
103+
104+ ccObj = mex .getCompilerConfigurations(' c' );
105+
106+ cc = ccObj .Details .CompilerExecutable ;
107+
108+ outFlag = " -o" ;
109+ shell = " " ;
110+ shell_arg = " " ;
111+ msvcLike = ispc && endsWith(cc , " cl" );
112+ if msvcLike
113+ shell = strtrim(ccObj .Details .CommandLineShell );
114+ shell_arg = ccObj .Details .CommandLineShellArg ;
115+ outFlag = " /link /out:" ;
116+ end
117+
118+ cmd = join([cc , src_c , outFlag , exe ]);
119+ if shell ~= " "
120+ cmd = join([shell , shell_arg , cmd ]);
121+ end
122+
123+ [r , m ] = system(cmd );
124+ if r ~= 0
125+ warning(" failed to build TestSubprocess printer_c.exe " + m )
126+ end
127+
128+ end
129+
130+
131+ function subprocess_build_fortran(context )
132+
133+ td = context .Plan .RootFolder + " /test" ;
134+ src = td + " /main.f90" ;
135+ exe = td + " /printer_fortran.exe" ;
136+
137+ fcObj = mex .getCompilerConfigurations(' Fortran' );
138+ if isempty(fcObj )
139+ fc = getenv(" FC" );
140+ if isempty(fc )
141+ warning(" set FC environment variable to the Fortran compiler executable, or do 'mex -setup fortran' to configure the Fortran compiler" )
142+ return
143+ end
144+ else
145+ fc = fcObj .Details .CompilerExecutable ;
146+ end
147+
148+ outFlag = " -o" ;
149+
150+ cmd = join([fc , src , outFlag , exe ]);
151+
152+ [r , m ] = system(cmd );
153+ if r ~= 0
154+ warning(" failed to build TestSubprocess printer_fortran.exe " + m )
155+ end
156+
157+ end
158+
159+
90160function srcs = get_mex_sources(build_all )
91161arguments
92162 build_all (1 ,1 ) logical = false
0 commit comments