5858 options.AdditionalFiles {mustBeText }
5959 options.AutoDetectFiles (1 ,1 ) {mustBeNumericOrLogical } = true
6060 end
61+ % check for anonymous function
62+ fs = functions(startfun );
63+ if fs .type == " anonymous"
64+ error(" opentelemetry:autoinstrument:AutoTrace:AnonymousFunction" , ...
65+ " Anonymous functions are not supported." );
66+ end
6167 obj.StartFunction = startfun ;
6268 startfunname = func2str(startfun );
63- processFileInput(startfunname ); % validate startfun
69+ startfunname = processFileInput(startfunname ); % validate startfun
6470 if options .AutoDetectFiles
6571 if isdeployed
6672 % matlab.codetools.requiredFilesAndProducts is not
7682 end
7783 else
7884 % only include the input file, not its dependencies
79- files = string(which( startfunname )) ;
85+ files = startfunname ;
8086 end
8187 % add extra files, this is intended for files
8288 % matlab.codetools.requiredFilesAndProducts somehow missed
8389 if isfield(options , " AdditionalFiles" )
84- incfiles = string(options .AdditionalFiles );
85- for i = 1 : numel(incfiles )
86- incfiles(i ) = which(incfiles(i )); % get the full path
87- processFileInput(incfiles(i )); % validate additional file
90+ incinput = string(options .AdditionalFiles );
91+ incfiles = [];
92+ for i = 1 : numel(incinput )
93+ % validate additional file
94+ incfiles = [incfiles ; processFileOrFolderInput(incinput(i ))]; % #ok<AGROW>
8895 end
8996 files = union(files , incfiles );
9097 end
94101
95102 % filter out excluded files
96103 if isfield(options , " ExcludeFiles" )
97- excfiles = string(options .ExcludeFiles );
98- for i = 1 : numel(excfiles )
99- excfiles(i ) = which(excfiles(i )); % get the full path
104+ excinput = string(options .ExcludeFiles );
105+ excfiles = [];
106+ for i = 1 : numel(excinput )
107+ % validate exclude file
108+ excfiles = [excfiles ; processFileOrFolderInput(excinput(i ))]; % #ok<AGROW>
100109 end
101110 files = setdiff(files , excfiles );
102111 end
@@ -155,15 +164,13 @@ function handleError(obj, ME)
155164end
156165
157166% check input file is valid
158- function processFileInput(f )
167+ function f = processFileInput(f )
159168f = string(f ); % force into a string
160- if startsWith(f , ' @' ) % check for anonymous function
161- error(" opentelemetry:autoinstrument:AutoTrace:AnonymousFunction" , ...
162- replace(f , " \" , " \\" ) + " is an anonymous function and is not supported." );
163- end
164169[~ ,~ ,fext ] = fileparts(f ); % check file extension
165170filetype = exist(f , " file" ); % check file type
166- if ~(filetype == 2 && ismember(fext , [" " " .m" " .mlx" ]))
171+ if filetype == 2 && ismember(fext , [" " " .m" " .mlx" ])
172+ f = string(which(f ));
173+ else
167174 if exist(f , " builtin" )
168175 error(" opentelemetry:autoinstrument:AutoTrace:BuiltinFunction" , ...
169176 replace(f , " \" , " \\" ) + " is a builtin function and is not supported." );
@@ -172,4 +179,20 @@ function processFileInput(f)
172179 replace(f , " \" , " \\" ) + " is not found or is not a valid MATLAB file with a .m or .mlx extension." );
173180 end
174181end
182+ end
183+
184+ % check input file or folder is valid
185+ function f = processFileOrFolderInput(f )
186+ f = string(f ); % force into a string
187+ if isfolder(f )
188+ % expand the directory
189+ mfileinfo = dir(fullfile(f , " *.m" ));
190+ mfiles = fullfile(string({mfileinfo .folder }), string({mfileinfo .name }));
191+ mlxfileinfo = dir(fullfile(f , " *.mlx" ));
192+ mlxfiles = fullfile(string({mlxfileinfo .folder }), string({mlxfileinfo .name }));
193+ f = [mfiles ; mlxfiles ];
194+ else
195+ % file
196+ f = processFileInput(f );
197+ end
175198end
0 commit comments