Bug 70371 - Identify unused headers
Summary: Identify unused headers
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: Other All
: medium normal
Assignee: Jelle van der Waa
URL:
Whiteboard: target:4.2.0
Keywords: difficultyBeginner, easyHack, skillScript
Depends on:
Blocks:
 
Reported: 2013-10-11 10:30 UTC by Björn Michaelsen
Modified: 2016-02-18 16:37 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
compares workdir files with git ls-tree (1.07 KB, text/x-perl)
2013-10-12 12:29 UTC, Jelle van der Waa
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Michaelsen 2013-10-11 10:30:25 UTC
Now that we have gbuild and gbuild only it should be rather easy to identify unused C/C++ headers. For this, this EasyHack asks to create a script that:
- concats and sorts all the filenames mentioned in workdir/unxlngx6.pro/Dep/CxxObject and workdir/unxlngx6.pro/Dep/CObject
- runs a `git ls-tree HEAD -r --name-only`
- and reports files in the second that are not in the first.

This might still create some false positives because of e.g. platform dependant files, but it should be a good starting point: Obviously such headers if truly unused, should be removed from the repository tree.
Comment 1 khagaroth 2013-10-11 20:20:47 UTC
http://code.google.com/p/include-what-you-use/ might be useful.
Comment 2 Jelle van der Waa 2013-10-12 12:29:44 UTC
Created attachment 87504 [details]
compares workdir files with git ls-tree
Comment 3 Jelle van der Waa 2013-10-12 12:32:24 UTC
(In reply to comment #2)
> Created attachment 87504 [details]
> compares workdir files with git ls-tree

This is a work in progress quickly hacked perl script, which should do what is descibed in the request. Example output: http://sprunge.us/CZSh 
Note: I've disabled some options when compiling so there might be some false-positives ;)
Comment 4 Jorendc 2013-10-12 12:44:45 UTC
(In reply to comment #0)
> This might still create some false positives because of e.g. platform
> dependant files, but it should be a good starting point: Obviously such
> headers if truly unused, should be removed from the repository tree.

Just a thought from a non-developer: what if we combine the output of all platforms (tinderboxes for example)? If header 'A' comes up in all output files, we can be (almost?) sure it isn't platform dependent. Isn't it?

Kind regards,
Joren
Comment 5 Björn Michaelsen 2013-10-13 01:20:39 UTC
@Jelle: Awesome, quick work! Could you commit this to ./bin in the core repo (if you want to use gerrit, feel free to add me as a reviewer, so I can fasttrack that)?

@Jorendc: Lets see how much false-positives there really are. If they are too many we might e.g. blacklist them (per platform). Another possibility would be to do `git grep` on the basename of the header and then see if there is any include statement for it. But first, lets get the script as-is in. ;)
Comment 6 Christina Rossmanith 2013-10-13 14:45:58 UTC
I just picked three results from the list (http://sprunge.us/CZSh) and all of them were found using "git grep <include file>": vertcurs_mask.h salframeview.h and weakbase.h
Comment 7 Thomas Arnhold 2013-10-14 07:50:08 UTC
Yes, there shouldn't be many of them, because I did a cleanup some month ago. See 0f11f30ea96fcec8d7c648089fc223a6fbed6aef, bbac35af148ed6c9f19386e4721fa38b500f45a1, and more... I searched for all *.h and *.hxx files and grepped if they are included or referenced in any way - if not I removed them.
Comment 8 Commit Notification 2013-10-15 08:22:54 UTC
Jelle van der Waa committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=1793e5c1ff5d4b84178b4805026b8d455f32b0e5

fdo#70371: Initial perl script



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 9 Björn Michaelsen 2013-10-15 08:25:41 UTC
Closing this one as fixed as it is clearly working.

@Jelle: Congratulations for fixing this Easy Hack. Feel free to file a follow up Easy Hack to:
- run this one regularly manually and recheck the list
- provide a blacklist of known false positives
- create a way to run this e.g. on a tinderbox and check if there are new headers in the list
- ...
Comment 10 Commit Notification 2013-10-15 08:34:19 UTC
Bjoern Michaelsen committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=e4fbcc549a143992f72333404adb0180afa69e1a

fdo#70371: create findunusedheaders target



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 11 Robinson Tryon (qubit) 2015-12-15 23:20:45 UTC
Migrating Whiteboard tags to Keywords: (EasyHack DifficultyBeginner SkillScript )
[NinjaEdit]
Comment 12 Robinson Tryon (qubit) 2016-02-18 16:37:16 UTC
Remove LibreOffice Dev List from CC on EasyHacks
(curtailing excessive email to list)
[NinjaEdit]