Wireshark-dev: [Wireshark-dev] Script used to automatically delete unused #includes

From: Martin Mathieson <martin.r.mathieson@xxxxxxxxxxxxxx>
Date: Sun, 4 Jan 2015 23:56:46 +0000
Hi,

I have attached the script that I used over the past week or 2 to detect and delete unneeded #includes.  I am not sure whether it is fit for submitting to the tools folder in its current state.

By my count it deleted > 1400 #includes, although:
- not all source files were scanned (e.g. plugins, epan other than dissectors)
- a few includes later needed to be restored

The script works by attempting to build without each #include, and permanently removing all that seem not to be needed.  Ideally, a script like this would be run in the least forgiving environment available and any added warnings seen after a deletion would be treated as failure.  I am currently building under VS 2010 EE, which is maybe the most forgiving environment we support.  The Ubuntu build done by the Petri Dish definitely helped, but new errors were still seen after committing the changes.

My reluctance to commit the script in its current form is because:
- while I hope it was worth running once, I'm not sure it'll be worth doing again.  Having said that, the script has some cowardly rules for not deleting includes that a better version on a less forgiving build environment could discard.  I doubt you could even measure the difference it makes to a clean build time, but hopefully removing some clutter was helpful.
- it is hard-coded to build with nmake.  I'm not sure how best to choose between make/Makefile and nmake/Makefile.nmake
- the results always need to be treated with care, and I wouldn't want someone to  run the script for several hours to find that they can't commit the result.

I'd be very happy if someone wants to further develop and run the script, but unless someone feels differently I'll assume that it shouldn't be committed as it stands.

Best regards,
Martin 


Attachment: delete_includes.py
Description: Binary data