bin/find-unusedheaders.py | 48 ---------------- bin/find-unusedheaders.sh | 88 +++++++++++++++++++++++++++++++ include/framework/transactionmanager.hxx | 2 3 files changed, 89 insertions(+), 49 deletions(-)
New commits: commit f8cd2837493ebcab1ff485e00bfc9181779b49d8 Author: Gabor Kelemen <kelem...@ubuntu.com> AuthorDate: Sat Dec 23 09:17:48 2023 +0100 Commit: Gabor Kelemen <kelem...@ubuntu.com> CommitDate: Sun Dec 24 11:50:26 2023 +0100 Rewrite bin/find-unusedheaders.py This script was broken, not only in the implementation (it gives too many false positives in a suspiciously short, <1s time) but in its approach as well: only considering stuff that is compiled under Linux inherently leaves out other platform specific or experimental stuff. Rewrite it using another approach: grep for mentions of each header in the modules or global ones in include/ everywhere. Runtime of this script is about 15 minutes, seems to give only a few relevant hits. Change-Id: Ifb92f41f11ca9a2bf14eec617a469003becb78fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161234 Tested-by: Jenkins Reviewed-by: Gabor Kelemen <kelem...@ubuntu.com> diff --git a/bin/find-unusedheaders.py b/bin/find-unusedheaders.py deleted file mode 100755 index 7ca9bea4be59..000000000000 --- a/bin/find-unusedheaders.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python3 - -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -""" -Find dirs in: -workdir/Dep/CObject -workdir/Dep/CxxObject - -Concat these files and compare them with the output of -`git ls-tree HEAD -r --name-only` and report files in the git ls-tree that aren't in the first. -""" - -import os -import subprocess - - -def get_files_dict_recursively(directory): - data = {} - for root, _, files in os.walk(directory, topdown=False): - for f in files: - basename = os.path.splitext(f)[0] - data[basename] = os.path.join(root, f) - return data - - -def main(): - data = {} - for d in ('workdir/Dep/CObject', 'workdir/Dep/CxxObject'): - tmp = get_files_dict_recursively(d) - data.update(tmp) - - gitfiles = subprocess.check_output(['git', 'ls-tree', 'HEAD', '-r', '--name-only']).decode('utf-8').split(' ') - - for f in gitfiles: - ext = os.path.splitext(f)[1] - if ext[1:] in ('c', 'cxx', 'h', 'hxx'): - tmp = os.path.basename(f) - tmp = os.path.splitext(tmp)[0] - if tmp not in data: - print(f) - -if __name__ == '__main__': - main() diff --git a/bin/find-unusedheaders.sh b/bin/find-unusedheaders.sh new file mode 100755 index 000000000000..0a27696cc161 --- /dev/null +++ b/bin/find-unusedheaders.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Search for headers not included in any source files +# Note: there are still exceptions (such as ODK) so results are not completely foolproof + +# Search in all subdirs, except for those not containing C/C++ headers +for subdir in $(ls -d */ | grep -v \ + -e include/ `# Handled differently` \ + -e android \ + -e animations `# No headers here` \ + -e bean \ + -e bin/ `# Skip subdirs not containing C/C++ code ` \ + -e cpputools/ \ + -e distro-configs/ \ + -e docmodel/ `# No headers here` \ + -e eventattacher/ \ + -e external/ `# FIXME Should be handled differently, but it\'s such a mess` \ + -e extras/ \ + -e i18nlangtag/ \ + -e icon-themes/ \ + -e idlc/ \ + -e instsetoo_native/ \ + -e jurt/ \ + -e jvmaccess/ \ + -e librelogo/ \ + -e m4/ \ + -e msicreator/ \ + -e nlpsolver/ \ + -e offapi/ \ + -e officecfg/ \ + -e oovbaapi/ \ + -e osx/ \ + -e pch/ \ + -e postprocess/ \ + -e qadevOOo/ \ + -e readlicense_oo/ \ + -e remotebridges/ \ + -e reportbuilder/ \ + -e ridljar/ \ + -e schema/ \ + -e scp2/ \ + -e smoketest/ \ + -e swext/ \ + -e sysui/ \ + -e udkapi/ \ + -e uitest/ \ + -e unoil/ \ + -e unotest/ \ + -e ure/ \ + -e wizards/ \ + -e xmerge/ \ + -e xmlreader/ \ + -e instdir/ `# Skip typical build-related temporaries` \ + -e workdir/ \ + -e autom4te.cache/ \ + -e config_host/ \ + -e dictionaries/ `# Skip typical submodules` \ + -e helpcontent2/ \ + -e translations/ + ) ; do + + # Get a feeling of progress :) + echo "Checking module: $subdir"; + + # Find all .h / .hxx files and see if they are mentioned in the module + # skip special directories: pch and precompiled_ (compilerplugins does not have separate pch dir), workben (playground code), test (dead code?) + for i in $(find "$subdir" -name "*\.h" -o -name "*\.hxx" -o -name "\.hrc" -o -name "*\.hlst" | grep -v -e "/pch/" -e "/precompiled_" -e "/workben/" -e "/test/" | xargs basename -a ); do + # Search only in source files, and skip mentions in makefiles, .yaml, clang-format excludelist etc. + if [ $(git grep -l "$i" "$subdir"/{*\.[hc]xx,*\.[hc],*\.hrc,*\.mm,*\.m,*\.py} | wc -l) -eq 0 ] ; then + echo "Out of use header: $(find "$subdir" -name "$i")"; + fi + done +done + +echo "Checking global headers"; +# Search for files in include is different since they can be used in any module +for i in $(find include/ -name "*\.h" -o -name "*\.hxx" -o -name "\.hrc" | cut -d "/" -f 2- ); do + # Some headers are only included between double quotes + if [ $(git grep -l -e \<$i\> -e \"$i\" {*\.[hc]xx,*\.[hc],*\.hrc,*\.mm,*\.m} | grep -v pch | wc -l) -eq 0 ] ; then + echo "Out of use header: include/$i"; + fi +done diff --git a/include/framework/transactionmanager.hxx b/include/framework/transactionmanager.hxx index fe011968cf32..026b6caf50bc 100644 --- a/include/framework/transactionmanager.hxx +++ b/include/framework/transactionmanager.hxx @@ -21,7 +21,7 @@ #include <mutex> -#include "gate.hxx" +#include <framework/gate.hxx> namespace framework{