Thursday, May 7, 2020

Mex only on file change

For large Simulink projects with lots of s-function, performing a mex of all files can be time consuming. Leaving it up to the user might result in simulation runs with older mex files because the user might forget to re-mex the updated file. You can automate the process as follows:
  • Create a hash list file that consists of file names used by s-functions and corresponding hashes.
  • Before simulation start, in InitFcn
    • Calculate hashes of files used by s-functions and compare them with the values saved in hash list file. Mark files whose hashes are different as "changed".
    • If an existing binary mex file date is earlier than any of the dates of the source files used in its build, mark that binary as "changed".
  • Mex files marked as "changed".
For hash calculation you can use [status, cmdout] = system(['certutil -hashfile', fileName, ' SHA256']) and parse cmdout via str=splitlines(cmdout); hash=str[2]; to get hash of file.

No comments:

Post a Comment