Merge pull request #5314 from harfbuzz/check-scripts-cleanup

Cleanup check-*.py scripts
This commit is contained in:
Behdad Esfahbod authored and GitHub committed 2025-05-06 09:33:13 -06:00
commit 2831956ba2
8 files changed
+300 -186

No files matched your search

+31 -22
View File
@@ -1,37 +1,46 @@
#!/usr/bin/env python3
import sys, os
import os
import sys
srcdir = os.getenv ('srcdir', os.path.dirname (__file__))
base_srcdir = os.getenv ('base_srcdir', srcdir)
srcdir = sys.argv[1]
base_srcdir = sys.argv[2]
builddir = sys.argv[3]
os.chdir(srcdir)
os.chdir (srcdir)
def removeprefix(s):
abs_path = os.path.join(base_srcdir, s)
return os.path.relpath(abs_path, srcdir)
abs_path = os.path.join(base_srcdir, s)
return os.path.relpath(abs_path, srcdir)
HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \
[x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')]
HBHEADERS = [x for x in HBHEADERS if x.endswith ('.h')]
HBSOURCES = [
removeprefix(x) for x in os.getenv ('HBSOURCES', '').split ()
] or [
x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))
HBHEADERS = [os.path.basename(x) for x in os.getenv("HBHEADERS", "").split()] or [
x for x in os.listdir(".") if x.startswith("hb") and x.endswith(".h")
]
HBHEADERS = [x for x in HBHEADERS if x.endswith(".h")]
HBSOURCES = [removeprefix(x) for x in os.getenv("HBSOURCES", "").split()] or [
x for x in os.listdir(".") if x.startswith("hb") and x.endswith((".cc", ".hh"))
]
stat = 0
for x in HBHEADERS:
with open (x, 'r', encoding='utf-8') as f: content = f.read ()
if ('HB_BEGIN_DECLS' not in content) or ('HB_END_DECLS' not in content):
print ('Ouch, file %s does not have HB_BEGIN_DECLS / HB_END_DECLS, but it should' % x)
stat = 1
print(f"Checking {x}")
with open(x, "r", encoding="utf-8") as f:
content = f.read()
if ("HB_BEGIN_DECLS" not in content) or ("HB_END_DECLS" not in content):
print(
"Ouch, file %s does not have HB_BEGIN_DECLS / HB_END_DECLS, but it should"
% x
)
stat = 1
for x in HBSOURCES:
with open (x, 'r', encoding='utf-8') as f: content = f.read ()
if ('HB_BEGIN_DECLS' in content) or ('HB_END_DECLS' in content):
print ('Ouch, file %s has HB_BEGIN_DECLS / HB_END_DECLS, but it shouldn\'t' % x)
stat = 1
print(f"Checking {x}")
with open(x, "r", encoding="utf-8") as f:
content = f.read()
if ("HB_BEGIN_DECLS" in content) or ("HB_END_DECLS" in content):
print("Ouch, file %s has HB_BEGIN_DECLS / HB_END_DECLS, but it shouldn't" % x)
stat = 1
sys.exit (stat)
sys.exit(stat)
+20 -11
View File
@@ -1,20 +1,29 @@
#!/usr/bin/env python3
import sys, os, re
import os
import re
import sys
os.chdir (os.getenv ('srcdir', os.path.dirname (__file__)))
srcdir = sys.argv[1]
base_srcdir = sys.argv[2]
builddir = sys.argv[3]
HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \
[x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')]
os.chdir(srcdir)
HBHEADERS = [os.path.basename(x) for x in os.getenv("HBHEADERS", "").split()] or [
x for x in os.listdir(".") if x.startswith("hb") and x.endswith(".h")
]
stat = 0
print ('Checking that all public symbols are exported with HB_EXTERN')
print("Checking that all public symbols are exported with HB_EXTERN")
for x in HBHEADERS:
with open (x, 'r', encoding='utf-8') as f: content = f.read ()
for s in re.findall (r'\n.+\nhb_.+\n', content):
if not s.startswith ('\nHB_EXTERN '):
print ('failure on:', s)
stat = 1
print(f"Checking {x}")
with open(x, "r", encoding="utf-8") as f:
content = f.read()
for s in re.findall(r"\n.+\nhb_.+\n", content):
if not s.startswith("\nHB_EXTERN "):
print("failure on:", s)
stat = 1
sys.exit (stat)
sys.exit(stat)
+34 -19
View File
@@ -1,34 +1,49 @@
#!/usr/bin/env python3
import sys, os, re
import os
import re
import sys
srcdir = os.getenv ('srcdir', os.path.dirname (__file__))
base_srcdir = os.getenv ('base_srcdir', srcdir)
srcdir = sys.argv[1]
base_srcdir = sys.argv[2]
builddir = sys.argv[3]
os.chdir(srcdir)
os.chdir (srcdir)
def removeprefix(s):
abs_path = os.path.join(base_srcdir, s)
return os.path.relpath(abs_path, srcdir)
abs_path = os.path.join(base_srcdir, s)
return os.path.relpath(abs_path, srcdir)
HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \
[x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')]
HBSOURCES = [
removeprefix(x) for x in os.getenv ('HBSOURCES', '').split ()
] or [
x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))
HBHEADERS = [os.path.basename(x) for x in os.getenv("HBHEADERS", "").split()] or [
x for x in os.listdir(".") if x.startswith("hb") and x.endswith(".h")
]
HBSOURCES = [removeprefix(x) for x in os.getenv("HBSOURCES", "").split()] or [
x for x in os.listdir(".") if x.startswith("hb") and x.endswith((".cc", ".hh"))
]
stat = 0
for x in HBHEADERS + HBSOURCES:
if not x.endswith ('h') or x == 'hb-gobject-structs.h': continue
tag = x.upper ().replace ('.', '_').replace ('-', '_').replace(os.path.sep, '_').replace('/', '_')
with open (x, 'r', encoding='utf-8') as f: content = f.read ()
if len (re.findall (tag + r'\b', content)) != 3:
print ('Ouch, header file %s does not have correct preprocessor guards. Expected: %s' % (x, tag))
stat = 1
if not x.endswith("h") or x == "hb-gobject-structs.h":
continue
print(f"Checking {x}")
tag = (
x.upper()
.replace(".", "_")
.replace("-", "_")
.replace(os.path.sep, "_")
.replace("/", "_")
)
with open(x, "r", encoding="utf-8") as f:
content = f.read()
if len(re.findall(tag + r"\b", content)) != 3:
print(
"Ouch, header file %s does not have correct preprocessor guards. Expected: %s"
% (x, tag)
)
stat = 1
sys.exit (stat)
sys.exit(stat)
+45 -32
View File
@@ -1,51 +1,64 @@
#!/usr/bin/env python3
import sys, os, re
import os
import re
import sys
srcdir = os.getenv ('srcdir', os.path.dirname (__file__))
base_srcdir = os.getenv ('base_srcdir', srcdir)
srcdir = sys.argv[1]
base_srcdir = sys.argv[2]
builddir = sys.argv[3]
os.chdir(srcdir)
os.chdir (srcdir)
def removeprefix(s):
abs_path = os.path.join(base_srcdir, s)
return os.path.relpath(abs_path, srcdir)
abs_path = os.path.join(base_srcdir, s)
return os.path.relpath(abs_path, srcdir)
HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \
[x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')]
HBSOURCES = [
removeprefix(x) for x in os.getenv ('HBSOURCES', '').split ()
] or [
x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))
HBHEADERS = [os.path.basename(x) for x in os.getenv("HBHEADERS", "").split()] or [
x for x in os.listdir(".") if x.startswith("hb") and x.endswith(".h")
]
HBSOURCES = [removeprefix(x) for x in os.getenv("HBSOURCES", "").split()] or [
x for x in os.listdir(".") if x.startswith("hb") and x.endswith((".cc", ".hh"))
]
stat = 0
print ('Checking that public header files #include "hb-common.h" or "hb.h" first (or none)')
print(
'Checking that public header files #include "hb-common.h" or "hb.h" first (or none)'
)
for x in HBHEADERS:
if x == 'hb.h' or x == 'hb-common.h': continue
with open (x, 'r', encoding='utf-8') as f: content = f.read ()
first = re.findall (r'#.*include.*', content)[0]
if first not in ['#include "hb.h"', '#include "hb-common.h"']:
print ('failure on %s' % x)
stat = 1
if x == "hb.h" or x == "hb-common.h":
continue
print(f"Checking {x}")
with open(x, "r", encoding="utf-8") as f:
content = f.read()
first = re.findall(r"#.*include.*", content)[0]
if first not in ['#include "hb.h"', '#include "hb-common.h"']:
print("failure on %s" % x)
stat = 1
print ('Checking that source files #include a private header first (or none)')
print("Checking that source files #include a private header first (or none)")
for x in HBSOURCES:
with open (x, 'r', encoding='utf-8') as f: content = f.read ()
includes = re.findall (r'#.*include.*', content)
if includes:
if not len (re.findall (r'".*\.hh"', includes[0])):
print ('failure on %s' % x)
stat = 1
print(f"Checking {x}")
with open(x, "r", encoding="utf-8") as f:
content = f.read()
includes = re.findall(r"#.*include.*", content)
if includes:
if not len(re.findall(r'".*\.hh"', includes[0])):
print("failure on %s" % x)
stat = 1
print ('Checking that there is no #include <hb-*.h>')
print("Checking that there is no #include <hb-*.h>")
for x in HBHEADERS + HBSOURCES:
with open (x, 'r', encoding='utf-8') as f: content = f.read ()
if re.findall ('#.*include.*<.*hb', content):
print ('failure on %s' % x)
stat = 1
print(f"Checking {x}")
with open(x, "r", encoding="utf-8") as f:
content = f.read()
if re.findall("#.*include.*<.*hb", content):
print("failure on %s" % x)
stat = 1
sys.exit (stat)
sys.exit(stat)
+29 -23
View File
@@ -1,39 +1,45 @@
#!/usr/bin/env python3
import sys, os, shutil, subprocess
import os
import shutil
import subprocess
import sys
os.chdir (os.getenv ('srcdir', os.path.dirname (__file__)))
srcdir = sys.argv[1]
base_srcdir = sys.argv[2]
builddir = sys.argv[3]
libs = os.getenv ('libs', '.libs')
os.chdir(srcdir)
ldd = os.getenv ('LDD', shutil.which ('ldd'))
ldd = os.getenv("LDD", shutil.which("ldd"))
if not ldd:
otool = os.getenv ('OTOOL', shutil.which ('otool'))
if otool:
ldd = otool + ' -L'
else:
print ('check-libstdc++.py: \'ldd\' not found; skipping test')
sys.exit (77)
otool = os.getenv("OTOOL", shutil.which("otool"))
if otool:
ldd = otool + " -L"
else:
print("check-libstdc++.py: 'ldd' not found; skipping test")
sys.exit(77)
stat = 0
tested = False
# harfbuzz-icu links to libstdc++ because icu does.
for soname in ['harfbuzz', 'harfbuzz-subset', 'harfbuzz-gobject', 'harfbuzz-cairo']:
for suffix in ['so', 'dylib']:
so = os.path.join (libs, 'lib%s.%s' % (soname, suffix))
if not os.path.exists (so): continue
for soname in ["harfbuzz", "harfbuzz-subset", "harfbuzz-gobject", "harfbuzz-cairo"]:
for suffix in ["so", "dylib"]:
so = os.path.join(builddir, "lib%s.%s" % (soname, suffix))
if not os.path.exists(so):
continue
print ('Checking that we are not linking to libstdc++ or libc++ in %s' % so)
ldd_result = subprocess.check_output (ldd.split() + [so])
if (b'libstdc++' in ldd_result) or (b'libc++' in ldd_result):
print ('Ouch, %s is linked to libstdc++ or libc++' % so)
stat = 1
print("Checking that we are not linking to libstdc++ or libc++ in %s" % so)
ldd_result = subprocess.check_output(ldd.split() + [so])
if (b"libstdc++" in ldd_result) or (b"libc++" in ldd_result):
print("Ouch, %s is linked to libstdc++ or libc++" % so)
stat = 1
tested = True
tested = True
if not tested:
print ('check-libstdc++.py: libharfbuzz shared library not found; skipping test')
sys.exit (77)
print("check-libstdc++.py: libharfbuzz shared library not found; skipping test")
sys.exit(77)
sys.exit (stat)
sys.exit(stat)
+37 -24
View File
@@ -1,51 +1,64 @@
#!/usr/bin/env python3
import sys, os, shutil, subprocess, glob, re
import glob
import os
import re
import shutil
import subprocess
import sys
builddir = os.getenv ('builddir', os.path.dirname (__file__))
libs = os.getenv ('libs', '.libs')
srcdir = sys.argv[1]
base_srcdir = sys.argv[2]
builddir = sys.argv[3]
objdump = os.getenv ('OBJDUMP', shutil.which ('objdump'))
objdump = os.getenv("OBJDUMP", shutil.which("objdump"))
if not objdump:
print ('check-static-inits.py: \'ldd\' not found; skipping test')
sys.exit (77)
print("check-static-inits.py: 'ldd' not found; skipping test")
sys.exit(77)
if sys.version_info < (3, 5):
print ('check-static-inits.py: needs python 3.5 for recursive support in glob')
sys.exit (77)
print("check-static-inits.py: needs python 3.5 for recursive support in glob")
sys.exit(77)
OBJS = glob.glob (os.path.join (builddir, libs, '**', '*hb*.o'), recursive=True)
OBJS = glob.glob(os.path.join(builddir, "**", "*hb*.o"), recursive=True)
if not OBJS:
print ('check-static-inits.py: object files not found; skipping test')
sys.exit (77)
print("check-static-inits.py: object files not found; skipping test")
sys.exit(77)
stat = 0
tested = 0
tested = False
result = subprocess.run(objdump.split () + ['-t'] + OBJS, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("Checking that the following object files has no static initializers/finalizers")
print("\n".join(OBJS))
result = subprocess.run(
objdump.split() + ["-t"] + OBJS, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if result.returncode:
if result.stderr.find (b'not recognized') != -1:
if result.stderr.find(b"not recognized") != -1:
# https://github.com/harfbuzz/harfbuzz/issues/3019
print ('objdump %s returned "not recognized", skipping')
print('objdump returned "not recognized", skipping')
else:
print ('objdump returned error:\n%s' % (result.stderr.decode ('utf-8')))
print("objdump returned error:\n%s" % (result.stderr.decode("utf-8")))
stat = 2
else:
tested = 1
tested = True
result = result.stdout.decode ('utf-8')
result = result.stdout.decode("utf-8")
# Checking that no object file has static initializers
for l in re.findall (r'^.*\.[cd]tors.*$', result, re.MULTILINE):
if not re.match (r'.*\b0+\b', l):
print ('Ouch, library has static initializers/finalizers')
for lib in re.findall(r"^.*\.[cd]tors.*$", result, re.MULTILINE):
if not re.match(r".*\b0+\b", lib):
print("Ouch, library has static initializers/finalizers")
stat = 1
# Checking that no object file has lazy static C++ constructors/destructors or other such stuff
if ('__cxa_' in result) and ('__ubsan_handle' not in result):
print ('Ouch, library has lazy static C++ constructors/destructors or other such stuff')
if ("__cxa_" in result) and ("__ubsan_handle" not in result):
print(
"Ouch, library has lazy static C++ constructors/destructors or other such stuff"
)
stat = 1
sys.exit (stat if tested else 77)
sys.exit(stat if tested else 77)
+99 -51
View File
@@ -1,77 +1,125 @@
#!/usr/bin/env python3
import sys, os, shutil, subprocess, re, difflib
import difflib
import os
import re
import shutil
import subprocess
import sys
os.environ['LC_ALL'] = 'C' # otherwise 'nm' prints in wrong order
os.environ["LC_ALL"] = "C" # otherwise 'nm' prints in wrong order
builddir = os.getenv ('builddir', os.path.dirname (__file__))
libs = os.getenv ('libs', '.libs')
srcdir = sys.argv[1]
base_srcdir = sys.argv[2]
builddir = sys.argv[3]
IGNORED_SYMBOLS = ['_fini', '_init', '_fdata', '_ftext', '_fbss',
'__bss_start', '__bss_start__', '__bss_end__', '_edata', '_end', '_bss_end__',
'__end__', '__gcov_.*', 'llvm_.*', 'flush_fn_list', 'writeout_fn_list', 'mangle_path',
'lprofDirMode', 'reset_fn_list']
IGNORED_SYMBOLS = [
"_fini",
"_init",
"_fdata",
"_ftext",
"_fbss",
"__bss_start",
"__bss_start__",
"__bss_end__",
"_edata",
"_end",
"_bss_end__",
"__end__",
"__gcov_.*",
"llvm_.*",
"flush_fn_list",
"writeout_fn_list",
"mangle_path",
"lprofDirMode",
"reset_fn_list",
]
# Rust
IGNORED_SYMBOLS += [
'rust_eh_personality',
'_ZN3std9panicking11EMPTY_PANIC.*', # 'std::panicking::EMPTY_PANIC::.*'
'_ZN3std3sys3pal4unix4args3imp15ARGV_INIT_ARRAY.*', # 'std::sys::pal::unix::args::imp::ARGV_INIT_ARRAY::.*'
'_ZN3std3sys4args4unix3imp15ARGV_INIT_ARRAY.*', # std::sys::args::unix::imp::ARGV_INIT_ARRAY::.*
'_ZN17compiler_builtins.*', # 'compiler_builtins::.*'
"rust_eh_personality",
"_ZN3std9panicking11EMPTY_PANIC.*", # 'std::panicking::EMPTY_PANIC::.*'
"_ZN3std3sys3pal4unix4args3imp15ARGV_INIT_ARRAY.*", # 'std::sys::pal::unix::args::imp::ARGV_INIT_ARRAY::.*'
"_ZN3std3sys4args4unix3imp15ARGV_INIT_ARRAY.*", # std::sys::args::unix::imp::ARGV_INIT_ARRAY::.*
"_ZN17compiler_builtins.*", # 'compiler_builtins::.*'
]
IGNORED_SYMBOLS = '|'.join (IGNORED_SYMBOLS)
IGNORED_SYMBOLS = "|".join(IGNORED_SYMBOLS)
nm = os.getenv ('NM', shutil.which ('nm'))
nm = os.getenv("NM", shutil.which("nm"))
if not nm:
print ('check-symbols.py: \'nm\' not found; skipping test')
sys.exit (77)
print("check-symbols.py: 'nm' not found; skipping test")
sys.exit(77)
tested = False
stat = 0
for soname in ['harfbuzz', 'harfbuzz-subset', 'harfbuzz-icu', 'harfbuzz-gobject', 'harfbuzz-cairo']:
for suffix in ['so', 'dylib']:
so = os.path.join (builddir, libs, 'lib%s.%s' % (soname, suffix))
if not os.path.exists (so): continue
for soname in [
"harfbuzz",
"harfbuzz-subset",
"harfbuzz-icu",
"harfbuzz-gobject",
"harfbuzz-cairo",
]:
for suffix in ["so", "dylib"]:
so = os.path.join(builddir, "lib%s.%s" % (soname, suffix))
if not os.path.exists(so):
continue
# On macOS, C symbols are prefixed with _
symprefix = '_' if suffix == 'dylib' else ''
# On macOS, C symbols are prefixed with _
symprefix = "_" if suffix == "dylib" else ""
EXPORTED_SYMBOLS = [s.split ()[2]
for s in re.findall (r'^.+ [BCDGIRSTu] .+$', subprocess.check_output (nm.split() + [so]).decode ('utf-8'), re.MULTILINE)
if not re.match (r'.* %s(%s)\b' % (symprefix, IGNORED_SYMBOLS), s)]
EXPORTED_SYMBOLS = [
s.split()[2]
for s in re.findall(
r"^.+ [BCDGIRSTu] .+$",
subprocess.check_output(nm.split() + [so]).decode("utf-8"),
re.MULTILINE,
)
if not re.match(r".* %s(%s)\b" % (symprefix, IGNORED_SYMBOLS), s)
]
prefix = (symprefix + os.path.basename (so)).replace ('libharfbuzz', 'hb').replace ('-', '_').split ('.')[0]
prefix = (
(symprefix + os.path.basename(so))
.replace("libharfbuzz", "hb")
.replace("-", "_")
.split(".")[0]
)
print ('Checking that %s does not expose internal symbols' % so)
suspicious_symbols = [x for x in EXPORTED_SYMBOLS if not re.match (r'^%s(_|$)' % prefix, x)]
if suspicious_symbols:
print ('Ouch, internal symbols exposed:', suspicious_symbols)
stat = 1
print("Checking that %s does not expose internal symbols" % so)
suspicious_symbols = [
x for x in EXPORTED_SYMBOLS if not re.match(r"^%s(_|$)" % prefix, x)
]
if suspicious_symbols:
print("Ouch, internal symbols exposed:", suspicious_symbols)
stat = 1
def_path = os.path.join (builddir, soname + '.def')
if not os.path.exists (def_path):
print ('\'%s\' not found; skipping' % def_path)
else:
print ('Checking that %s has the same symbol list as %s' % (so, def_path))
with open (def_path, 'r', encoding='utf-8') as f: def_file = f.read ()
diff_result = list (difflib.context_diff (
def_file.splitlines (),
['EXPORTS'] + [re.sub ('^%shb' % symprefix, 'hb', x) for x in EXPORTED_SYMBOLS] +
# cheat: copy the last line from the def file!
[def_file.splitlines ()[-1]]
))
def_path = os.path.join(builddir, soname + ".def")
if not os.path.exists(def_path):
print("'%s' not found; skipping" % def_path)
else:
print("Checking that %s has the same symbol list as %s" % (so, def_path))
with open(def_path, "r", encoding="utf-8") as f:
def_file = f.read()
diff_result = list(
difflib.context_diff(
def_file.splitlines(),
["EXPORTS"]
+ [re.sub("^%shb" % symprefix, "hb", x) for x in EXPORTED_SYMBOLS]
+
# cheat: copy the last line from the def file!
[def_file.splitlines()[-1]],
)
)
if diff_result:
print ('\n'.join (diff_result))
stat = 1
if diff_result:
print("\n".join(diff_result))
stat = 1
tested = True
tested = True
if not tested:
print ('check-symbols.py: no shared libraries found; skipping test')
sys.exit (77)
print("check-symbols.py: no shared libraries found; skipping test")
sys.exit(77)
sys.exit (stat)
sys.exit(stat)
+5 -4
View File
@@ -1038,10 +1038,6 @@ if get_option('tests').enabled()
]
env = environment()
env.set('srcdir', meson.current_source_dir())
env.set('base_srcdir', meson.project_source_root())
env.set('builddir', meson.current_build_dir())
env.set('libs', meson.current_build_dir()) # TODO: Merge this with builddir after autotools removal
HBSOURCES = []
foreach f : hb_sources
if meson.version().version_compare('>=1.4.0')
@@ -1069,6 +1065,11 @@ if get_option('tests').enabled()
foreach name : dist_check_script
test(name, find_program(name + '.py'),
env: env,
args: [
meson.current_source_dir(),
meson.project_source_root(),
meson.current_build_dir(),
],
depends: name == 'check-symbols' ? defs_list : [],
suite: ['src'],
)