Is it possible to programmatically get a list of all file dependencies included in my standalone application (Matlab Compiler )
36 views (last 30 days)
Show older comments
Hello,
I would like to compute the hash of all files that are included in my application by the Matlab Compiler at compilation time and then write the result (hashes) to disk, for achiving reasons. I use a script to build my application, not the Application Compiler add-on, which gives less customization options.
Even though, at compilation time, Matlab Compiler does a dependency file analysis, it doesn't output it in any way, at least as far as I can tell (workspace variable, result object nor in the console).
Hence my question.
I have wandered on the internet and didn't find an answer (at least with recent versions of Matlab: R2021b and up). Its seems there was a 'depfun' function at some point that could have helped, but it looks like it has been deprecated.
As a workaround, I currently create a dummy Matlab Project prior to compiling and at least get to retrieve the m-file list, like below.
proj_mainfile = 'mainApp.m';
tempDir = 'some_temp_directory'
% create dummy matlab project
buildProj = matlab.project.createProject('Name','buildProj.prj','Folder',tempDir);
% add main m-file
buildProj.addFile(proj_mainfile);
% update dependencies
buildProj.updateDependencies();
% extract dependency file list using digraph Nodes
filedep = buildProj.Dependencies.Nodes.Name(cellfun(@isfile,buildProj.Dependencies.Nodes.Name));
% delete dummy project
rmdir(tempDir,'s')
While the above works to get the m-files, it obviously isn't 'clean' and adds unecessary time to the compilation process, while the compiler already computed that list, but just won't output it.
By the way, the reason why I use a dummy Matlab project is that our source control solution is customized in a way that conflicts with the way the Matlab Projects manages path. So it isn't an option to work with that (we actually recently moved away from Matlab prj and do not plan on going back).
Any ideas on how to do this better, would be appreciated.
Thanks!
0 Comments
Answers (2)
Fabio Freschi
on 28 Sep 2023
Never used Matal Compiler, so I don't now if I'm of help. In any case I put my 50 cents in.
When I want to extract all matlab functions and all dependencies used by a main matlab script, and copy them into a folder in order to have a standalone project, I use these instructions
[fList,pList] = matlab.codetools.requiredFilesAndProducts('mainScript.m');
for i = 1:length(fList)
[status,msg,msgID] = copyfile(fList{i},'DestinationFolder');
end
So, my suggestion is to give a go to matlab.codetools.requiredFilesAndProducts and check the first output
2 Comments
Fabio Freschi
on 28 Sep 2023
My pleasure! Good to know that it helps!
and I'll keep my radar on to learn from possible improvements
Image Analyst
on 29 Sep 2023
I use my attached function.
Obviously it only finds functions called by your functions. Even if you hard coded some filename into your code to read that file in, it will not be found. So things like MAT files, Excel files, and any other data files and images whose filenames are hard-coded in or supposed to be there for the user to select interactively will have to be kept track of and be shipped with your app. They will have to be packaged yourself since the code does not know about them.
For example, the dependency analyzer will not know from this line:
tbl = readtable('mydata.xlsx');
that you want to ship mydata.xlsx with your app.
0 Comments
See Also
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!