killOrphanFiles()

Search all unreachable code files, from one or more Main Entry files, and delete them.
240 téléchargements
Mise à jour 22 sept. 2021

Afficher la licence

Search all unreachable code files, from a Main Entry file (or multiple entry files), and delete them.
Do you happen to have a large Matlab project with few entry points (MAIN1,MAIN2,..) ? Then there is a chance that a lot of scripts within your root are not needed by none of those entry points. This tool helps you clean up your code before releasing it.
Note: Dependencies in this script are very conservative by design: A calls B if the string "B" is mentioned anywhere in A with the following conditions:
1) once all spaces are removed the last character before 'name' is ' ' or '='
2) once all spaces are removed the first character after 'name' is '( '
More specifically
functioName1/scriptName1 is considered Reachable from MAIN.m if the string functioName1/scriptName1 appears in MAIN.m and obeys the 2 reules above.
This is extended recursively to all depth of "calls" (AdjacencyMatrix is propagated into TransitiveClosure). At that point in the 1st row all the reachable files from main Nr 1 are flagged.
KILLORPHANFILES() starts-up a number of user dialogues consisting of these steps
- select MAIN file
- select ROOT folder
- LIST all MAIN-unreachable files in ROOT
- SELECT which ones / CONFIRM deletion
% SEARCH METHOD:
% - A list of all filenames within root is created,
% with MAIN1,MAIN2,.. in position 1,2,...
% - Make dependency table:
% A(i,j) = "name(j) appears in file(i)" (even within a comment)
% this way also commented code is protected (desired)
% - Propagate dependency (transitive closure of adjacency matrix A)
% If i mentions(needs) j and j mentions k then i needs k:
% i --> j --> k ==> i --> k
% A(i,j)==1
% A(j,k)==1 ==> A(i,k) = 1
% - A(1,:) contains all nodes called by MAIN1 within selected ROOT folder.
% - A(2,:) contains all nodes called by MAIN2 within selected ROOT folder.
% - Intersection of {~A(1,:),~A(2,:)} is the unreachable set
% by the union of MAIN1,MAIN2. Meaning both MAIN1,MAIN2 will run after
% clean up is completed

Citation pour cette source

Massimo Ciacci (2024). killOrphanFiles() (https://www.mathworks.com/matlabcentral/fileexchange/46618-killorphanfiles), MATLAB Central File Exchange. Extrait(e) le .

Compatibilité avec les versions de MATLAB
Créé avec R2016b
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur STL (STereoLithography) dans Help Center et MATLAB Answers

Community Treasure Hunt

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

Start Hunting!

Kill_Orphans_v2_0

Version Publié le Notes de version
2.0.0.2

updated comment

2.0.0.1

bug for multiple main entry points found and fixed.

2.0.0.0

(1)Fixed dependency check errors. A function name is being invoked if [X]name[Y] satisfy Y='(' and X terminates with a blank.
(2) Fix comment detection: A line of code is a comment if all chars before the first '%' are spaces.

1.8.0.0

- Following suggestion from Carl Witthoft, files are now moved to a folder called "__Orphans" created inside the user selected root folder. It is up to the user to actually delete the files.

1.7.0.0

User can now choose to ignore comments (a commented call is not a call). Ignoring comments deletes more orphans.
Should work also in 2011b, the new version was tested on 2015b.

1.6.0.0

Improved functionality, to support multiple entry points.

1.5.0.0

Changed screenshot to a less distracting one.

1.4.0.0

- Updated description about the weak definition of 'dependency'. Note however that this method will not miss any true dependency to the best of my knowledge. And it does not require special code toolboxes either.

1.3.0.0

- Added info in help section
- Added plots of graphs before and after pruning.

1.2.0.0

Added more info in summary

1.1.0.0

changed few strings

1.0.0.0