Is it possible to programmatically get a list of all file dependencies included in my standalone application (Matlab Compiler )

45 次查看(过去 30 天)
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!

采纳的回答

Fabio Freschi
Fabio Freschi 2023-9-28
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 个评论
Sébastien Doré
Sébastien Doré 2023-9-28
Fabio,
50 cents worth a least a dollar, surely more actually ! ;-)
This (almost) gets me the same list as my dummy project code above, but in a one liner and faster. Big improvement.
Thank you for this !
'Almost' because I also get 2 additionnal files that I don't get with my 'hack' (not sure why):
1) a custom SVG image integrated in my application (good thing)
2) 'C:\Program Files\MATLAB\R2021b\toolbox\local\userpath.m' (odd as no other native matlab function are included, but OK I guess as I do use it in my main script). I'll just need to filter it out manually using a regexp somehow...
For now, I'll retain from marking your reply as an accepted answer in case someone comes up with a way to get the list as a direct output of the compilation process. But it is indeed very close to what I was looking for.
Intuitively, it seems to me that the
compiler.build.Results % output object from:
compiler.build.StandaloneApplication() % function that actually builds the app
should include the dependency file list. It even has a 'Files' property that, for some reason, only lists 'myapp.exe' and the auto-generated 'readme.txt' files (even though other files are generated during the build process).

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2023-9-29
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.

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by