summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-11-28 20:32:19 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-11-29 13:15:28 +0100
commit5e55f7a54170b25aaf82520c1cde307ece362eef (patch)
tree5e8a2d47650735c860b5a0054fa0d19cf2312d59 /bin
parentde62d0c77e2f9e24f72fd638cb5c5e365ff164b5 (diff)
make some function symbols module private
improve the script to filter out more noise generated by library symbols Change-Id: I22bf6037d56bc4015001825c3fb3b21a39d85e07 Reviewed-on: https://gerrit.libreoffice.org/84022 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/find-can-be-private-symbols.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/bin/find-can-be-private-symbols.py b/bin/find-can-be-private-symbols.py
index 0ff17072361a..a795abdb9208 100755
--- a/bin/find-can-be-private-symbols.py
+++ b/bin/find-can-be-private-symbols.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python2
#
# Find exported symbols that can be made non-exported.
#
@@ -22,6 +22,21 @@ import re
exported_symbols = set()
imported_symbols = set()
+# standalone functions that are exported but not imported
+unused_function_exports = set()
+classes_with_exported_symbols = set()
+classes_with_imported_symbols = set()
+# all names that exist in the source code
+all_source_names = set()
+
+
+# look for imported symbols in executables
+subprocess_find_all_source_names = subprocess.Popen("git grep -oh -P '\\b\\w\\w\\w+\\b' -- '*.h*'", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
+with subprocess_find_all_source_names.stdout as txt:
+ for line in txt:
+ line = line.strip()
+ all_source_names.add(line)
+subprocess_find_all_source_names.terminate()
subprocess_find = subprocess.Popen("find ./instdir -name *.so && find ./workdir/LinkTarget/CppunitTest -name *.so", stdout=subprocess.PIPE, shell=True)
with subprocess_find.stdout as txt:
@@ -76,11 +91,6 @@ print("exported = " + str(len(exported_symbols)))
print("imported = " + str(len(imported_symbols)))
print("diff = " + str(len(diff)))
-# standalone functions that are exported but not imported
-unused_function_exports = set()
-classes_with_exported_symbols = set()
-classes_with_imported_symbols = set()
-
for sym in exported_symbols:
filtered_sym = subprocess.check_output(["c++filt", sym]).strip()
if filtered_sym.startswith("non-virtual thunk to "): filtered_sym = filtered_sym[21:]
@@ -106,6 +116,11 @@ for sym in imported_symbols:
classname = filtered_sym[:i]
classes_with_imported_symbols.add(classname)
+def extractFunctionNameFromSignature(sym):
+ i = sym.find("(")
+ if i == -1: return sym
+ return sym[:i]
+
with open("bin/find-can-be-private-symbols.functions.results", "wt") as f:
for sym in sorted(unused_function_exports):
# Filter out most of the noise.
@@ -189,6 +204,8 @@ with open("bin/find-can-be-private-symbols.functions.results", "wt") as f:
elif sym.startswith("typelib_"): continue
elif sym.startswith("typereg_"): continue
elif sym.startswith("uno_"): continue
+ # remove things we found that do not exist in our source code, they're not ours
+ if not(extractFunctionNameFromSignature(sym) in all_source_names): continue
f.write(sym + "\n")
with open("bin/find-can-be-private-symbols.classes.results", "wt") as f: